Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

Vector Subscript Out of Range - what does it mean and how to solve it?

$
0
0
Hello, I had been using the code for single image and it had working fine. But today I want to have it to run using video. Error now vector subscript out of range. What is that mean? #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #define PI 3.14159265 #include #include #include #include using namespace cv; using namespace std; int edgeThresh = 1; int lowThreshold,minthreshold; int const max_lowThreshold = 100; int const max_houghlowThreshold = 100; int ratio = 3; int kernel_size = 3; Mat frame, frame_gray, dst, cdst,imHSV, frame_rgb, draw; Mat hsv_channels[3]; int flag_off=0; ofstream outputfile; double pixelwhitevalue [5]; char filename[80]; RNG rng(12345); double TOTALM00; double TOTALLength; int main(int argc, char** argv) { VideoCapture cap("C:\\db\\Day3Full\\13pm.wmv"); Mat mask =imread("c:\\db\\maskcrop.jpg",1); while(1) { bool bSuccess = cap.read(frame); // read a new frame from video if (!bSuccess) //if not success, break loop { cout << "Cannot read the frame from video file" << endl; break; } imshow("MyVideo", frame); draw = frame.clone(); Rect rectangle (0,200,frame.cols,frame.rows/2); frame = frame(rectangle); bitwise_and(frame,mask,frame); imshow("aftermask",frame); cvtColor(frame, frame_gray, CV_BGR2GRAY); threshold(frame_gray, frame_gray, 190, 255, THRESH_BINARY); erode(frame_gray, frame_gray, Mat()); dilate(frame_gray, frame_gray, Mat()); imshow("clean binary", frame_gray); vector< vector> contours; findContours(frame_gray, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE); vector mu(contours.size() ); for( int i = 0; i < contours.size(); i++ ) { mu[i] = moments( contours[i], false ); TOTALM00 = TOTALM00 + mu[i].m00; } Moments mom = cv::moments(contours[0]); double hu[7]; HuMoments(mom, hu); vector mc( contours.size() ); for( int i = 0; i < contours.size(); i++ ) { mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 ); std::cout << "x1 " << mc[i] << std::endl; } Point2f a = mc[0]; Point2f b = mc[1]; double res = cv::norm(a-b); std::cout << "Res" <

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>