【发布时间】:2014-12-14 14:50:18
【问题描述】:
我是 OpenCV 的新手,正在做一个视频分析项目。基本上,我想将我的网络摄像头分成两侧(左侧和右侧),并且已经想出了如何做到这一点。但是,我还想分析每一面的红色和绿色,并打印出红色/绿色的像素数量。我必须通过所有可能的博客来解决这个问题,但可惜它仍然不起作用。以下代码运行,但不是检测红色,因为代码可能暗示它似乎拾取白色(所有光源和白色墙壁)。我花了几个小时梳理代码,但仍然找不到解决方案。请帮忙!另请注意,这是通过 Xcode 在 OSX 10.8 上运行的。谢谢!
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
VideoCapture cap(0); //capture the video from webcam
if ( !cap.isOpened() ) // if not success, exit program
{
cout << "Cannot open the web cam" << endl;
return -1;
}
namedWindow("HSVLeftRed", CV_WINDOW_AUTOSIZE);
namedWindow("HSVLeftGreen", CV_WINDOW_AUTOSIZE);
while (true) {
Mat image;
cap.read(image);
Mat HSV;
Mat threshold;
//Left Cropping
Mat leftimg = image(Rect(0, 0, 640, 720));
//Left Red Detection
cvtColor(leftimg,HSV,CV_BGR2HSV);
inRange(HSV,Scalar(0,0,150),Scalar(0,0,255),threshold);
imshow("HSVLeftRed",threshold);
//Left Green Detection
cvtColor(leftimg,HSV,CV_BGR2HSV);
inRange(HSV,Scalar(still need to find proper min values),Scalar(still need to find proper max values),threshold);
imshow("HSVLeftGreen",threshold);
}
return 0;
}
【问题讨论】:
标签: c++ xcode macos opencv video-processing