gpt4 book ai didi

python - CV2 : Is there a function that outputs the number of white dots in a polygon?

转载 作者:太空宇宙 更新时间:2023-11-03 23:04:53 25 4
gpt4 key购买 nike

我用 VideoStream 做了一个“背景减法”。然后我想检查指定多边形的内部,是否有白点。

我考虑过使用 https://docs.opencv.org/2.4/doc/tutorials/imgproc/shapedescriptors/point_polygon_test/point_polygon_test.html但我不知道该怎么做,因为应用滤镜后白点就存在了。原始流还包含我也不想计算的白点。

import numpy as np
import cv2
import time
cap = cv2.VideoCapture()
cap.open("rtsp://LOGINNAME:PASSWORD@192.168.178.42:554")
#cap.open("C:\\Users\\001\\Desktop\\cam-20191025-220508-220530.mp4")

fgbg = cv2.bgsegm.createBackgroundSubtractorMOG()

while(1):
ret, frame = cap.read()
fgmask = fgbg.apply(frame)
polygonInnenAutoErkennen_cnt = np.array( [(24, 719), (714,414), (1005,429),(1084,719)] )
cv2.drawContours(fgmask,[polygonInnenAutoErkennen_cnt],-1,(255,128,60))
#How can I check here?
cv2.imshow('frame',fgmask)
k = cv2.waitKey(30) & 0xff
if k == 27: # exit on ESC
break

cap.release()
cv2.destroyAllWindows()

最佳答案

最简单的方法是使用蒙版图像。在二进制图像上绘制多边形,并将其用作白点的掩码。您可以只进行每像素乘法或逻辑与。

关于python - CV2 : Is there a function that outputs the number of white dots in a polygon?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58577815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com