import os import cv import anpr from quick_show import quick_show files = os.listdir('data/examples') counter = 0 for f in files: image = cv.LoadImage('data/examples/'+f) for plate in anpr.detect_plates(image): zzz = cv.CreateImage(cv.GetSize(plate), cv.IPL_DEPTH_8U, 3) cv.Smooth(plate, zzz) # cv.PyrMeanShiftFiltering(plate, zzz, 40, 15) foo = anpr.greyscale(plate) segmented = cv.CreateImage(cv.GetSize(plate), cv.IPL_DEPTH_8U, 1) bar = cv.CreateImage(cv.GetSize(plate), cv.IPL_DEPTH_8U, 1) cv.EqualizeHist(foo, segmented) cv.AdaptiveThreshold(segmented, bar, 255, cv.CV_ADAPTIVE_THRESH_GAUSSIAN_C, cv.CV_THRESH_BINARY_INV, plate.height%2 == 0 and (plate.height+1) or plate.height, plate.height/2) baz = cv.CreateImage(cv.GetSize(plate), cv.IPL_DEPTH_8U, 1) el = cv.CreateStructuringElementEx(1, 2, 0, 0, cv.CV_SHAPE_RECT) cv.Erode(bar, baz, el) #quick_show(plate) #quick_show(segmented) #quick_show(bar) quick_show(baz) for char in anpr.find_characters(foo, baz):
Created by Oliver Smith on 2009-09-26. Copyright (c) 2009 Oliver Smith. All rights reserved. """ import os import cv import anpr from quick_show import quick_show files = os.listdir('data/examples') counter = 0 for f in files: image = cv.LoadImage('data/examples/' + f) for plate in anpr.detect_plates(image): plate_grey = anpr.greyscale(plate) hist = cv.CreateHist([256], cv.CV_HIST_ARRAY, [[0, 255]]) cv.CalcHist([plate_grey], hist) total_pixels = plate_grey.width * plate_grey.height accum = 0 threshold = 0 for i in range(0, 256): accum += cv.QueryHistValue_1D(hist, i) if accum > total_pixels * .45: threshold = i break print threshold plate_mono = cv.CreateImage((plate.width, plate.height), cv.IPL_DEPTH_8U, 1) cv.Threshold(plate_grey, plate_mono, threshold, 255.0, cv.CV_THRESH_BINARY)
import os import cv import anpr from quick_show import quick_show files = os.listdir('data/examples') counter = 0 for f in files: image = cv.LoadImage('data/examples/' + f) for plate in anpr.detect_plates(image): zzz = cv.CreateImage(cv.GetSize(plate), cv.IPL_DEPTH_8U, 3) cv.Smooth(plate, zzz) # cv.PyrMeanShiftFiltering(plate, zzz, 40, 15) foo = anpr.greyscale(plate) segmented = cv.CreateImage(cv.GetSize(plate), cv.IPL_DEPTH_8U, 1) bar = cv.CreateImage(cv.GetSize(plate), cv.IPL_DEPTH_8U, 1) cv.EqualizeHist(foo, segmented) cv.AdaptiveThreshold( segmented, bar, 255, cv.CV_ADAPTIVE_THRESH_GAUSSIAN_C, cv.CV_THRESH_BINARY_INV, plate.height % 2 == 0 and (plate.height + 1) or plate.height, plate.height / 2) baz = cv.CreateImage(cv.GetSize(plate), cv.IPL_DEPTH_8U, 1) el = cv.CreateStructuringElementEx(1, 2, 0, 0, cv.CV_SHAPE_RECT) cv.Erode(bar, baz, el) #quick_show(plate) #quick_show(segmented) #quick_show(bar) quick_show(baz)
Created by Oliver Smith on 2009-09-26. Copyright (c) 2009 Oliver Smith. All rights reserved. """ import os import cv import anpr from quick_show import quick_show files = os.listdir('data/examples') counter = 0 for f in files: image = cv.LoadImage('data/examples/'+f) for plate in anpr.detect_plates(image): plate_grey = anpr.greyscale(plate) hist = cv.CreateHist([256], cv.CV_HIST_ARRAY, [[0,255]]) cv.CalcHist([plate_grey], hist) total_pixels = plate_grey.width * plate_grey.height accum = 0 threshold = 0 for i in range(0,256): accum += cv.QueryHistValue_1D(hist, i) if accum > total_pixels*.45: threshold = i break print threshold plate_mono = cv.CreateImage((plate.width,plate.height), cv.IPL_DEPTH_8U, 1) cv.Threshold(plate_grey,