saving frames is returning gray scale image

Answered

Comments

14 comments

  • Avatar
    Andrey Terentyev

    Hello Mohamed,

    Could you please explain in more detail what are doing? What is you objective? What is this piece of code from?

    0
    Comment actions Permalink
  • Avatar
    Mohamed Thasin

    Hello Andrey,
    The above code snippet I have added at pushUncompressedVideoFrame function in device agent CPP file.

    DeviceAgent::pushUncompressedVideoFrame(const IUncompressedVideoFrame* videoFrame)

    I want to extract images from camera. The above code snippet export it as image. But it's in gray-scale. I want this as a color image.

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hello Mohamed,

    videoFrame parameter of pushUncompressedVideoFrame refers the actual frame data the Server receives from a camera, i.e. if there is a gray-scale image in the frame data, it means the camera has sent such a frame to the Server and it passed the frame to the plugin.

    Please, check your camera settings.

    0
    Comment actions Permalink
  • Avatar
    Mohamed Thasin

    What is the settings should I change exact;y?

     

     

    My client application video looks like below,  It's not gray scale video. 

     

     

    At the same time, this is what I am receivng after imwrite




    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Muhamed,

    The code you posted and cv::imwrite(file_path,img_color); seems to be OpenCV specific and has no relation to Nx Witness SDK.

    I'm afraid I can't help you with OpenCV programming at the moment. Try to consult the opencv documentation or ask in the forum https://answers.opencv.org/questions/

    0
    Comment actions Permalink
  • Avatar
    Mohamed Thasin

    Hello Andrey,

    I have raised the question on stackoverflow. https://stackoverflow.com/questions/61221880/image-export-is-returning-grey-scale-image-in-opencv/61222004?noredirect=1#comment108311334_61222004.

    It's not working as I expected. 

    The above code snippet I took out from this post. https://support.networkoptix.com/hc/en-us/community/posts/360037395653-Convert-IUncompressedVideoFrame-to-OpenCV-Mat

     

    I hope this is what NX team also using to save it as a file as mentioned by Roman Inflianskas.

    i am really struggling a lot to convert this into colour image. I hope you understand the issue. please help me to solve the issue. 

     

    NOTE: The above post not answered my problem

    1
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hello Mohamed,

    This is a good post on your issue. It lead me to the root cause of your problem, I hope.

    https://support.networkoptix.com/hc/en-us/community/posts/360037395653-Convert-IUncompressedVideoFrame-to-OpenCV-Mat

    As my colleague has mentioned "The server will transcode video into a requested pixel format,"

    That means that a plugin can request from the Server needed frame format. It is done in Engine manifest in capabilities section.

    Let's have a look at sample plugin engine.cpp.

    std::string Engine::manifestString() const
    {
    // Ask the Server to supply uncompressed video frames in YUV420 format (see
    // https://en.wikipedia.org/wiki/YUV).
    //
    // Note that this format is used internally by the Server, therefore requires minimum
    // resources for decoding, thus it is the recommended format.
    return /*suppress newline*/ 1 + R"json(
    {
    "capabilities": "needUncompressedVideoFrames_yuv420|deviceDependent"
    }
    )json";
    }

    There is needUncompressedVideoFrames_yuv420. The yuv420 specifies the frame type the Server will feed to the plugin.

    The yuv420 frame has 3 (three) planes.

    0 - black-n-white frame

    1,2 - differential frames, using which you can restore RGB frame.

    In your code your are referencing and using 0-plane

    (void*) videoFrame->data(0),

    That's is why you have a black-n-white picture.

    Depending on your plugin objective you can either restore the RGB from yuv420 frame or request another frame time. In both cases it will increase the load, because either your plugin or the Server will transcode frames.

    The list of possible frame type can be found in pixel_format.cpp of Metadat SDK.

    INIT_PIXEL_FORMAT_DESCRIPTOR(yuv420, 3, 8, 2, 2);
    INIT_PIXEL_FORMAT_DESCRIPTOR(argb, 1, 32, 1, 1);
    INIT_PIXEL_FORMAT_DESCRIPTOR(abgr, 1, 32, 1, 1);
    INIT_PIXEL_FORMAT_DESCRIPTOR(rgba, 1, 32, 1, 1);
    INIT_PIXEL_FORMAT_DESCRIPTOR(bgra, 1, 32, 1, 1);
    INIT_PIXEL_FORMAT_DESCRIPTOR(rgb, 1, 24, 1, 1);
    INIT_PIXEL_FORMAT_DESCRIPTOR(bgr, 1, 24, 1, 1);
    0
    Comment actions Permalink
  • Avatar
    Mohamed Thasin

    Hello Andrey,

    I tried instead of using

    (void*) videoFrame->data(0),

    I modifed,

     

    (void*) videoFrame->data(1),


    Still It's not working.

     





    Could you tell me where exactly I have to specify frame type?

    Am I doing what you suggested in the previous post? 

    It's quite difficult understand what you have mentioned previously for me.

     

     

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hello Mohamed,

     

    (void*) videoFrame->data(1),

    > Still It's not working.

    It is expected. It would not give your color framed.

    > Am I doing what you suggested in the previous post?

    No, you are not. Please, read this article to get yourself familiar how YUV frames built. https://en.wikipedia.org/wiki/YUV

    > It's quite difficult understand what you have mentioned previously for me.

    Could you please specify what is not quite clear? I would give you more explanations.

    What is your objective? What do you need color frame for? What are you going to do next with the frame?

    0
    Comment actions Permalink
  • Avatar
    Mohamed Thasin

    Hello Andrey,
    I have written a python API. This exported color frame is input for the API. It detects objects in the image and send back the results. For that, I want to export frame as RGB image.

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Your can request the Server to feed RGB frames to you plugin. For that, declare the needUncompressedVideoFrames_rgb capability in Engine manifest. For example,

    {
    "capabilities": "needUncompressedVideoFrames_rgb"
    }

     

    0
    Comment actions Permalink
  • Avatar
    Mohamed Thasin

    Thanks, I hope this will solve my problem.

    0
    Comment actions Permalink
  • Avatar
    Mohamed Thasin

    Hello Andrey, 

     

    I tried the suggested solution, It didn't wok for `needUncompressedVideoFrames_rbg`  but it gives color image for `

    needUncompressedVideoFrames_rgb`. Eventhough frames are extracted as RGB image, 
    the actual colors of images are missing. i.e.,

    Actual Image.

     

    CPP program produced (exported frame) image.


    Any idea how to resolve the issue? 

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hello Mohamed,

    I'm sorry. I just mistyped the sting, "needUncompressedVideoFrames_rbg" instead of "needUncompressedVideoFrames_rgb" - R G B in the end.

    I have fixed it in my previous post, as well.

    Try the corrected version.

    0
    Comment actions Permalink

Please sign in to leave a comment.