convert char** to cv::Mat
Hi to everyone! I am trying to convert raw image data from my IP camera to cv::Mat. But can't do it properly. My IP camera use it's own library to retrieve images. This function looks like
GetVideoData(hwnd, (char**)&Frame, &dataLen, videofmt,&mediaSpeed);
Frame has a data buffer of type char data[0] in it's struct; Can anybody help me to find out how to convert Frame->data to cv::Mat?
I tried to do it like:
cv::Mat cameraFrame = cv::Mat(h, w, CV_8UC1, Frame->data);
But when i am trying to show it with imshow("name",cameraFrame); it looks like gray and very pure image.. C:\fakepath\Screen.JPG
what is
Frame
, exactly ? please show us the declaration. same withGetVideoData()
Here is the declaration of GetVideoData function:
Here is struct of the Frame datatype:
I need only Frame->data. This is the data of the image from IP camera stream. Finally i need to convert it to cv::Mat, make facerecognition processing, and convert the image back to char* data, that i can draw it with IP camera function
Also i tried to use another way of convertion, and it behaves different. Here i convert the Frame->data to cv:Mat:
make some face recognition processing with cameraFrame and finally trying to draw the image this way:
And now i got the color image, but it seems like it mirrored or i dont know how to explaine. Here is a link i upload the screen shot.
</a">link text
If i use imshow() instead of DrawVideoIamge(). I've got the gray image like on the previos screen i posted.
try
cv::Mat cameraFrame = cv::Mat(h, w, CV_8UC3, Frame->data);
CV_8UC3 doesn't work for this code(throws c000005):
If use CV_8UC3 with this code:
Results the almost the same as for CV_8UC1. But now it lookes like triple image.
Here is CV_8UC3 with imshow():
Here is CV_8UC3 with DrawVideoIamge():
try
Just tried:
It throws an exception on the memcpy line of code:
what is dataLen value and w and h value?
I don't think copying to a
Mat
is your problem, but getting the right data. When I look at the Frame struct, I see that there's more than just the data container. So I thinkcould be the problem. At first I would check
(char**)&Frame
and try something like&Frame->data
I want to post the full function code. But there is not enough space for comments. I will post it in slices
Here is global variables:
Function:
@Bilityuk, rather edit your question, and add further information there, than making multiple comments
(the outcome will be much more readable / useful)
here's the beef :)
DECFMT videofmt = DECTYPE_YUYV422;
&Frame->data doesnt make any sence in compare with Frame->data The same result.
berak, can you explaine please wich way to dig? DECFMT has the following types:
Here is the rest of the enum: