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> ¤tFrameBlobs);
void addBlobToExistingBlobs(Blob ¤tFrameBlob, std::vector<Blob> &existingBlobs, int &intIndex);
void addNewBlob(Blob ¤tFrameBlob, 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)