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

VideoCapture is very slow in OpenCV 3.1

$
0
0
Hi to everyone! I am trying to get an mjpg videostream from ip camera Foscam 9831p (30 fps max) and run the face recognition code. But the VideoCapture frame rate is very very slow. I use realese mode libraries, also trying to run the code in separate thread.. Can anybody advice please wich technics to use to run the VideoCapture stream with face recognition at least with 15-20 FPS??? I run the stream from ip camera without opencv processing in internet explorer and it runs very fast with 25 fps.. But in opencv face recognition project i can't get even 2-3 fps... Also i tried the hardware notebook web cam to set to VideoCapture and it runs relatively fast. Can anybody share a solution please? Here is my code (As separate thread i use DWORD ThreadRun WIN32 Api function): //load pre-trained data sets Ptr model = cv::face::createFisherFaceRecognizer(num_compFisher,thresholdFisher); model->load("C:\\Users\\Alexey\\Documents\\Visual Studio 2012\\Projects\\RaptorBOT_PC_Control\\С++\\RaptorBOT_PC_Control\\OpenCV3.1\\IMG_DB\\YML\\fisherface.yml"); Mat testSample = imread("C:\\Users\\Alexey\\Documents\\Visual Studio 2012\\Projects\\RaptorBOT_PC_Control\\С++\\RaptorBOT_PC_Control\\OpenCV3.1\\IMG_DB\\DB_Bilityuk_Alexey\\Snapshot_20160106.JPG"); int img_width = testSample.cols; int img_height = testSample.rows; string classifier = "C:\\Program Files\\opencv\\build_\\install\\etc\\haarcascades\\haarcascade_frontalface_default.xml"; CascadeClassifier face_cascade; string window = "Capture - face"; if (!face_cascade.load(classifier)){ cout << " Error loading file" << endl; } VideoCapture cap("http://ip/Cgi/GetMjpgstream/&.mjpg); if (!cap.isOpened()) { cout << "exit" << endl; } //double fps = cap.get(CV_CAP_PROP_FPS); //cout << " Frames per seconds " << fps << endl; //namedWindow(window, 1); int count = 0; while(true) { vector faces; Mat frame; Mat graySacleFrame; Mat original; cap >> frame; //cap.read(frame); count = count + 1;//count frames; if (!frame.empty()){ //clone from original frame original = frame.clone(); //convert image to gray scale and equalize cvtColor(original, graySacleFrame, CV_BGR2GRAY); //equalizeHist(graySacleFrame, graySacleFrame); //detect face in gray image face_cascade.detectMultiScale(graySacleFrame, faces, 1.1, 3, 0, cv::Size(80, 80)); //face_cascade.detectMultiScale(graySacleFrame, faces); //number of faces detected cout << faces.size() << " faces detected" << endl; std::string frameset = SSTR(count); std::string faceset = SSTR(faces.size()); int width = 0, height = 0; //region of interest //cv::Rect roi; //person name string Pname = ""; for (int i = 0; i < faces.size(); i++) { //region of interest Rect face_i = faces[i]; //crop the roi from grya image Mat face = graySacleFrame(face_i); //resizing the cropped image to suit to database image sizes Mat face_resized; cv::resize(face, face_resized, Size(img_width, img_height), 1.0, 1.0, INTER_CUBIC); //recognizing what faces detected int label = -1; double confidence = 0; model->predict(face_resized, label, confidence); cout << " confidencde " << confidence << endl; cout << " label " << label << endl; //drawing green rectagle in recognize face rectangle(original, face_i, CV_RGB(255, 0, 0), 1); string text = "Opredelen"; if (label == 1){ //string text = format("Person is = %d", label); Pname = "Alexey"; } if (label == 2){ Pname = "Tanya"; } if (label == -1 || label == 0){ Pname = "Neizvestniy"; } int pos_x = std::max(face_i.tl().x - 10, 0); int pos_y = std::max(face_i.tl().y - 10, 0); //name the person who is in the image putText(original, text, Point(pos_x, pos_y), FONT_HERSHEY_COMPLEX_SMALL, 1.0, CV_RGB(255, 0, 0), 1.0); //cv::imwrite("E:/FDB/"+frameset+".jpg", cropImg); } putText(original, "Kadrov: " + frameset, Point(30, 60), CV_FONT_HERSHEY_COMPLEX_SMALL, 1.0, CV_RGB(255, 0, 0), 1.0); putText(original, "Imya: " + Pname, Point(30, 90), CV_FONT_HERSHEY_COMPLEX_SMALL, 1.0, CV_RGB(255, 0, 0), 1.0); //display to the winodw cv::imshow("IDC_STATIC", original); //cout << "model infor " << model->getDouble("threshold") << endl; } if (waitKey(30) >= 0) break; }

Viewing all articles
Browse latest Browse all 41027

Trending Articles



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