Last active
June 27, 2018 06:50
-
-
Save femioladeji/a1ecd2b7f26fc562975bb1b5b59143b9 to your computer and use it in GitHub Desktop.
Improved Connected Component Analysis that removes some regions based on some characteristics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage import measure | |
from skimage.measure import regionprops | |
import matplotlib.pyplot as plt | |
import matplotlib.patches as patches | |
import localization | |
# this gets all the connected regions and groups them together | |
label_image = measure.label(localization.binary_car_image) | |
# getting the maximum width, height and minimum width and height that a license plate can be | |
plate_dimensions = (0.08*label_image.shape[0], 0.2*label_image.shape[0], 0.15*label_image.shape[1], 0.4*label_image.shape[1]) | |
min_height, max_height, min_width, max_width = plate_dimensions | |
plate_objects_cordinates = [] | |
plate_like_objects = [] | |
fig, (ax1) = plt.subplots(1) | |
ax1.imshow(localization.gray_car_image, cmap="gray"); | |
# regionprops creates a list of properties of all the labelled regions | |
for region in regionprops(label_image): | |
if region.area < 50: | |
#if the region is so small then it's likely not a license plate | |
continue | |
# the bounding box coordinates | |
min_row, min_col, max_row, max_col = region.bbox | |
region_height = max_row - min_row | |
region_width = max_col - min_col | |
# ensuring that the region identified satisfies the condition of a typical license plate | |
if region_height >= min_height and region_height <= max_height and region_width >= min_width and region_width <= max_width and region_width > region_height: | |
plate_like_objects.append(localization.binary_car_image[min_row:max_row, | |
min_col:max_col]) | |
plate_objects_cordinates.append((min_row, min_col, | |
max_row, max_col)) | |
rectBorder = patches.Rectangle((min_col, min_row), max_col-min_col, max_row-min_row, edgecolor="red", linewidth=2, fill=False) | |
ax1.add_patch(rectBorder) | |
# let's draw a red rectangle over those regions | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
label_image = measure.label(localization.binary_car_image)
Error : module localization has no attribute(binary_car_image)
Can u explain me how to rid off this error