im = cv2.imread('luffy.jpg')
gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray,127,255,0)
contours,h = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
// return color inside of the contour here
mask = np.zeros(cnt.shape[:2],np.uint8)
mean = cv2.mean(cant,mask) // I think this is promising but so far it returns arrays with just zeros. I think its because I used np.zeros above to find the mask....
moment = cv2.moments(cnt) //maybe this will help?
我能找到没有这样的OpenCV的功能内置的。我想也许你可以用瞬间办呢?我怎样才能做到这一点?
编辑:由ZAW林给我的这个输入图像所提出的解决方案:
这个输出图像:
一种方法是:您可以获取轮廓内的图像区域,然后将其用于进一步处理。裁剪内部区域看到这个:http://stackoverflow.com/questions/28759253/how-to-crop-the-internal-area-of-a-contour – Vipul
我认为最好的方法是处理内部的直方图图片。 [本](http://www.pyimagesearch.com/2014/01/22/clever-girl-a-guide-to-utilizing-color-histograms-for-computer-vision-and-image-search-engines/ )可能会有帮助。 – Mahm00d
第一个链接似乎给了一个空白的白色裁剪,所以我不能用它来找到颜色。直方图可能工作,但它似乎适合做一个实际的直方图。例如,我无法找到平均每个通道值的方法。我发现你可以在轮廓上运行cv2.mean(cnt,mask)来获得BGR通道的平均值,这看起来很有前途。到目前为止,虽然 – BigBoy1337