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