| | |
| | | # Get bounding box |
| | | x, y, w, h = cv2.boundingRect(ctr) |
| | | # Getting ROI |
| | | if w < h / 2: |
| | | if w < h / 3: |
| | | sid_no = sid_no + "1" |
| | | continue |
| | | roi = image[y : y + h, x : x + w] |
| | |
| | | cv2.imwrite("/tmp/enSID0.png", image) |
| | | |
| | | # Remove noise |
| | | image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(3, 3), iterations=3) |
| | | image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(3, 3), iterations=2) |
| | | |
| | | # Closing. Connect non connected parts |
| | | image = cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel(5, 1), iterations=4) |
| | |
| | | # Again noise removal after closing |
| | | #image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(8, 8), iterations=1) |
| | | # don't do too much noise removal. |
| | | image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(3, 3), iterations=1) |
| | | #image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(3, 3), iterations=2) |
| | | |
| | | # Skeletonization |
| | | #image = img_as_ubyte(morphology.skeletonize(image > 128)) |
| | |
| | | |
| | | if not sid_compare(sid_no, sid_mask): |
| | | sid_err = ["Wrong SID!"] |
| | | |
| | | cv2.imwrite("/tmp/SID_"+sid_no+".png", image) |
| | | return sid_no, sid_err, sid_warn |