opencv零点矩阵在每次迭代时在三个位置上给出255

时间:2016-12-24 12:36:38

标签: c++ opencv image-processing

这是我关于堆栈概述的第一篇文章,所以对我很温柔:) 我是opencv的新手,试图制作一个游戏,我必须创建两个圆形的形状,每当我的手接触其中一个时,我会计算得分或者向上计数。 我已经从皮肤检测变为对象检测 我已经对HSV中3个通道的阈值进行了某种颜色的校准。 代码总是给我零球的位置,除非我已经定义它的对象是255通过该位置。 我的问题是 CODE 总是返回三个255值,它应该是ZERO。 并且每次循环必须是3次。 谢谢,这是我的代码

    #include < windows.h >
#include <highgui.h>
#include <cxcore.h>
#include <cv.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include<time.h>

using namespace std; 

using namespace cv;

int main() 

{
VideoCapture cap(0);

Mat frame,frames,frame1[3],newone,thresholded,thresholded1,thresholded2;

int scoreUpDown=0;

for(;;){

   Redo:int a=rand()%550;

        int b=abs(a-120);

        if(abs(a-b)<=25)goto Redo;

cap>>frame;

for(int i=0;i<= frame.rows-10;i=i+10)

{

cap>>frame;

flip(frame,frame,1);

cvtColor(frame,frames,CV_RGB2HSV);

split(frames,frame1);

threshold(frame1[0], thresholded, 42, 112, THRESH_BINARY);

threshold(thresholded, thresholded, 0, 255, THRESH_BINARY);

bitwise_not(thresholded,thresholded);

threshold(frame1[1], thresholded1, 87, 163, THRESH_BINARY);

threshold(thresholded1, thresholded1, 0, 255, THRESH_BINARY);

threshold(frame1[2], thresholded2, 145, 260, THRESH_BINARY);

threshold(thresholded2, thresholded2, 0, 255, THRESH_BINARY);

bitwise_and(thresholded,thresholded1,newone);

bitwise_and(newone,thresholded2,newone);

// GaussianBlur( newone, newone, Size( 7, 7 ), 0, 0 );

circle( newone, Point(a , i), 22, Scalar( 255, 0, 0 ), -5, 15,2 );

circle( newone, Point(b , i), 22, Scalar( 255, 0 , 0 ), -5, 15,2 );

circle( frames, Point(a , i), 22, Scalar( 0, 0, 255 ), -5, 15,2 );

circle( frames, Point(b , i), 22, Scalar( 0, 255 , 0 ), -5, 15,2 );

line( frames, Point( 0, 410 ), Point(640,410), Scalar( 255, 255, 255 ),  5, 10 );

putText(frames,"STARAT",Point(5,450),2,1,CV_RGB(255, 255, 0),4,8,false);    

putText(frames,"END",Point(550,450),2,1,CV_RGB(255, 255, 0),4,8,false); 

putText(frames,"SCORE",Point(250,450),2,1,CV_RGB(255, 255, 0),4,8,false);

stringstream ss;

                ss<<scoreUpDown;

                string txt=ss.str();

                Point textPos(100,50);

                putText(frames,txt,Point(400,450),2,1,CV_RGB(255, 0, 
0),4,8,false);

int u=newone.at<uchar>(a,i);

int m=newone.at<uchar>(b,i);

int s=frames.at<uchar>(a,i);

int z=newone.at<uchar>(b,i);

if(u==255)

    scoreUpDown=scoreUpDown+10;

if(m==255)

    scoreUpDown=scoreUpDown-10;

cout<<"u= "<<u;

cout<<"   m= "<<m;

cout<<"   s= "<<s<<endl;

cvtColor(newone,newone,CV_HSV2RGB);

imshow("HSV",frames);

imshow("new",newone);

if(waitKey(60)==99)break;  

}
}

return 0; 

}

0 个答案:

没有答案