python - Finding Light Spots with OpenCV -
i circle light spots opencv. idea find webcam light spots, if have 3 leds in scene likt circle them. not sure how circle/filter them. here code far:
import cv2 import numpy np import imutils cap = cv2.videocapture(0) while true: _, frame = cap.read() gray = cv2.cvtcolor(frame, cv2.color_bgr2gray) blur = cv2.gaussianblur(gray, (11,11), 0) (minval, maxval, minloc, maxloc) = cv2.minmaxloc(blur) hi, threshold = cv2.threshold(blur, maxval-20, 230, cv2.thresh_binary) thr = threshold.copy() cv2.resize(thr, (300,300)) edged = cv2.canny(threshold, 50, 150) _, lightcontours, hierarchy = cv2.findcontours(edged, cv2.retr_tree, cv2.chain_approx_simple) (i, c) in enumerate(lightcontours): points = [] (x, y, w, h) = cv2.boundingrect(c) ((cx, cy), radius) = cv2.minenclosingcircle(c) cv2.circle(frame, (int(cx), int(cy)), int(radius), (0, 0, 255), 3) points.append([[int(cx), int(cy)]]) print points cv2.puttext(frame, "#{}".format(i + 1), (x, y - 15), cv2.font_hershey_simplex, 0.45, (0, 0, 255), 2) cv2.imshow('light', thr) cv2.imshow('frame', frame) cv2.imshow('edges', edged) cv2.waitkey(4) key = cv2.waitkey(5) & 0xff if key == ord('q'): break cap.release() cv2.destroyallwindows() so can circle them? found sources circle light spots in picture did not managed adapt them streaming. ideas?
best regards
update: updated code show actual state.
Comments
Post a Comment