Ask Your Question
0

Convert RGBTRIPLE to cv::Mat

asked 2018-07-19 05:51:19 -0600

TinTin82 gravatar image

Hi,

i have a RGBTRIPLE Image pointer from DirectShow filter and i want to use it with OpenCV. How can i convert it to a cv::Mat structure ??

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-07-19 06:02:46 -0600

berak gravatar image

you can just wrap a Mat header around that:

given it's like this:

typedef uchar BYTE; 
typedef struct tagRGBTRIPLE {
  BYTE rgbtBlue;
  BYTE rgbtGreen;
  BYTE rgbtRed;
} RGBTRIPLE;

// demo data:  
RGBTRIPLE p[] = {{1,2,3}, {4,5,6}, {7,8,9}, {2,4,8}};

Mat a(2,2,CV_8UC3, p);

cout << a << endl;

[  1,   2,   3,   4,   5,   6;
   7,   8,   9,   2,   4,   8]

but, careful ! a Mat constructor with an "external" data pointer does neither allocate memory, nor copy the data !

(so your p pointer must not go out of scope, before you're finished with a)

you probably need like: Mat b = a.clone(); or some other processing, that does a "deep copy" after that !

edit flag offensive delete link more

Comments

Hi berak,

Thanks for the great answer. It works now. Unfortunately my OpenCV image is upside down. Can I copy the image while copying
Mat frame (cyImage, cxImage, CV_8UC3, prgb);
right at the horizontal axis reflect ?? (Or set a bit while showing - because no deep copy will be made)
Can a
waitKey (1)
cause problems in the DirectShow filter in the Transform method ?? imshow ("original", frame);
waitKey (1)

TinTin82 gravatar imageTinTin82 ( 2018-07-19 07:00:26 -0600 )edit

flip(a,b,0); will do, what you need there.

berak gravatar imageberak ( 2018-07-19 07:20:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-07-19 05:51:19 -0600

Seen: 128 times

Last updated: Jul 19 '18