| | |
| | | |
| | | import pkg_resources |
| | | |
| | | templatefile = '/template-8.png' # always use slash |
| | | templatefile = "/template-8.png" # always use slash |
| | | template8 = pkg_resources.resource_filename(__name__, templatefile) |
| | | |
| | | |
| | |
| | | return np.ones((x, y), np.uint8) |
| | | |
| | | |
| | | def find_biggest_blob(image, original_image,sid_mask): |
| | | def find_biggest_blob(image, original_image, sid_mask): |
| | | if sid_mask[0] == "1": |
| | | move_left = 35 |
| | | elif sid_mask[0] == "x": |
| | | move_left = 40 |
| | | else: |
| | | move_left = 0 |
| | | # Remove noise |
| | | # Remove noise |
| | | image2 = cv2.morphologyEx( |
| | | original_image, cv2.MORPH_OPEN, kernel(2, 2), iterations=3 |
| | | ) |
| | |
| | | image = image[y : y + h, x + 25 - move_left : x + w - 40] # +25,-25 |
| | | return image |
| | | |
| | | |
| | | def sid_compare(sid_no, sid_mask): |
| | | """ |
| | | Function compares student id number with student id mask if the recognised number is valid according to the mask |
| | |
| | | return True |
| | | |
| | | |
| | | def segment_by_contours(image, original_image, classifier,sid_mask): |
| | | def segment_by_contours(image, original_image, classifier, sid_mask): |
| | | """ |
| | | First algorithm. it segments numerals with contours. It works with numbers where individual numerals does not touch. |
| | | :param image: |
| | |
| | | """ |
| | | |
| | | sid_no = "" |
| | | image=find_biggest_blob(image,original_image,sid_mask) |
| | | cv2.imwrite("/tmp/sid_contour1.png",image) |
| | | image = find_biggest_blob(image, original_image, sid_mask) |
| | | cv2.imwrite("/tmp/sid_contour1.png", image) |
| | | im2, ctrs, hier = cv2.findContours( |
| | | image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE |
| | | ) |
| | |
| | | """ |
| | | sid_no = "" |
| | | sid_len = len(sid_mask) |
| | | image=find_biggest_blob(image,original_image,sid_mask) |
| | | image = find_biggest_blob(image, original_image, sid_mask) |
| | | cv2.imwrite("/tmp/sidblock2.png", image) |
| | | imgHeight, imgWidth = image.shape[0:2] |
| | | numWidth = int(imgWidth / (sid_len)) |
| | |
| | | cv2.imwrite("/tmp/enSID0.png", image) |
| | | |
| | | # Remove noise |
| | | #image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(2, 2), iterations=3) |
| | | # image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(2, 2), iterations=3) |
| | | |
| | | # Closing. Connect non connected parts |
| | | image = cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel(5, 1), iterations=4) |