【发布时间】:2016-05-13 13:52:12
【问题描述】:
我需要指导才能实现代码。目的是计算自习室里的学生人数。我的想法是:
1) 拍照空教室学习 2)在一天中的某个时间与坐在预定位置的学生合影,因为椅子不能移动。 3) 定义图片中与座位教室学习相对应的关键点。 4)两张照片的差异。 5)如果这些职位现在被占用(差异已经给出了可见的结果),那么计算与学生数量相对应的差异数量。
有人知道如何在代码中实现它吗?
Mat differenceFrame(Mat prev_frame, Mat curr_frame);
int main(void) {
cv::Mat frame, frame1, framedifference;
int key = 0;
frame = imread("2.jpg", CV_LOAD_IMAGE_COLOR); // Read the file
frame1 = imread("1.jpg", CV_LOAD_IMAGE_COLOR); // Read the file
while (key != 27){
differenceFrame(frame, frame1);
cv::absdiff(frame, frame1, framedifference);
key = 0;
cv::imshow("stream", framedifference);
key = cv::waitKey(10);
}
ContPeople(framedifference) ?????
}
现在: 我试过这个解决方案。我不知道这是否是最有效的。 blob可以帮助我吗? 当我对图像进行差异化时,我将一些反射点标记为好像它们被改变了一样,我认为这是光线过多的问题,您可以细化差异以避免这些问题吗?
cv::Mat imgFrame1Copy = F_RoomFull.clone(); cv::Mat imgFrame2Copy = F_RoomEmpty.clone();
cv::Mat imgDifference;
cv::Mat imgThresh;
cv::cvtColor(imgFrame1Copy, imgFrame1Copy, CV_BGR2GRAY);
cv::cvtColor(imgFrame2Copy, imgFrame2Copy, CV_BGR2GRAY);
cv::GaussianBlur(imgFrame1Copy, imgFrame1Copy, cv::Size(5, 5), 0);
cv::GaussianBlur(imgFrame2Copy, imgFrame2Copy, cv::Size(5, 5), 0);
cv::absdiff(imgFrame1Copy, imgFrame2Copy, imgDifference);
cv::threshold(imgDifference, imgThresh, 180, 255, CV_THRESH_BINARY);
cv::imshow("imgThresh", imgThresh);
cv::Mat structuringElement3x3 = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
cv::Mat structuringElement5x5 = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(5, 5));
cv::Mat structuringElement7x7 = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(7, 7));
cv::Mat structuringElement9x9 = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(9, 9));
cv::dilate(imgThresh, imgThresh, structuringElement5x5);
cv::dilate(imgThresh, imgThresh, structuringElement5x5);
cv::erode(imgThresh, imgThresh, structuringElement5x5);
cv::Mat imgThreshCopy = imgThresh.clone();
cv::findContours(imgThreshCopy, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
cv::Mat imgContours(imgThresh.size(), CV_8UC3, SCALAR_BLACK);
cv::drawContours(imgContours, contours, -1, SCALAR_WHITE, -1);
cv::imshow("imgContours", imgContours);
printf("%d", contours.size());
【问题讨论】: