- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用Python中的openCV检测红色三角形和黄色三角形以区分它们。我是初学者。
首先,我想检测,计数(黄色和红色)并用一个矩形标记相机可以看到的所有三角形。我也想找到他们的重心。
目前,我一次只检测到一个三角形而没有发现颜色。
我的质量中心计算不起作用,出现了以下错误:
centroid_x = int(M['m10']/M['m00'])
ZeroDivisionError: float division by zero
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
print cap.get(3)
print cap.get(4)
# changing display size
ret = cap.set(3,320)
ret = cap.set(4,240)
def getthresholdedimg(hsv):
yellow = cv2.inRange(hsv,np.array((10,100,100)),np.array((30,255,255)))
red = cv2.inRange(hsv,np.array((0,0,0)),np.array((190,255,255)))
both = cv2.add(yellow,red)
return both
def nothing(x):
pass
# Create a black image, a window
img = np.zeros((300,512,3), np.uint8)
cv2.namedWindow('image')
while(True):
thr1 = 50
thr2 = 110
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gaussian_blur = cv2.GaussianBlur(gray,(5,5),0)
# Our operations on the frame come here
canny = cv2.Canny(gray,thr1,thr2)
canny_blur = cv2.Canny(gaussian_blur,thr1,thr2)
# Our operations on the frame come here
contours,hier = cv2.findContours(canny,1,2)
for cnt in contours:
approx = cv2.approxPolyDP(cnt,0.02*cv2.arcLength(cnt,True),True)
if len(approx)==3:
cv2.drawContours(frame,[cnt],0,(0,255,0),2)
tri = approx
M = cv2.moments(cnt)
centroid_x = int(M['m10']/M['m00'])
centroid_y = int(M['m01']/M['m00'])
cv2.circle(img,(centroid_x,centroid_y),3,255,-1)
for vertex in tri:
cv2.circle(frame,(vertex[0][0],vertex[0][1]),3,(64,0,128),-1)
cv2.line(img,(vertex[0][0],vertex[0][1]),(centroid_x,centroid_y),(0,0,255),1)
# Display the resulting frame
cv2.imshow('normal flux',frame)
cv2.imshow('gray conversion',gray)
cv2.imshow('canny edges conversion',canny)
cv2.imshow('canny edges gaussian blur',canny_blur)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
最佳答案
也许你想做M = cv2.moments(tri)
而不是M = cv2.moments(cnt)
?
关于python - 在Python中使用openCV检测红色和黄色三角形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20732158/
北京时间今天下午,realme 5i手机正式登陆印度市场,5000mAh+骁龙665处理器,售价约合人民币870元。在发布会上,realme的印度CEO马达夫·希思(Madhav Sh
这个问题在这里已经有了答案: What does a space mean in a CSS selector? i.e. What is the difference between .clas
我配置了 Jenkins 构建(项目使用 Java、Maven、JUnit)。根据单元测试失败的 Maven 阶段,我想将构建标记为红色、黄色或绿色: 编译错误:红色 Maven 阶段“测试”失败:红
我想知道是否可以在“solidGauge”图表的右侧设置一个从左侧绿色(0 值)开始、中间渐变为黄色然后渐变为红色的渐变。 我在 yAxis 中尝试了一些配置,但它们没有按照我的要求进行:
我正在使用 cocos2d 库制作 iOS 游戏。 假设您有两个具有两种不同颜色的对象 - 在 RGB 中定义为 Blue: 0,0,255 Yellow: 255,255,0 我想添加蓝色和
有没有办法轻松地将给定的十六进制颜色代码分配给更一般的类别(红色、绿色、蓝色、黄色、橙色、粉色、黑色、白色、灰色……)? 比如 #ffcc55 -> 橙色,#f0f0f0 -> 白色,... 编辑:甚
我必须区分5种类型的图像,这些图像可能主要是红色,绿色,蓝色,橙色或黄色,而白色或黑色。我必须找到图像中突出的颜色。 图像来源是网络摄像头,因此实际颜色还取决于图像的照明度和距网络摄像头的距离。我的图
我一直在寻找如何在 qtableview 的特定单元格上设置颜色。目前,我正在使用 qt 示例卡住列来查看如何在特定单元格上设置颜色。 我在论坛上搜索有关如何告诉使用 qitemdelegate 或
我是一名优秀的程序员,十分优秀!