converting byte array [] to cv::Mat problems

asked 2016-06-04 07:14:51 -0600

stillNovice gravatar image

updated 2016-06-04 08:55:33 -0600

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

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:

I have tried other formats in place of CV_8UC4, but see other, worse issues. What am I missing ?



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).
BOOL smx16eXX_GetFrameEx8 (HANDLE H, PVOID Buffer, size_t length)
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.
The function supplies frame data linearly converted from 16bpp to 8bpp
edit retag flag offensive close merge delete


please spare us duplicate questions (took liberty to delete the other)

berak gravatar imageberak ( 2016-06-04 07:25:06 -0600 )edit

Sorry! I though it had failed.

stillNovice gravatar imagestillNovice ( 2016-06-04 07:30:18 -0600 )edit

no problem. due to a lot of spam, this site has to go moderated, posts are stuck in the queue, just needs somepatience.

berak gravatar imageberak ( 2016-06-04 07:36:22 -0600 )edit

ok, will be more careful in future. :) While you are here... I couldn't trouble you for an opinion on my issue could I? :)

stillNovice gravatar imagestillNovice ( 2016-06-04 07:42:27 -0600 )edit

have you a documentation or source about smx16eXX_GetFrameEx8 function?

sturkmen gravatar imagesturkmen ( 2016-06-04 08:46:47 -0600 )edit

I have edited the question to contain the relevant info. Thanks!

stillNovice gravatar imagestillNovice ( 2016-06-04 08:50:19 -0600 )edit


cv::Mat newImg = cv::Mat(H, W, CV_8UC1, framemaster + FRAMEINFO_SIZEF );
sturkmen gravatar imagesturkmen ( 2016-06-04 09:01:12 -0600 )edit

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)

berak gravatar imageberak ( 2016-06-04 09:03:37 -0600 )edit

cv::Mat newImg = cv::Mat(H, W, CV_8UC1, framemaster + FRAMEINFO_SIZEF ); gives me: this

stillNovice gravatar imagestillNovice ( 2016-06-04 09:37:34 -0600 )edit

cv::Mat newImg = cv::Mat(H, W, CV_8UC3, framemaster + FRAMEINFO_SIZEF ); gives this

stillNovice gravatar imagestillNovice ( 2016-06-04 09:40:51 -0600 )edit