converting byte array [] to cv::Mat problems
Hi, I have a Sumix usb3 camera, and am attempting to stream into cv::Mat.
The data comes in as a byte[]:
#define FRAMEINFO_SIZEF 4096
#define MAX_FRAME_SIZE (MAX_FRAME_SIZEX*MAX_FRAME_SIZEY)
#define MAX_FRAME_SIZE_RAW (2*MAX_FRAME_SIZE+FRAMEINFO_SIZEF)
BYTE framemaster[MAX_FRAME_SIZE_RAW + FRAMEINFO_SIZEF];
And I run:
int W = 640;
int H = 480;
if (smx16eXX_GetFrameEx8(H_master, framemaster, MAX_FRAME_SIZE_RAW + FRAMEINFO_SIZEF))
{
std::cout << "got cameras" << std::endl;
cv::Mat newImg = cv::Mat(H, W, CV_8UC4, framemaster);
cv::imshow("yes", newImg);
}
The image that I get is squashed horizontally, and doubled. Please see:
http://pasteboard.co/1qM0BFvA.jpg
I have tried other formats in place of CV_8UC4, but see other, worse issues. What am I missing ?
Thanks!
edit:
The ducumentation for the function smx16eXX_GetFrameEx8 is:
The smx16eXX_GetFrameEx8 function is used to retrieve frame data containing frame statistics, frame parameters and events to user indicated memory buffer (8 bits per pixel).
Syntax
BOOL smx16eXX_GetFrameEx8 (HANDLE H, PVOID Buffer, size_t length)
Parameters:
H [in] - HANDLE, device handle
Buffer [in] - PVOID, points to user allocated buffer
length [in] - size_t variable that contains size of the buffer
Return value:
BOOL - TRUE if function succeeds, FALSE otherwise.
Remarks
The function supplies frame data linearly converted from 16bpp to 8bpp
please spare us duplicate questions (took liberty to delete the other)
Sorry! I though it had failed.
no problem. due to a lot of spam, this site has to go moderated, posts are stuck in the queue, just needs somepatience.
ok, will be more careful in future. :) While you are here... I couldn't trouble you for an opinion on my issue could I? :)
have you a documentation or source about
smx16eXX_GetFrameEx8
function?I have edited the question to contain the relevant info. Thanks!
try
CV_8UC4 is unlikely the right one. either CV_8U for 1channel or CV_8UC3 for 3
but good, that you added the description: if it's converted from 16bit to 8bit, my guess is, you too the wrong buffersize, try MAX_FRAME_SIZE, not MAX_FRAME_SIZE_RAW (which i guess, is for the raw 16bit signal)
cv::Mat newImg = cv::Mat(H, W, CV_8UC1, framemaster + FRAMEINFO_SIZEF );
gives me: thiscv::Mat newImg = cv::Mat(H, W, CV_8UC3, framemaster + FRAMEINFO_SIZEF );
gives this