这篇文章主要介绍了opencv摄像头捕获识别颜色,用opencv通过摄像头捕获识别颜色,红色蓝色等,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了opencv摄像头捕获识别颜色的具体代码,供大家参考,具体内容如下
#include "highgui.h" #include "iostream" using namespace std; int main() { CvCapture* pCap = cvCreateCameraCapture(1 );//这里-1也可以,不过我的电脑装的有CyberLink YouCam软件, int flag=0; //OpenCV会默认调用该摄像头,而不调用系统的驱动 IplImage* frame =NULL; if (<strong style="color:transparent">来源gaodai#ma#com搞@@代~&码*网</strong>cvCreateCameraCapture == NULL) { return(0); } cvNamedWindow("Camera",CV_WINDOW_FULLSCREEN); while ((frame = cvQueryFrame(pCap)) != 0 && cvWaitKey(20) != 27) { frame = cvQueryFrame(pCap); //cout<width<<" "<height<<endl; flag=0; for(int x=0;xheight;x++) { for(int y=0;ywidth*3;y++) { //CV_IMAGE_ELEM(frame,uchar,x,y)=255; if( ((uchar*)(frame->imageData+x*frame->widthStep))[y*frame->nChannels+0]imageData + x*frame->widthStep))[y*frame->nChannels + 1]imageData + x*frame->widthStep))[y*frame->nChannels + 2]>150) //r flag++; } } cout<<flag<70000) cout<<"red"; else cvShowImage("Camera",frame); } aaa: cvReleaseCapture(&pCap); cvDestroyWindow("Camera"); system("pause"); return (0); }
以上就是opencv摄像头捕获识别颜色的详细内容,更多请关注gaodaima搞代码网其它相关文章!