image show have some errors

asked 2017-09-07 20:47:09 -0600

I accept the unsigned char type data from the camera using the opencv class of mat, Then use the imshow function to display in the window, but do not know why the image displayed is a bit of a problem, The following section of the image is normal, but the upper part is abnormal purple. What's the reason for that?Can you explain it? Thank you。 image description

edit retag flag offensive close merge delete

Comments

Can you post code creating Mat ?

Ziri gravatar imageZiri ( 2017-09-07 23:20:46 -0600 )edit

Mat imt(960,1280,CV_8UC3,ImgData);

Mat imt_dst;

resize(imt,imt_dst,Size(640,480),0,0,CV_INTERLINEAR);

namedWindow("imt",1);

namedWindow("imt_dst",1);

imshow("imt",imt);

imshow("imt_dst",imt_dst);

cvWaitKey(0);

destroyWindow("imt");

destroyWindow("imt_dst",imt_dst);

QinXiaoXu gravatar imageQinXiaoXu ( 2017-09-07 23:49:06 -0600 )edit

You need right step parameter .

C++: Mat::Mat(Size size, int type, void* data, size_t step=AUTO_STEP)

Ziri gravatar imageZiri ( 2017-09-08 01:41:06 -0600 )edit

well,how to set up it?

QinXiaoXu gravatar imageQinXiaoXu ( 2017-09-08 02:05:29 -0600 )edit

if you'are getting data and width/height from camera you'll be able to get step as well , pass it like this:

Mat(Size(width , height), type ,data, step)

Ziri gravatar imageZiri ( 2017-09-08 02:11:45 -0600 )edit

I set it Mat imt(Size(1280,960),CV_8UC3,ImgData,1280*3); it still wrong,is my set is wrong?

QinXiaoXu gravatar imageQinXiaoXu ( 2017-09-08 02:58:58 -0600 )edit

did you try : AUTO_STEP ? if it's not working search camera API how to get step parameter .

Ziri gravatar imageZiri ( 2017-09-08 03:00:31 -0600 )edit

it show use of undeclared identifer ‘AUTO_STEP’,which include file it define at?

QinXiaoXu gravatar imageQinXiaoXu ( 2017-09-08 03:04:54 -0600 )edit

Mat::AUTO_STEP

Ziri gravatar imageZiri ( 2017-09-08 03:06:30 -0600 )edit

image is still wrong

QinXiaoXu gravatar imageQinXiaoXu ( 2017-09-08 03:09:33 -0600 )edit