检测彩色线条并在两条彩色线条之间绘制图像python opencv

时间:2018-04-27 13:29:27

标签: machine-learning artificial-intelligence python-3.5 opencv3.2

enter image description here我已经使用opencv和numpy编写了一个python代码来检测视频中的红色线条,它工作正常,因为它能够检测到红线的边缘。但我想抓住它视频的一部分在每两行之间作为图像。如何做?现在我已经更新了一个图像。我想从视频中的两条红线之间提取图像。

import cv2
import numpy as np
import matplotlib.pyplot as plt

video = cv2.VideoCapture("/home/ksourav/AGS/SampleVideos/Trail1.mp4")

while True:
    ret, frame = video.read()

if not ret:

    video = cv2.VideoCapture("/home/ksourav/AGS/SampleVideos/Trail1.mp4")
    continue

#gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

low_red = np.array ([5, 50, 50])

up_red = np.array([10, 255, 255])

mask = cv2.inRange(hsv, low_red, up_red)

edges= cv2.Canny(mask, 100, 200, apertureSize=7, L2gradient=True)

lines = cv2.HoughLinesP(edges, 9, np.pi/180, 250, maxLineGap=70)

if lines is not None:

    for line in lines:

        x1, y1, x2, y2 = line[0]

        cv2.line(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)


cv2.imshow("frame", frame)

key = cv2.waitKey(25)

if key == 27:

    break

video.release()
cv2.destroyAllWindows()

0 个答案:

没有答案