0

I am trying to use OpenCV to apply treatments on an mj2 file encoded as grayscale uint16 per pixel. Unfortunately, a non disclosure agreement covers this file (which I did not generate myself) and I can not post a sample mj2 file.

The description of my .mj2 file as provided by ffmpeg is:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'data/DEVISSAGE_181.mj2':
  Metadata:
    major_brand     : mjp2
    minor_version   : 0
    compatible_brands: mjp2
    creation_time   : 2015-10-09 08:07:43
  Duration: 00:01:03.45, start: 0.000000, bitrate: 14933 kb/s
    Stream #0:0: Video: jpeg2000 (mjp2 / 0x32706A6D), gray16le, 1152x288, lossless, 14933 kb/s, SAR 1:4 DAR 1:1, 5.50 fps, 5.50 tbr, 55 tbn, 55 tbc (default)
    Metadata:
      creation_time   : 2015-10-09 08:07:43
      handler_name    : Video
      encoder         : Motion JPEG2000

I take it that gray16le confirms the uint16 encoding somehow.

Here is my C++ code:

#include<iostream>

#include "opencv2/opencv.hpp"

int main(int, char**) {
    cv::VideoCapture cap("data/DEVISSAGE_181.mj2"); // open the video file
    cap.set(CV_CAP_PROP_FORMAT, CV_16UC1);

    cv::Mat frame;
    cap.read(frame); // get a new frame from file

    std::cout << "frame.rows: " << frame.rows << ", frame.cols: " << frame.cols << ", frame.channels(): " << frame.channels() << std::endl;

    return 0;
}

The result of running this code is:

frame.rows: 288, frame.cols: 1152, frame.channels(): 3, frame.depth(): 0

Which indicates a 3 channels, CV_8U pixel encoding. Why does the cap.set instruction appear to be ignored ? What should I do to get the correct encoding ?

vkubicki
  • 1,104
  • 1
  • 11
  • 26
  • maybe the device doesn't accept to set those properties or the driver doesn't. If you're using windows you can have a look at videoInput library – Micka Sep 30 '16 at 18:33
  • My problem is that the device is actually a video file, the depth of which I know to be uint16. – vkubicki Oct 03 '16 at 09:08
  • not sure whether reading 16 bit videos without conversion is possiblr with opencv's videocapture class – Micka Oct 03 '16 at 10:18
  • OK... We will try to use Matlab and the video related toolboxes then ... – vkubicki Oct 03 '16 at 12:29
  • Might be related to this http://stackoverflow.com/questions/21555572/can-i-set-the-color-depth-while-capturing-the-webcam-image-using-opencv – shawndfernandes Feb 05 '17 at 00:35

0 Answers0