I am runing web-cam, trying to detect object in real time and I have this code running. It gives me error at video.main(video.java:92) - CvRect sq = cvBoundingRect(ptr, 0); But I am checking if(ptr != null) . I don't understand why.
CvMemStorage storage = CvMemStorage.create();
CvSeq contours = new CvContour(null);
noOfContors = cvFindContours(imgbin, storage, contours, Loader.sizeof(CvContour.class), CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE, new CvPoint(0,0));
for (ptr = contours; ptr != null; ptr = ptr.h_next()) {
if(ptr != null){
CvRect sq = cvBoundingRect(ptr, 0);
if(sq.height()*sq.width() > minAreaa && sq.height()* sq.width() < maxAreaa){
p1.x(sq.x());
p2.x(sq.x()+sq.width());
p1.y(sq.y());
p2.y(sq.y()+sq.height());
cvRectangle(img1, p1, p2, CV_RGB(255, 0, 0), 2, 8, 0);
}
}
}
In command window:
OpenCV Error: Null pointer (NULL array pointer is passed) in unknown function, file ..\..\..\src\opencv\modules\core\src\array.cpp, line 2382
Exception in thread "main" java.lang.RuntimeException: ..\..\..\src\opencv\modules\core\src\array.cpp:2382: error: (-27) NULL array pointer is passed
at com.googlecode.javacv.cpp.opencv_imgproc.cvBoundingRect(Native Method)
at video.main(video.java:92)
NULLarray pointer.