Python 我想在不同的光照条件下探测激光光斑(圆)
此代码可以工作,但当网络摄像头面对有灯光的区域时,它也会将其识别为激光指针。我需要帮助的是消除噪音,只识别激光指针。这张图片显示了它在面具中的样子,但还没有光线条件。以下是我目前的代码:Python 我想在不同的光照条件下探测激光光斑(圆),python,opencv,hough-transform,Python,Opencv,Hough Transform,此代码可以工作,但当网络摄像头面对有灯光的区域时,它也会将其识别为激光指针。我需要帮助的是消除噪音,只识别激光指针。这张图片显示了它在面具中的样子,但还没有光线条件。以下是我目前的代码: cap = cv2.VideoCapture(0) while True: ret, main = cap.read() hsv = cv2.cvtColor(main, cv2.COLOR_BGR2HSV) gray = cv2.cvtColor(m
cap = cv2.VideoCapture(0)
while True:
ret, main = cap.read()
hsv = cv2.cvtColor(main, cv2.COLOR_BGR2HSV)
gray = cv2.cvtColor(main, cv2.COLOR_BGR2GRAY)
lower_laserdot = np.array([0, 0, 255])
upper_laserdot = np.array([255, 255, 255])
threshold = cv2.inRange(hsv, lower_laserdot, upper_laserdot)
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 700, param1
= 50, param2 = 30, minRadius = 0, maxRadius = 0)
threshcopy = threshold.copy()
_, find, _ = cv2.findContours(threshcopy, cv2.RETR_LIST,
cv2.CHAIN_APPROX_SIMPLE)
maxarea = 1
bestcnt = 1
for cnt in find:
area = cv2.contourArea(cnt)
if area > maxarea:
maxarea = area
bestcnt = cnt
M = cv2.moments(bestcnt)
x, y = int(M['m10']/M['m00']), int(M['m01']/M['m00'])
if circles is not None:
circles = np.round(circles[0, :]).astype("int")
for(cx,cy,r) in circles:
if x > 0 or y > 0:
print('A laser dot has been detected')
cv2.imshow('mask', threshold)
rs = cv2.resize(main, (1365, 730))
cv2.imshow('main', rs)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
假设它是红点,只过滤红色色调(例如色调230)。您还可以增加图像的对比度,因为激光很可能是图片中强度最高的颜色。我该怎么做呢?转换图像BGR2HSV。创建相似大小的遮罩。如果hsv numpy数组中的H值为230,则根据您创建的遮罩的颜色深度,将遮罩numpy数组中的相应位设置为1或255。否。我的意思是如何增加图像的对比度?