|
@@ -20,22 +20,25 @@ def contourIndex(lista):
|
|
|
return index
|
|
|
|
|
|
img=cv2.imread(sys.argv[1],cv2.CV_LOAD_IMAGE_GRAYSCALE)
|
|
|
+#img=cv2.imread(sys.argv[1],cv2.CV_LOAD_IMAGE_COLOR)
|
|
|
#la riga successiva serve a rendere visualizzabile l immagine sul nostro pc
|
|
|
#img=cv2.resize(img,(350,262))
|
|
|
-#assumendo che il background e nero nelle condizioni attuali (27/12/2016) del bookscanner il valore buono e 100
|
|
|
-buono=155
|
|
|
-mask=cv2.inRange(img,0,buono)
|
|
|
-#show(mask)
|
|
|
-mask=255-mask
|
|
|
+#assumendo che il background e nero nelle condizioni attuali (27/12/2016) del bookscanner il valore buono e 100 (su 255)
|
|
|
+buono=100
|
|
|
+mask=cv2.inRange(img,buono,255)
|
|
|
contorni, hier =cv2.findContours(mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
|
|
|
-bianco=np.zeros(mask.shape,dtype=np.uint8)
|
|
|
-img=cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
|
|
|
+bianco=np.zeros(mask.shape,dtype=np.uint8) # crea un coso nero
|
|
|
|
|
|
# indexImportante indica il contorno piu grande, che crediamo sia quello del libro
|
|
|
indexImportante=contourIndex(contorni)
|
|
|
cv2.drawContours(img,contorni,indexImportante,255,thickness=3)
|
|
|
-cv2.fillPoly(bianco,[contorni[indexImportante]],255)
|
|
|
-show(bianco)
|
|
|
-cv2.imwrite(sys.argv[2],bianco)
|
|
|
+cv2.fillPoly(bianco,[contorni[indexImportante]], 255)
|
|
|
+
|
|
|
+img=cv2.imread(sys.argv[1],cv2.CV_LOAD_IMAGE_COLOR)
|
|
|
+img = cv2.bitwise_and(img, img, mask=bianco)
|
|
|
+if len(sys.argv) > 2:
|
|
|
+ cv2.imwrite(sys.argv[2],img)
|
|
|
+else:
|
|
|
+ show(img)
|
|
|
|
|
|
# vim: set ts=4 sw=4 et:
|