Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

problems with running OpenCV code

$
0
0
Hello, I train the cascade classifier to detect letters, here is the code I'm running: #include "opencv2/objdetect.hpp" #include "opencv2/highgui.hpp" #include "opencv2/imgproc.hpp" #include #include using namespace std; using namespace cv; /** Function Headers */ void detectAndDisplay(Mat frame); /** Global variables */ String letter_cascade_name = "C:\\opencv\\sources\\data\\haarcascades_GPU\\letters_cascade.xml"; CascadeClassifier letter_cascade; String window_name = "Capture - letter detection"; /** @function main */ int main(void) { VideoCapture capture; Mat frame; //-- 1. Load the cascades if (!letter_cascade.load(letter_cascade_name)) { printf("--(!)Error loading face cascade\n"); return -1; }; //-- 2. Read the video stream capture.open(0); if (!capture.isOpened()) { printf("--(!)Error opening video capture\n"); return -1; } while (capture.read(frame)) { if (frame.empty()) { printf(" --(!) No captured frame -- Break!"); break; } //-- 3. Apply the classifier to the frame detectAndDisplay(frame); int c = waitKey(10); if ((char)c == 27) { break; } // escape } return 0; } /** @function detectAndDisplay */ void detectAndDisplay(Mat frame) { std::vector letters; Mat frame_gray; cvtColor(frame, frame_gray, COLOR_BGR2GRAY); equalizeHist(frame_gray, frame_gray); //-- Detect faces letter_cascade.detectMultiScale(frame_gray, letters, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(30, 30)); for (size_t i = 0; i < letters.size(); i++) { Point center(letters[i].x + letters[i].width / 2, letters[i].y + letters[i].height / 2); ellipse(frame, center, Size(letters[i].width / 2, letters[i].height / 2), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0); } //-- Show what you got imshow(window_name, frame); } When I start the program, it opens my web cam but doesn't show the image (frames) and the detection but just a single blank window. I noticed this line causes the problem: letter_cascade.detectMultiScale(frame_gray, letters, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(30, 30)); What should I do to make it show the captured frames and start detecting? Thank you.

Viewing all articles
Browse latest Browse all 19555

Latest Images

Trending Articles



Latest Images

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