小编Kau*_*ran的帖子

使用Opencv检测图像中矩形的中心和角度

我的图像如下:

包含许多矩形轮廓的示例图像

我需要找出矩形的数量,每个矩形的中心和测量平行于通过中心的矩形的长边的轴之间的角度,并测量从水平方向逆时针方向的角度.我发现了数量图像中的矩形.我很惊讶地发现了中心和反射角度.通过瞬间找到中心并没有给我正确的答案.

我的代码:

import cv2
import numpy as np 
import sys

img = cv2.imread(str(sys.argv[1]),0)
ret,thresh = cv2.threshold(img,127,255,0)
contours,hierarchy = cv2.findContours(thresh,1,2)



for contour in contours:
    area = cv2.contourArea(contour)
    if area>100000:
        contours.remove(contour)




cnt = contours[0]

epsilon = 0.02*cv2.arcLength(cnt,True)
approx = cv2.approxPolyDP(cnt,epsilon,True)

print 'No of rectangles',len(approx)


#finding the centre of the contour
M = cv2.moments(cnt)

cx = int(M['m10']/M['m00'])
cy = int(M['m01']/M['m00'])

print cx,cy
Run Code Online (Sandbox Code Playgroud)

python opencv image-processing computer-vision

11
推荐指数
1
解决办法
1万
查看次数

如何使用opencv-python创建缩略图?

我正在尝试anti-aliasing使用Python-Pillow's im.thumbnail()方法对我的图像进行下采样(使用).

我的代码看起来像:

MAXSIZE = 1024
im.thumbnail(MAXSIZE, Image.ANTIALIAS)
Run Code Online (Sandbox Code Playgroud)

你能告诉我一些替代方法opencv-python来执行这个重新调整大小的操作吗?

python opencv image-processing python-imaging-library

5
推荐指数
1
解决办法
3325
查看次数

在opencv-python中检测星形

我需要检测形状并计算图像中每个形状的出现.我最初检测到轮廓并对它们进行近似,并计算每个轮廓中的顶点.我的代码如下所示:

import cv2
import numpy as np 
import collections
import sys

img = cv2.imread(str(sys.argv[1]),0)
ret,thresh = cv2.threshold(img,127,255,0)
contours,hierarchy = cv2.findContours(thresh,1,2)


no_of_vertices = []

i = 0
mask = np.zeros(img.shape,np.uint8)
for contour in contours:

 cnt = contour
 area = cv2.contourArea(cnt)
 if area>150:
    epsilon = 0.02*cv2.arcLength(cnt,True)
    approx = cv2.approxPolyDP(cnt,epsilon,True)
    no_of_vertices.append(len(approx))



counter = collections.Counter(no_of_vertices)




 a,b = counter.keys(),counter.values()

 i=0
 while i<len(counter):
   print a[i],b[i]
   i = i + 1
Run Code Online (Sandbox Code Playgroud)

我的代码不能用于检测此图像中的星星:

图像与星星和其他基本形状

我应该在代码中做出哪些更改?

python opencv image-processing computer-vision

5
推荐指数
1
解决办法
2253
查看次数