#Error reading image data (invalid argument) - Raspberry Pi Rev 1.3 connected to Raspberry Pi Zero 2W

7 messages · Page 1 of 1 (latest)

harsh adderBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

chilly sand
#

The part of creating buffer and read bytes is the following bellow:

#

int SendFrames(){
        allocator = make_shared<FrameBufferAllocator>(cameraconnection.camera);
        for (StreamConfiguration &streamConfig : *cameraconnection.config){
            int ret = allocator->allocate(streamConfig.stream());
            if(ret<0){
                cerr << "Can't allocate buffers" << endl;
                return -ENOMEM;
            }
        }

        if(cameraconnection.camera->start() < 0){
            cerr << "Failed to start the camera" << endl;
            return EXIT_FAILURE;
        }

        while(running){
            const auto &buffers = allocator->buffers(cameraconnection.stream);
            cout << "Allocated buffers: " << buffers.size() << endl;

            if(buffers.empty()){
                cerr << "Allocated buffers are empty, waiting ..." << endl;
                usleep(100000);
                continue;
            }

            unique_ptr<Request> request = cameraconnection.camera->createRequest();
            if(!request){
                cerr << "Failed to create the request" << endl;
                continue;
            } else {
                cout << "Request created successfully" << endl;
            }
#
 FrameBuffer *frameBuffer = buffers[0].get();
            if(!frameBuffer){
                cerr << "Frame buffer is null" << endl;
                continue;
            }

            request->addBuffer(cameraconnection.stream, frameBuffer);
            if(cameraconnection.camera->queueRequest(request.get()) < 0){
                cerr << "Failed to queue request" << endl;
                continue;
            }

            request->status();

            const auto &planes = frameBuffer->planes();  // object plane to adquire image data after the request
            if(!planes.empty()){
                const auto &plane = planes[0];
                if(plane.length <= 0){
                    cerr << "Invalid plane length: " << plane.length << endl;
                    continue;
                }

                vector<unsigned char> image_data(plane.length);  

                // GET THE IMAGE DATA
                int fd_value = plane.fd.get();
                cout << "Checking fd value:" << fd_value << endl;

                if(fd_value < 0){
                    cerr << "Invalid file descriptor (FD: " << fd_value << ")" << endl;
                    continue;
                }

                ssize_t bytes_read = read(fd_value, image_data.data(), plane.length);
                if (bytes_read == -1) {
                    perror("Failed to read image data");
                    cerr << "Error reading image data. FD: " << fd_value
                        << ", length: " << plane.length << endl;
                    continue;
                }

        ```
#
                image_data.resize(static_cast<size_t>(bytes_read));

                if(bytes_read <= 0){
                    cerr << "No data read. Bytes read: " << bytes_read << endl;
                    continue;
                }
                
                if(!BytesToSend(socketconnection, image_data)){
                    cerr << "Failed to send image data" << endl;
                } else {
                    cout << "Data sent" << endl;
                }

            } else {
                cerr << "No planes available for frame" << endl;
            }
        }
        return 0;
    }
#

(OBS.: I'm new coding with C++, so I accept suggestions to improve it)

vague glade
#

why did you give it an invalid argument?