VS+MFC+OPENCV摄像头跟踪蓝色物体并输出坐标并发送

VS+MFC+OPENCV摄像头跟踪蓝色物体并输出坐标并发送_第1张图片

            cvtColor(frame, imgHSV, COLOR_BGR2HSV);
            split(imgHSV, hsvSplit);
            equalizeHist(hsvSplit[2], hsvSplit[2]);
            merge(hsvSplit, imgHSV);
            Mat imgThresholded;
            inRange(imgHSV, Scalar(iLowH, iLowS, iLowV), Scalar(iHighH, iHighS, iHighV), imgThresholded);
            Mat element = getStructuringElement(MORPH_RECT, Size(5, 5));
            morphologyEx(imgThresholded, imgThresholded, MORPH_OPEN, element);
            morphologyEx(imgThresholded, imgThresholded, MORPH_CLOSE, element);
            Canny(imgThresholded, canny_output, thresh, thresh * 3, 3);
            findContours(canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
            vector mu(contours.size());
            for (int i = 0; i < contours.size(); i++)
            {
                mu[i] = moments(contours[i], false);
            }
            vector mc(contours.size());
            for (int i = 0; i < contours.size(); i++)
            {
                Scalar color = Scalar(255, 0, 0);
                drawContours(frame, contours, i, color, 2, 8, hierarchy, 0, Point());
                mc[i] = Point2d(mu[i].m10 / mu[i].m00, mu[i].m01 / mu[i].m00);
                circle(frame, mc[i], 5, Scalar(0, 0, 255), -1, 8, 0);
                fuck4 = mc[i].x;
                fuck5 = mc[i].y;
            }
            fine4 = fuck4;
            fine5 = fuck5;

            imshow("view", frame);
            UpdateData(FALSE);
            X_time_new = fuck4;//输出到static text中
            Y_timm_new = fuck5;//输出到static text中
        }

你可能感兴趣的:(VS+MFC+OPENCV摄像头跟踪蓝色物体并输出坐标并发送)