나는이 윈도우 화면을 짓고 있어요 : 내가 플레이 사각형 내부의 제스처 터치를 결정하는 노란색 마커를 사용하려면 내가 녹색 마커 내부의 제스처 터치를 결정 사각형을 종료 할OpenCV에서 두 가지 색상을 추적하는 방법은 무엇입니까?
. 그러나, 나는이 코드를 썼다 :
//Capture a temporary image from the camera
Mat imgTmp;
cap.read(imgTmp);
//Create a black image with the size as the camera output
Mat imgLines = Mat::zeros(imgTmp.size(), CV_8UC3);;
while (true)
{
Mat frame;
bool bSuccess = cap.read(frame); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
//tracking colors
Mat imgHSV;
cvtColor(frame, imgHSV, COLOR_BGR2HSV); //Convert the captured frame from BGR to HSV
Mat imgThresholded;
inRange(imgHSV, Scalar(ylowH, ylowS, ylowV), Scalar(yhighH, yhighS, yhighV), imgThresholded); //Threshold the image
inRange(imgHSV, Scalar(glowH, glowS, glowV), Scalar(ghighH, ghighS, ghighV), imgThresholded);
//morphological opening (removes small objects from the foreground)
erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)));
dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)));
//morphological closing (removes small holes from the foreground)
dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)));
erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)));
//Calculate the moments of the thresholded image
Moments oMoments = moments(imgThresholded);
double dM01 = oMoments.m01;
double dM10 = oMoments.m10;
double dArea = oMoments.m00;
// if the area <= 10000, I consider that the there are no object in the image and it's because of the noise, the area is not zero
if (dArea > 10000)
{
//calculate the position of the ball
int posX = dM10/dArea;
int posY = dM01/dArea;
을하지만, 녹색과 노란색 컬러 모두보기의 카메라 필드 안에있는 동안 만 녹색을 추적한다. 어떻게 여러 색상을 추적하고 화면에서 특정 좌표 (마우스 기능과 같은)에서 상호 작용을 발견?
감사합니다. 도움이되었습니다. – robstat7