Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检测每个“点”的中心;块;在Python中的图像(矩阵)中?_Python_Image Processing_Edge Detection - Fatal编程技术网

如何检测每个“点”的中心;块;在Python中的图像(矩阵)中?

如何检测每个“点”的中心;块;在Python中的图像(矩阵)中?,python,image-processing,edge-detection,Python,Image Processing,Edge Detection,请看下图,共有9个“块”,我希望检测它们的中心 您可以使用openCV: 1)查找对象: import numpy as np import cv2 im = cv2.imread('test.jpg') imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) ret, thresh = cv2.threshold(imgray, 127, 255, 0) im2, contours, hierarchy = cv2.findContours(thresh,

请看下图,共有9个“块”,我希望检测它们的中心

您可以使用openCV:

1)查找对象:

import numpy as np
import cv2
im = cv2.imread('test.jpg')
imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 127, 255, 0)
im2, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

2)查找对象的中心:

import cv2
import numpy as np
img = cv2.imread('star.jpg',0)
ret,thresh = cv2.threshold(img,127,255,0)
im2,contours,hierarchy = cv2.findContours(thresh, 1, 2)
cnt = contours[0]
M = cv2.moments(cnt)

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

检测边缘,然后执行代数?你试过什么?你是指最大值的像素还是明亮事件的“重心”?嗨,约翰,这张图像是CNN提取的特征,我想检测中心,以便对原始图像进行自动注释。嗨,大卫,是的,这是真的。你似乎忘记了第二部分中的这一行:imgray=cv2.cvt颜色(im,cv2.COLOR\u bgr2灰色)