イメージ内の黒い線の中に含まれる領域を見つけようとしています。黒い線で塗りつぶされた領域
はここでサンプル画像を始める "photo.jpg" である:私はこのためにOpenCVのとSimpleCVを使用している
Sample starting image "photo.jpg"
。ここ
コードである:ここ
from SimpleCV import Camera, Display, Image, Color
import time
import cv2
import numpy as np
n_image = Image('photo.jpg')
n_image2 = n_image.crop(55, 72, 546, 276) #Crop X,Y,W,H
n_image2.save('photo_2.jpg')
imagea = Image("photo_2.jpg")
greya = imagea.stretch(50).invert() #50=Blackness level of Black
greya.show()
greya.save('photo_2-GREY.jpg')
im = cv2.imread('photo_2-GREY.jpg')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,220,255,0)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
largest_areas = sorted(contours, key=cv2.contourArea)
cv2.drawContours(im, [largest_areas[-2]], 0, (255,255,255,255), -1)
cv2.drawContours(im,contours,-1,(255,255,255),-1)
cv2.imshow('Image Window',im)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite('photo_3.jpg',im)
n_image = Image('photo_3.jpg')
mask = n_image.colorDistance((127, 127, 127))
mask.show()
mask.save('mask.jpg')
time.sleep(3)
binarised = mask.binarize()
blobs = binarised.findBlobs()
blobs.show(width=3)
time.sleep(60)
individualareaofholes = blobs.area()
compositeareaofholes = sum(individualareaofholes)
orig_area = 132432
finalarea = (orig_area - compositeareaofholes)
res = round(((finalarea/orig_area)*100),0)
print "Area is %d" % res
は、面積計算のために使用される画像 "mask.jpg" である:
は観察:内部 1.黒色パッチ"mask.jpg"の白い部分 2.左下の白い部分に "TAXI"と表示されます
どうすれば削除できますか? 私は、黒い線で囲まれたものすべてを掴んで、線を外したものはすべて面積を計算する際に考慮しないことを望みます。