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:
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 think GetVideoData(hwnd, (char)&Frame, &dataLen, videofmt,&mediaSpeed); could be the problem. At first I would check (char)&Frame and try something like &Frame->data
I am sure that
is not a problem, because it works perfect and if i pass the native Frame->data to the renderer it draws the video even with 30 fps without a problems..
But when i am trying to pass the processed Mat to renderer there is a problem:
I feel that the problem somewhere in (char*)displayedFrame.data. I think that the renderer doesnt recognize it as native Frame->data format that is of type char data[0];
The second part of the problem is in:
Becase i think it is not properly copy the char* data from Frame to Mat, maybe it requires some decoding i have no idea. If i put the displayedFrame to imshow() just after i memcpy() it to Mat it will not be drawn properly.
The broblem is clear for now. How to convert BGR24 to YUYV422 that i can draw it with DrawVideoImage function? Wich CV_8U option to use (CV_8UC1,CV_8UC2,CV_8UC3,CV_8UC4) and wich option to use for cv::CvtColor(dst,src, ????).
Can anybody share a working pixel convertion function. I cant find the right solution fo my problem..