Share
Visit

Monday, November 28, 2016

IP camera video stream opencv and people detection

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;
}

13 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
  4. Thank you for sharing like this information. If you want more information regarding CCTV Camera visit shipgig website.

    ReplyDelete
  5. 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

    ReplyDelete
  6. . 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

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

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

    ReplyDelete
  9. 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 da nang, sua chua camera da nang dich vu camera da nang

    ReplyDelete
  10. Can I know which model of ip camera you use?

    ReplyDelete

ad