import cv2;
import numpy as np;
from matplotlib import pyplot as plt;

class Plate:
	""" A class for the license plates """
	def __init__(self, image):
		self.original_image = image;
		self.plate_image = None;
		self.gray_image = None;
		self.plate_number = "";

	def grayImage(self):
		self.gray_image = cv2.cvtColor(self.original_image, cv2.COLOR_BGR2GRAY);
		# apply a heavy gaussian blur
		self.gray_image = cv2.GaussianBlur(self.gray_image, (45,45), 0);

	def findContour(self):
		self.grayImage();
		ret, threshold = cv2.threshold(self.gray_image, 127, 255, 0);
		image, contours, hierarchy = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE);
		potential_plates = [];
		w = 0;

		print("[findContour]: "+str(len(contours))+" contours found...");

		for contour in contours:
			area = cv2.contourArea(contour);
			if area > 200 and area < 400:
				[w,h,x,y] = cv2.boundingRect(contour);

			if w > 50:
				potential_plates.append(contour);
				cv2.fillPoly(self.original_image, pts=contour, color=(255,255,255));

		#final_image = cv2.drawContours(self.original_image, potential_plates, -1, (0,255,0), 4);

		plt.figure();
		plt.imshow(final_image);
		plt.show();


@@ -254,16 +254,33 @@
 er = %22%22;
+%0A%09%09self.roi = %5B%5D;
 %0A%0A%09def g
@@ -374,39 +374,52 @@
 Y);%0A
+%0A
 %09%09# 
-apply a heavy gaussian bl
+blur image to remove noise for conto
 ur
+s
 %0A%09%09s
@@ -474,13 +474,13 @@
 e, (
-45,45
+29,29
 ), 0
@@ -593,23 +593,18 @@
 , 0);%0A%09%09
-image, 
+_,
 contours
@@ -608,18 +608,9 @@
 urs,
- hierarchy
+_
  = c
@@ -681,109 +681,28 @@
 E);%0A
-%09%09potential_plates = %5B%5D;%0A%09%09w = 0;%0A%0A%09%09print(%22%5BfindContour%5D: %22+str(len(contours))+%22 contours found...%22)
+%0A%09%09w,h,x,y = 0,0,0,0
 ;%0A%0A%09
@@ -776,17 +776,18 @@
  area %3E 
-2
+60
 00 and a
@@ -799,22 +799,24 @@
  400
+00
 :%0A%09%09%09%09%5B
-w,h,x,y
+x,y,w,h
 %5D = 
@@ -857,32 +857,60 @@
 w %3E 
-50:%0A%09%09%09%09potential_plates
+100 and w %3C 200 and h %3E 60 and h %3C 100:%0A%09%09%09%09self.roi
 .app
@@ -935,16 +935,17 @@
 cv2.
-fillPoly
+rectangle
 (sel
@@ -966,98 +966,90 @@
 ge, 
-pts=contour, color=(255,255,255));%0A%0A%09%09#final_image = cv2.drawContours(self.original_image,
+(x,y), (x+w, y+h), (0,255,0), 15);%0A%0A%09%09print(%22%5BfindContour%5D: %22+str(len(self.roi))+%22
  pot
@@ -1058,33 +1058,25 @@
 tial
-_
+ 
 plates
-, -1, (0,255,0), 4
+ found...%22
 );%0A%0A
@@ -1104,17 +1104,25 @@
 .imshow(
-f
+self.orig
 inal_ima

basic contour searching for rectangles of certain area. low success rate