Convert RGBTRIPLE to cv::Mat
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 ??
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 ??
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 !
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)
Asked: 2018-07-19 05:51:19 -0600
Seen: 128 times
Last updated: Jul 19 '18
What is the most effective way to access cv::Mat elements in a loop?
Is there penalty for reference counting in Mat?
Saving an image with unset pixels
android: how to put a column into Mat
Find pixel color out of cv::Mat on specific position
How to update Mat with multiple channels?