在视频的有限帧高度中进行霍夫变换

时间:2017-01-01 15:59:00

标签: c++ visual-studio opencv detection hough-transform

这是我的代码:

int main() {
    VideoCapture cap;
    cap.open("D:/01.avi");
    if (!cap.isOpened()) {
        cout << "Video cannot be opened" << endl;
        system("pause");
        return -1;
    }
    VideoWriter cap_output("D:/01_ouput.avi", 
        cap.get(CV_CAP_PROP_FOURCC), 
        cap.get(CV_CAP_PROP_FPS), 
        Size(cap.get(CV_CAP_PROP_FRAME_WIDTH), 
            cap.get(CV_CAP_PROP_FRAME_HEIGHT)));
    if (!cap_output.isOpened()) {
        cout << "Output video cannot be opened" << endl;
        return -1;
    }
    Mat frame, canny_frame, frame_ouput;
    while (true) {
        if (!cap.read(frame))
            break;

        Canny(frame, canny_frame, 50, 200, 3);
        cvtColor(canny_frame, frame_ouput, CV_GRAY2BGR);
        vector<Vec4i> lines;
        HoughLinesP(canny_frame, lines, 1, CV_PI / 180, 100, 100, 10);
        for (size_t i = 0; i < lines.size(); i++) {
            Vec4i l = lines[i];
            line(frame, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0, 0, 255), 3, 8);
        }
        imshow("ahoho", frame);
        //cap_output.write(frame_ouput);
        if (waitKey(30) >= 0) {
            break;
        }
    }


    cap.release();
    cap_output.release();

    return 0;
}

我想检测视频帧仅1/2高度的线条(以避免不同的对象)。我该怎么办?

0 个答案:

没有答案