Forward() Fails: Vector Subscript Out Of Range C++, Vector Subscript Out Of Range

What is the reason why the OpenCV program reports vector subscript out of range?

#include “opencv2/objdetect/objdetect.hpp”#include “opencv2/highgui/highgui.hpp”#include “opencv2/imgproc/imgproc.hpp”#include #include using namespace std;using namespace cv;/** Function declaration */void detectAndDisplay(Mat frame); /** Global variables */string face_cascade_name = “haarcascade_frontalface_alt.xml”;string eyes_cascade_name = “haarcascade_eye_tree_eyeglasses.xml”;CascadeClassifier face_cascade;CascadeClassifier eyes_cascade;string window_name = “Capture – Face detection”;RNG rng(12345); /**
Main function */int main(int argc, const char** argv){ CvCapture* capture; Mat frame; //— 1. Load the cascade classifier file if (!face_cascade.load(face_cascade_name)){ printf(“–(!)Error loading
“); return -1; }; if (!eyes_cascade.load(eyes_cascade_name)){ printf(“–(!)Error loading
“); return -1; }; //— 2. Open the video stream of the built-in camera capture = cvCaptureFromCAM(0); //If the screen is still gray, change it to -1 and try if (capture) { while (true) { frame = cvQueryFrame(capture); //Grab and return a frame from the camera or file //— 3. Use the classifier to detect the current frame if (!frame.empty()) { detectAndDisplay(frame); } else { printf(” –(!) No captured frame — Break!”); break; } int c = waitKey(10); if ((char)c == “c”) { break; } } } return 0;} /**
function detectAndDisplay */void detectAndDisplay(Mat frame){ std::vector faces; Mat frame_gray; faces.resize(50000); cvtColor(frame, frame_gray, CV_BGR2GRAY); equalizeHist(frame_gray, frame_gray); //— multi-size face detection face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30)); for (int i = 0; i eyes; eyes.resize(50000); //— detect both eyes on each face eyes_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30)); for (int j = 0; j This is a simple program that obtains the camera and then performs face recognition, eyes.resize(50000); and the previous resize is added by myself, but after the program runs for a while (about five minutes), report the vector subscript out of range error

cvRound((eyes.width + eyes.height)*0.25); // The j for eyes is typed wrong here


Intelligent Recommendation



Expression:vector subscript out of range


The reason for this problem is that the vector container subscript is out of range, that is, the array is out of bounds.   The shortcut sentence I have always used when chatting …

Đang xem: Vector subscript out of range c++


OpenCV:vector subscript out of range


Wrong vector subscript out of range Source modify…




Two-dimensional vector, please be cautious about clear() operation, beware of vector subscript out of range problems


Today, I want to use vector to realize the function of two-dimensional array, and I tried to use two-dimensional vector. Who knew that I met Lei when I first started. The form of the code is roughly a…




PCL learning: Surface reconstruction based on B-spline curve: Error in the program “Expression: vector subscript out of range”


In debug mode: Error when executing code: The reason has not been located yet; however, replacing other pcd files, modifying the input parameters, can run normally; or curve_params.accuracy is set to …




C++:vector out of range


#C++:vector out of range# The following error was reported when debugging the code today. As a C++ novice, I was also confused. I did not find the reason for debugging for a long time. Later, I carefu…

Read more: Which Boon Do You Prefer? : Wow Boon Of The Butcher Which Boon Do You Prefer


More Recommendation




VS debug C ++ pop-up window throws an exception: debug assertion failed! Expression: Vector Subscript Out of Range XXXXXXX


Generate the above errors when running C ++ code, the cause of this error is generally caused by invalid memory, such as: Generally use invalid iterators can also result in access to invalid memory, a…


Vector resize failed, resulting in subscript out of bounds


Today I received a dump from other groups, and the analysis showed that the stack is as follows Find the corresponding code as follows The red box is the dump corresponding code. The first reaction is…


swing table row is deleted subscript out of range error


If you delete a row in the swing, subscript error occurs because a line is still in edit mode, you must first cancel its editorial states: …


c++ Expression: vector iterator + offset out of range


I encountered this problem when writing code today The error of this function is that the addition of the iterator is out of bounds, because mybigFlow()The function return value is between -1 and n, s…

Read more: Wow You Hear A Faint Caw In The Distance And Then Silence, Long Forgotten Hippogryph


The vector iterator offset out of range problem in C++


C++ primer 3.24 iterator problem Error code display: The main purpose of this program is to use an iterator to find the sum of two numbers before and after a set of numbers. Report an error after runn…

Leave a Comment