def _find_power_plug_thing(self):
""" Find the power plug at the solar array box """
""" This uses color to determine if we have a choke """
lower = np.array([100, 40, 0], dtype = "uint8")
upper = np.array([255, 255, 20], dtype = "uint8")
mask = cv2.inRange(self.img, lower, upper)
blurred = cv2.GaussianBlur(mask, (5, 5), 0)
thresh = cv2.threshold(blurred, 60, 255, cv2.THRESH_BINARY)[1]
contours = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = contours[0] if is_cv2() else contours[1]
sorted_contours = sorted(contours, cmp=lambda a,b: int(cv2.contourArea(b)) - int(cv2.contourArea(a)))
if len(sorted_contours) > 0:
plug = self._find_a_thing(sorted_contours[0], 0, 0.06, 0, 0.06, 99.0)
if plug is not None:
plug.set_power_plug()
self.things.append(plug)
self.power_plug = plug
if self.debug:
debug_img = self.img.copy()
for c in sorted_contours:
cv2.drawContours(debug_img, [c], -1, (0, 255, 0), 2)
cv2.imshow("plug picture", debug_img)
cv2.setMouseCallback("plug picture", self.handle_mouse)
cv2.waitKey(0)
cv2.destroyAllWindows()
评论列表
文章目录