Ask Your Question
0

Initialize MAT from pointer - help. [closed]

asked 2017-03-16 06:13:04 -0600

Soarez gravatar image

Hi, Im working with a camera, and the camera gives me the image in its own type of variable, that contains image width , height , depth , and other things.

In this data i receive a pointer for the first pixel , and i know that the RGB is organized like (assuming the image as n pixels), the first n address have the R, the next n address have the G and the last n address have the B.

So im trying to initialize the image like this.

cv::Mat dummy_query = cv::Mat(img->h, img->w, CV_8UC3, pData , 0 );

pData is the pointer from the first pixel. the 0 ,on openCV doc they say its the step , i really dont understand what is this step.

whit this i get some data to the matrix, but when i do the imshow nothing happens.

hope someone can help. =)

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2017-03-16 12:43:39.657558

2 answers

Sort by ยป oldest newest most voted
2

answered 2017-03-16 06:28:35 -0600

berak gravatar image

updated 2017-03-16 06:35:04 -0600

if your data comes as consecutive image "planes" you will need 3 seperate 1 channel Mat's with the color channels, and then merge them (we also need to swap b<-->r for opencv):

Mat chn[] = {
    Mat(img->h, img->w, CV_8UC1, pData + img->h*img->w*2),  // starting at 1st blue pixel 
    Mat(img->h, img->w, CV_8UC1, pData + img->h*img->w),    // 1st green pixel
    Mat(img->h, img->w, CV_8UC1, pData)                     // 1st red pixel
};

Mat bgr;
merge(chn,3,bgr);
imshow("my image !", bgr);
waitKey(33); // else it won't show anything
edit flag offensive delete link more

Comments

Looks like i have a 3 channel image now ,i print one col ...

although i cant see the image on imshow, but this could be other problem.

Soarez gravatar imageSoarez ( 2017-03-16 06:42:25 -0600 )edit

if you can't get it done - show us your attempt !

berak gravatar imageberak ( 2017-03-16 06:49:33 -0600 )edit

im just doing

namedWindow( "Display windsssow", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display windsssow",bgr);
cv::waitKey(3);

it should work =)

Soarez gravatar imageSoarez ( 2017-03-16 06:51:31 -0600 )edit

@berak , Im working on a thread, and on the main i can load images but on the thread i can't, and the same with display and imwrite.

Soarez gravatar imageSoarez ( 2017-03-16 07:17:19 -0600 )edit

yea, bad idea.

berak gravatar imageberak ( 2017-03-16 07:19:18 -0600 )edit

@berak so i cant do it on the thread?

Soarez gravatar imageSoarez ( 2017-03-16 07:29:08 -0600 )edit

at least you should not try to use gui functions in a thread

berak gravatar imageberak ( 2017-03-16 07:47:56 -0600 )edit

im getting images like this ...link text , do you have any idea why!?
http://imgur.com/a/8bXEG

Soarez gravatar imageSoarez ( 2017-03-16 09:02:17 -0600 )edit

well, that's definitely not correct. maybe your assumption about the input buffer was wrong ?

berak gravatar imageberak ( 2017-03-16 09:07:54 -0600 )edit

yeah, i already asked the seller waiting for response. Do you know what padding bytes mean!? for each image i recive a x_padding and y_padding, but i dont know what they mean.

Soarez gravatar imageSoarez ( 2017-03-16 09:17:11 -0600 )edit
0

answered 2017-03-16 12:40:55 -0600

Soarez gravatar image

@berak , its working , used the same think that i used on the question , because the images is 8bit packed RGB, so im sorry for your time , but thanks again =)

edit flag offensive delete link more

Comments

no worries ;)

berak gravatar imageberak ( 2017-03-16 12:43:58 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-03-16 06:13:04 -0600

Seen: 2,566 times

Last updated: Mar 16 '17