问题
Right now I am working on a project that requires me to detect when a perforated line is in the middle of the video image and then output a serial command to control a cutter arm. Right now I can detect lines that are vertical (which is what I want), However I can not detect just when they are in the center of the screen. Also I imagine that using the output from the following line I could tell that there are lines being detected?:
lines = cv2.HoughLinesP(edges, 1, math.pi/1, 1, None, 23, 1)
My main question is as follows using OpenCV/python how do I detect vertical lines that are just in the center of the video output in order to count how many perforated sets have passed the camera and on X stop and cut when lined up?????
Picture of what I would like to possibly see https://www.dropbox.com/s/13v9g92uw40riiq/good.png
Full Working code bellow:
import cv2
import os
import math
import numpy
import scipy
vc =cv2.VideoCapture(0)
if vc.isOpened():
rval, frame = vc.read()
else:
rval = False
while rval:
rval, frame = vc.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 80, 120, apertureSize=3)
lines = cv2.HoughLinesP(edges, 1, math.pi/1, 1, None, 23, 1) #20-25 works well
if lines != None:
for line in lines[0]:
pt1 = (line[0],line[1])
pt2 = (line[2],line[3])
cv2.line(frame, pt1, pt2, (0,0,255), 2)
cv2.imshow("edge", frame)
ch = cv2.waitKey(50)
if ch != -1:
print "keypressed"
print ch
break
cv2.destroyAllWindows()
来源:https://stackoverflow.com/questions/18993846/detect-line-in-center-of-video-opencv