How to calculate number of people counting inside/outside in shop?

asked 2017-04-14 07:08:53 -0600

updated 2017-04-15 16:19:40 -0600

Hello. How to calculate how many people are in the shop a lot ? Came out 7 people left 5 people in the shop left 2 people.

Could you tell me how it can be implemented?

#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>

#include<iostream>
#include<conio.h>           // it may be necessary to change or remove this line if not using Windows
#include <fstream>      // file utils
#include <ctime>        // timestamp stuff
#include "Blob.h"

#define SHOW_STEPS            // un-comment or comment this line to show steps or not
#define FRAME_SCALE     1   // divide frame dimentions by this number

// global variables ///////////////////////////////////////////////////////////////////////////////
const cv::Scalar SCALAR_BLACK = cv::Scalar(0.0, 0.0, 0.0);
const cv::Scalar SCALAR_WHITE = cv::Scalar(255.0, 255.0, 255.0);
const cv::Scalar SCALAR_YELLOW = cv::Scalar(0.0, 255.0, 255.0);
const cv::Scalar SCALAR_GREEN = cv::Scalar(0.0, 200.0, 0.0);
const cv::Scalar SCALAR_RED = cv::Scalar(0.0, 0.0, 255.0);
const cv::Scalar SCALAR_BLUE = cv::Scalar(255.0, 0.0, 0.0);

// function prototypes ////////////////////////////////////////////////////////////////////////////
void matchCurrentFrameBlobsToExistingBlobs(std::vector<Blob> &existingBlobs, std::vector<Blob> &currentFrameBlobs);
void addBlobToExistingBlobs(Blob &currentFrameBlob, std::vector<Blob> &existingBlobs, int &intIndex);
void addNewBlob(Blob &currentFrameBlob, std::vector<Blob> &existingBlobs);
double distanceBetweenPoints(cv::Point point1, cv::Point point2);
void drawAndShowContours(cv::Size imageSize, std::vector<std::vector<cv::Point> > contours, std::string strImageName);
void drawAndShowContours(cv::Size imageSize, std::vector<Blob> blobs, std::string strImageName);
bool checkIfBlobsCrossedTheLine(std::vector<Blob> &blobs, int &intVerticalLinePosition, int &ShopCountL, int &ShopCountR, std::ofstream &myfile);
void drawBlobInfoOnImage(std::vector<Blob> &blobs, cv::Mat &imgFrame2Copy);
void drawShopCountOnImage(int &ShopCountL, int &ShopCountR, cv::Mat &imgFrame2Copy);

///////////////////////////////////////////////////////////////////////////////////////////////////
int main(void) {

    cv::VideoCapture capVideo;
    std::ofstream myfile; // log file

    cv::Mat imgFrame1;
    cv::Mat imgFrame2;
    cv::Mat imgFrame1L;
    cv::Mat imgFrame2L;

    std::vector<Blob> blobs;

    cv::Point crossingLine[2];

    int ShopCountL = 0;
    int ShopCountR = 0;

    capVideo.open("input1_2.MOV");
    //capVideo.open("rtsp://192.168.1.254/sjcam.mov");
    //capVideo.open(1);

    // log file
    myfile.open("/tmp/OpenCV-" + std::string() + "-" + std::to_string(time(0)) + ".txt");
    std::cout << "Logging to: \"/tmp/OpenCV-" << "-" << std::to_string(time(0)) << ".txt\"" << std::endl;

    myfile << "\"Timestamp\",\"Left\",\"Right\"" << std::endl;

    if (!capVideo.isOpened()) {                                                 // if unable to open video file
        std::cout << "error reading video file" << std::endl << std::endl;      // show error message
        _getch();                   // it may be necessary to change or remove this line if not using Windows
        return(0);                                                              // and exit program
    }

    if (capVideo.get(CV_CAP_PROP_FRAME_COUNT) < 2) {
        std::cout << "error: video file must have at least two frames";
        _getch();                   // it may be necessary to change or remove this line if not using Windows
        return(0);
    }

    capVideo.read(imgFrame1L);
    capVideo.read(imgFrame2L);

    resize(imgFrame1L, imgFrame1, cv::Size(imgFrame1L.size().width / FRAME_SCALE, imgFrame1L.size().height / FRAME_SCALE));
    resize(imgFrame2L, imgFrame2, cv::Size(imgFrame2L.size().width / FRAME_SCALE, imgFrame2L.size().height / FRAME_SCALE));


    //int intHorizontalLinePosition = (int)std::round((double)imgFrame1.rows * 0.35);
    int intVerticalLinePosition = (int)std::round((double)imgFrame1.cols * 0.50);

    crossingLine[0].y = 0;
    crossingLine[0].x = intVerticalLinePosition;

    crossingLine[1].y = imgFrame1.rows - 1;
    crossingLine ...
(more)
edit retag flag offensive close merge delete

Comments

Just to give you a heads up, your code seems completely unrelated to the whole car, inside outside thing, so unless you make it more clear, noone is going to have a clue on how to help you...

StevenPuttemans gravatar imageStevenPuttemans ( 2017-04-14 07:56:52 -0600 )edit

I fixed the code. At the moment I think the number of people entering the store and going out, but I would like to know how many people are left in the store at the moment.

AndreyPavlov gravatar imageAndreyPavlov ( 2017-04-15 08:49:30 -0600 )edit

Again it is still not clear how you know numbers of people inside and outside. This code is incomplete.

StevenPuttemans gravatar imageStevenPuttemans ( 2017-04-15 15:34:16 -0600 )edit

I fixed the code.

AndreyPavlov gravatar imageAndreyPavlov ( 2017-04-15 15:58:45 -0600 )edit

I would like to do something similar to this on youtube - People Counter 2 user danduck101https://www.youtube.com/watch?v=W-gDfr_G7GA&t=1s (link text)

AndreyPavlov gravatar imageAndreyPavlov ( 2017-04-17 00:51:51 -0600 )edit