Ask Your Question

deepmore's profile - activity

2017-04-11 05:18:27 -0600 answered a question Opencv IP Camera Error

when u close the wifi it's totally normal for it to crash because you're using an ip camera !! without wifi you will have no access on it.

2017-03-16 02:38:15 -0600 received badge  Enthusiast
2017-03-13 09:14:36 -0600 asked a question lag in opencv videocapture when i use rtsp camera stream

So i'm currently working on a project that needs to do a facial recognition on rtsp ip cam , i managed to get the rtsp feed with no problems, but when it comes to applying the face recognition the video feed gets too slow and shows a great delay, i even used multithreading to make it better but with no success,here is my code i'm still a beginner in multi threading matters so any help would be appreciated.

 #include <iostream>
#include <thread>
#include "opencv2/opencv.hpp"

#include <vector>
using namespace std;
using namespace cv;
void detect(Mat img, String strCamera) {
    string cascadeName1 = "C:\\ocv3.2\\Build\\install\\etc\\haarcascades\\haarcascade_frontalface_alt.xml";
    CascadeClassifier facedetect;
    bool loaded1 = facedetect.load(cascadeName1);
    Mat original;
    img.copyTo(original);
    vector<Rect> human;
    cvtColor(img, img, CV_BGR2GRAY);
    equalizeHist(img, img);
    facedetect.detectMultiScale(img, human, 1.1, 2, 0 | 1, Size(40, 80), Size(400, 480));
    if (human.size() > 0)
    {
        for (int gg = 0; gg < human.size(); gg++)
        {
            rectangle(original, human[gg].tl(), human[gg].br(), Scalar(0, 0, 255), 2, 8, 0);
        }
    }
    imshow("Detect " + strCamera, original);
    int key6 = waitKey(40);
    //End of the detect
}
void stream(String strCamera) {
    VideoCapture cap(strCamera);
    if (cap.isOpened()) {
        while (true) {
            Mat frame;
            cap >> frame;
            resize(frame, frame, Size(640, 480));
            detect(frame, strCamera);
        }
    }
}
int main() {
    thread cam1(stream, "rtsp://admin:password@ipaddress:554/live2.sdp?tcp");
    thread cam2(stream, "rtsp://admin:password@ipaddress/live2.sdp?tcp");
    cam1.join();
    cam2.join();
    return 0;
}
2017-02-14 03:01:09 -0600 commented answer How to count faces in the video?

hey anje can you provide the final code with the face count displayed and all ? thank you