Error when get color from pixel in visual studio C++
This is function to get the color from a given Mat image,
string getColorFromPx(Mat *src, uint16_t x, uint16_t y){
Point pt = Point(x, y);
//Mat img = (*src).clone();
Vec3b& levelPxImg = imgHSV.at<Vec3b>(y, x);
if ((levelPxImg[0] != NULL) && (levelPxImg[1] != NULL) && (levelPxImg[2] != NULL)){
//H(openCV) / 2 = H (HSV_Real);
if (levelPxImg[0] > 170 && levelPxImg[0] < 180)
return "R";
else if (levelPxImg[0] > 107 && levelPxImg[0] < 122)
return "B";
else
return "xx";
}
}
the program can work for a period time after that it notify an error as below:
" First-chance exception at 0x00007FF64C1C30A3 in OpenCVex1.exe: 0xC0000005: Access violation reading location 0x0000000000000018. If there is a handler for this exception, the program may be safely continued. "
and current breakpoint is halted at return line as below:
int compare(const _Elem *_Ptr) const {// compare [0, _Mysize) with [_Ptr, <null>)
_DEBUG_POINTER(_Ptr);
-------> return (compare(0, this->_Mysize, _Ptr, _Traits::length(_Ptr))); }
(this function locate in VS/include/xstring file).
Please take a look and help me to show problem.
You should learn c++ debugger. When error throw use stack trace and select line with function name getColorFromPx. Then you will have all variable values. Check x and y values.
some bad things here:
Mat *src
, but you never use itlevelPxImg[0] != NULL
<-- it's not a pointer.Yes, I check it before I pass x and y, I think it has problem with the passing Mat, so I just replace it to the original matrix (for surely)