Ask Your Question
0

Accessing pixel value with .at<uchar> and .at<Vec3b> does not work

asked 2014-03-06 13:53:58 -0600

Andrey Gaganov gravatar image

updated 2014-03-07 02:46:21 -0600

berak gravatar image

I am trying to rewrite the value for a pixel in a Mat-type grayscale image using Visual Studio Express 2012 for Windows Desktop. I've tried:

1) imgGrayComp.at<uchar>(5, 4) = 0;

2) imgGrayComp.ptr(4)[5] = 0;

3) imgGrayComp.at<vec3b>(5, 4) = 0;

But it gives me this instead:

OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (unsigned)(i1DataType<_Tp>::channels) < (unsigned)(size.p[1]channels()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in cv::Mat::at, file c:\opencv\build\include\opencv2\core\mat.hpp, line 537

edit retag flag offensive close merge delete

Comments

I think there are some problem in Visual Studio "Express" 2012 combine opencv

wuling gravatar imagewuling ( 2014-03-06 18:35:44 -0600 )edit

^ No ... I've been told that the problem lies in the use of image.convertTo(imageGrayClassify, COLOR_BGR2GRAY); instead of cvtColor(image, imageGrayClassify, COLOR_BGR2GRAY ); ... but once I substituted the calls, I get OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv::cvtColor, file ..\..\..\..\opencv\modules\imgproc\src\color.cpp, line 3737 on the command prompt.

Andrey Gaganov gravatar imageAndrey Gaganov ( 2014-03-06 18:40:31 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-03-12 04:49:03 -0600

Andrey Gaganov gravatar image

updated 2014-03-12 04:50:30 -0600

I've received a number of adequate answers on StackOverflow (see here). Turns out I had two problems, not just one. Not only was I using a wrong function (I should have used cv::cvtColor(image, imageGrayClassify, CV_BGR2GRAY) instead of image.convertTo(imageGrayClassify, COLOR_BGR2GRAY) ), but I also used a reference to an image that wasn't in the indicated path (I should have backed out into the parent directory and then go into the "src" directory where I keep all images). I've decided to stick with .ptr instead of .at<uchar> .

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-03-06 13:53:58 -0600

Seen: 2,894 times

Last updated: Mar 12 '14