Raw image data from camera like “645 PRO”

后端 未结 4 1448
庸人自扰
庸人自扰 2020-11-30 05:09

A time ago I already asked this question and I also got a good answer:

I\'ve been searching this forum up and down but I couldn\'t find what I reall

4条回答
  •  情话喂你
    2020-11-30 05:57

    as @Wildaker mentioned, for a specific code to work you have to be sure which pixel format the camera is sending you. The code from @thomketler will work if it's set for 32-bit RGBA format.

    Here is a code for the YUV default from camera, using OpenCV:

    cv::Mat convertImage(CMSampleBufferRef sampleBuffer)
    {
        CVImageBufferRef cameraFrame = CMSampleBufferGetImageBuffer(sampleBuffer);
        CVPixelBufferLockBaseAddress(cameraFrame, 0);
    
        int w = (int)CVPixelBufferGetWidth(cameraFrame);
        int h = (int)CVPixelBufferGetHeight(cameraFrame);
        void *baseAddress = CVPixelBufferGetBaseAddressOfPlane(cameraFrame, 0);
    
        cv::Mat img_buffer(h+h/2, w, CV_8UC1, (uchar *)baseAddress);
        cv::Mat cam_frame;
        cv::cvtColor(img_buffer, cam_frame, cv::COLOR_YUV2BGR_NV21);
        cam_frame = cam_frame.t();
    
        //End processing
        CVPixelBufferUnlockBaseAddress( cameraFrame, 0 );
    
        return cam_frame;
    }
    

    cam_frame should have the full BGR frame. I hope that helps.

提交回复
热议问题