IP camera video stream opencv and people detection

Follow

My favourite

  • Opencv tutorial people detection
  • Head people cascade download
  • Opencv tutorial optical flow
  • Opencv Video stabilization
  • Opencv car dataset download
  • Opencv tutorial Transparent mask
  • Opencv videowriter
  • Opencv FFMPEG
  • Opencv Canny edge and hough lines
  • Video capture IP camera stream in opencv and people detection 


    Opencv video stream rtsp mjpeg

    In that tutorial, I just want to introduce how to read the more video streams in threads. In some cases you need to have FFMPEG installed. Hopefully, Windows nuger default instalation in Visual Studio should be enaught.. Let me know if there is some problem. 

    Opencv environmen for tutorial

    Just use the instalation of Opencv in Visual Studio 2015 by Nuget packages. In package console just type and wait for message that your opencv is succesfully instaled in your project. More info in tutorial Here
    Type to package console
    PM>  Install-Package opencvdefault

    On the Linux distribution i can recommend my tutorial Here. In case of Debian like packages.

    Opencv video stream verification

    http://IP:PORT/mjpeg/video.mjpg?counter
    rtsp://IP:PORT/various url

    Find your IP camera model on http://www.ispyconnect.com
    Select for example for Axis and the model..
    There is various stream url for each of this. There is no standard way of URL format.
    Find your for the camera and model.
    rtsp://IP:PORT/axis-cgi/mjpg/video.cgi
    http://IP:PORT/mjpg/video.mjpg

    And milion of others different kind of URL formats.

    Opencv tutorial code IP camera pseudo code

    There is 3 function.. 
    First of all, the main function at the end, where are established 2 threads to read the camera stream..

    In Main
    • Thread call the stream function for both camera with different IP camera URL                       thread cam1(stream, "http://xxxxxxxR");
    • To run the function stream inside the thread with url as parametr use.                       cam1.join();
    void stream

    • Capture video from url strCamera VideoCapture cap(strCamera) 
    • Fill the frame from cap  cap >> frame;
    • Detect people in camera detect(frame, strCamera);
    void detect


    Opencv C++ IP camera code


    
    
    
    #include <iostream>
    #include <thread>
    #include "opencv2/opencv.hpp"
    #include <vector>
    using namespace std;
    using namespace cv;
    void detect(Mat img, String strCamera) {
      string cascadeName1 = "haar_cascade_for_people_detection.xml";
      CascadeClassifier detectorBody;
      bool loaded1 = detectorBody.load(cascadeName1);
      Mat original;
      img.copyTo(original);
      vector human;
      cvtColor(img, img, CV_BGR2GRAY);
      equalizeHist(img, img);
      detectorBody.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, "http://xxxxxxxR");
        thread cam2(stream, "http://xxxxxxxR");
        cam1.join();
        cam2.join();
        return 0;
    }
    
    

    4 comments:

    1. Replies
      1. Thank you. It is important sometime to have install ffmpe.
        For camera reading I am using threads to lock the resources. for example for 3 4 ip address..

        #include
        This call function stream.
        thread cam1(stream, "http://90.1xxxxxxxxxxxjpg",1);
        cam1.join();

        Inside stream there is a standard reading loop of opencvg input sources
        void stream(String strCamera, int mode) {
        }




        Delete
    2. is this works with WiFi ip camera

      ReplyDelete
    3. شرکت هوشمند افزار آسیا یکی از قدرتمند ترین شرکت های حوزه سیستم های امنیتی و نظارت تصویری و دوربین های مداربسته
      نماینده فروش دوربین های مداربسته هایک ویژن در کرج و تهران

      نصب دوربین مداربسته
      نماینده فروش دوربین های مداربسته هایک ویژن در کرج و تهران
      نماینده فروش دوربین های مداربسته هایک ویژن در کرج و تهران

      مجله تخصصی دوربین مداربسته و سیستم های حفاظتی و امنیتی
      02634216001-02634216002

      ReplyDelete

    ad