opencv IP camera video stream capture and people detection

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 installation in Visual Studio should be enough. Let me know if there is any problem. Opencv video stream rtsp mjpeg

Opencv environment for tutorial

Just use the installation of Opencv in Visual Studio 2015 by Nuget packages. In package console just type and wait for the message that your opencv is successfully installed 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 the 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 imgString 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.120 | 1Size(4080), Size(400,480 ));
  if (human.size() > 0
    {
      for (int gg = 0; gg < human.size(); gg++) 
      {
      rectangle(original, human[gg].tl(), human[gg].br(), Scalar(00255), 280);
      }
    }
  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(640480));  
        detect(frame, strCamera);
     }
   }
}
int main() {
    thread cam1(stream, "http://xxxxxxxR");
    thread cam2(stream, "http://xxxxxxxR");
    cam1.join();
    cam2.join();
    return 0;
}
Next Post Previous Post
14 Comments
  • Unknown
    Unknown January 24, 2017 at 10:31 PM

    This post is very useful. Thnks for sharing it.
    CCTV Camera Dealers | Fire Hydrant Dealers in India

    • Vl
      Vl January 28, 2017 at 5:10 AM

      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) {
      }




  • Unknown
    Unknown June 16, 2017 at 6:42 PM

    is this works with WiFi ip camera

  • علی عباسپور
    علی عباسپور August 13, 2017 at 10:17 PM

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

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

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

  • Shipgig
    Shipgig February 12, 2018 at 1:47 AM

    Thank you for sharing like this information. If you want more information regarding CCTV Camera visit shipgig website.

  • Unknown
    Unknown May 4, 2018 at 5:37 AM

    Very good post. we are doing CCTV Industry in chennai. Thank you.
    CCTV Camera Dealers in Chennai
    CCTV Camera Installation Chennai

  • Unknown
    Unknown May 25, 2018 at 5:22 AM

    thanks

  • Unknown
    Unknown May 25, 2018 at 5:29 AM

    This is a great article, this provide more information in it, these type of articles keeps the users interest on a security camera for homes and business. Thanks for sharing good information and keep on sharing more content.
    Thanks and Regards,
    Jordan Caver
    Home Theater Vancouver
    Home Theater Toronto

  • jhon
    jhon July 5, 2018 at 3:37 AM

    . I will be using it to pan the FourthFest activities in Bayfront Park and the Harbor in general.https://www.cameresupraveghereieftine.ro/19-kit-camere-supraveghere

  • lovephileo2
    lovephileo2 July 30, 2018 at 10:49 PM

    Accurate multiple person counting program using OpenCV and Visual Studio. Axis camera

  • Ener-jblog
    Ener-jblog September 3, 2018 at 10:39 PM

    Fantastic and useful we blog thanks for publishing this.it's useful and informative.keep up the great.
    ENER-J CCTV Security Camera

  • Minh Định
    Minh Định October 21, 2018 at 8:19 AM

    HighMark Security is a direct supplier of security cameras, video surveillance systems, and CCTV equipment. We supply analog CCTV cameras, HD security cameras, IP cameras, and complete video surveillance systems worldwide. We supply our equipment to homeowners, business owners, government agencies, and any other type of organization, any size. Most of our business comes from the Da Nang, however, we do ship our products everywhere in the world. No project is too small or too large for us to handle. We have trained sales engineers that can help design a system that will fit your requirements and budget. Mua may dinh vi, class="st">CCTV Camera, IP Camera Lap Camera Da Nang, Security Systems, Analog Camera, Smart Home Store, Omnipolis, DVR, NVR, Video Management Software, camera ip wifi da nang, read more: lap dat camera da nang. HighMark Security has earned a reputation with the best technical support and customer service in the Da Nang security camera industry, lap camera …

  • Unknown
    Unknown December 28, 2018 at 11:54 PM

    Can I know which model of ip camera you use?

  • Jhon Walker
    Jhon Walker September 13, 2019 at 1:58 AM

    Thank you for share such great information about security alarm system. Home security is important thing for every home and business. I consider you to choose secure and reliable wireless burglar alarm to protect your home, property and family from thieves and criminals. Its really helpful for everyone.

Add Comment
comment url