繁体   English   中英

使用python和raspberry pi进行对象检测

[英]Object detection with python and raspberry pi

我正在通过带有picamera和openCV python3的树莓派开发颜色和对象检测算法。 我在一帧中检测到对象中的多种颜色,但是我需要知道该帧何时包含一种颜色 ,请通知我。

我关于此功能的代码如下:

    # only proceed if at least one contour was found
    if len(cnts) > 0:
        # find the largest contour in the mask, then use
        # it to compute the minimum enclosing circle and
        # centroid
        c = max(cnts, key=cv2.contourArea)
        ((x, y), radius) = cv2.minEnclosingCircle(c)
        M = cv2.moments(c)
        center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))

        # only proceed if the radius meets a minimum size. Correct this value for your obect's size
        if radius > 2:
            # draw the circle and centroid on the frame,
            # then update the list of tracked points
            cv2.circle(frame, (int(x), int(y)), int(radius), colors[key], 2)
            cv2.putText(frame,key + " Color Detected", (int(x-radius),int(y-radius)), cv2.FONT_HERSHEY_SIMPLEX, 0.6,colors[key],2)

        if key == "Yellow" and radius > 2:
            print("Hello from other side")
# show the frame to our screen
cv2.imshow("Frame", frame)

key = cv2.waitKey(1) & 0xFF
# if the 'q' key is pressed, stop the loop
if key == ord("q"):
    break

我的完整代码在这里: https : //paper.dropbox.com/doc/CODE--AR6uAVjSJFF2vv3YHC97_B3NAQ-EVg5oJec6eTwycFqDQ38r

我尝试做很多事情,但没有任何帮助。 如果有人可以帮助我将不胜感激

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM