예제 #1
0
Testing character extraction.

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):
		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)
예제 #2
0
    #    waitKey(0)
    #    destroyWindow("cam-test")
    imwrite('./tmp/temp.jpg', camimg)  #("test.jpg",camimg) #save image
#ImageMagick - textcleaner script: Cleaning source picture for background noise.
#with open(os.devnull, "w") as f: #open dev/null to obj
#    subprocess.call(["./textcleaner.sh", "-g", "./tmp/temp.jpg", "./tmp/converted_image.jpg"], stderr=f) #clean image, and suppress errors. Needs some fine-tuning.
#Current time for capturing.
now = datetime.datetime.now()
capTime = now.strftime("%Y-%m-%d %H:%M")
#Restraining to a smaller area of a specific web-cam will also be preferable.
print '\n\nRunning OpenANPR by O.E.Smith'
counter = 0
image = cv.LoadImage(
    './tmp/temp.jpg')  #possible multiple outputs. Therefore the loop.
for plate in anpr.detect_plates(
        image
):  #Need some sort of method to include all possbile outputs to 1 ID - maybe another counter and DB entry of sorts?
    cv.SaveImage(
        'processed_temp.jpg' % counter, plate
    )  #counter processed_temp%02d.jpg, but how to "pick up" from there?
    counter = counter + 1

print '\n\nRunning picture through Tesseract OCR, by Google\n\n'
#Tesseract OCR
im = Image.open('./tmp/processed_temp.jpg')  #
text = image_to_string(im)
print '\n\nPrinting output of OCR process: ' + text
#SQL connection string.
cnxn = pyodbc.connect('DRIVER={MySQL ODBC 5.1 Driver};SERVER=' + server +
                      ';DATABASE=' + database + ';UID=' + uid + ';PWD=' + pwd)
cursor = cnxn.cursor()
예제 #3
0
파일: plates.py 프로젝트: ealkl/OpenANPR
#!/usr/bin/env python
# encoding: utf-8
"""
test/plates.py

Testing plate detection.

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 ['30082009_007.jpg']:
    image = cv.LoadImage('data/examples/' + f)
    for plate in anpr.detect_plates(image):
        cv.SaveImage('output%02d.png' % counter, plate)
        counter = counter + 1
예제 #4
0
#    namedWindow("cam-test",CV_WINDOW_AUTOSIZE)
#    imshow("cam-test",camimg)
#    waitKey(0)
#    destroyWindow("cam-test")
    imwrite('./tmp/temp.jpg', camimg)#("test.jpg",camimg) #save image
#ImageMagick - textcleaner script: Cleaning source picture for background noise.
#with open(os.devnull, "w") as f: #open dev/null to obj
#    subprocess.call(["./textcleaner.sh", "-g", "./tmp/temp.jpg", "./tmp/converted_image.jpg"], stderr=f) #clean image, and suppress errors. Needs some fine-tuning.
#Current time for capturing.
now = datetime.datetime.now()
capTime = now.strftime("%Y-%m-%d %H:%M")
#Restraining to a smaller area of a specific web-cam will also be preferable.
print '\n\nRunning OpenANPR by O.E.Smith'
counter = 0
image = cv.LoadImage('./tmp/temp.jpg') #possible multiple outputs. Therefore the loop.
for plate in anpr.detect_plates(image): #Need some sort of method to include all possbile outputs to 1 ID - maybe another counter and DB entry of sorts?
    cv.SaveImage('processed_temp.jpg' % counter, plate) #counter processed_temp%02d.jpg, but how to "pick up" from there?
    counter = counter+1

print '\n\nRunning picture through Tesseract OCR, by Google\n\n'
#Tesseract OCR
im = Image.open('./tmp/processed_temp.jpg') #
text = image_to_string(im)
print '\n\nPrinting output of OCR process: ' + text
#SQL connection string.
cnxn = pyodbc.connect('DRIVER={MySQL ODBC 5.1 Driver};SERVER=' + server + ';DATABASE=' + database + ';UID=' + uid + ';PWD=' + pwd)
cursor = cnxn.cursor()
cursor.execute("insert into ocrplates(numberplate, timestamp) values (?, ?)", text, capTime)
cnxn.commit()
cursor.execute("SELECT @@IDENTITY") #Triggers DB id generated. This ID will be the filename of the picture.
for row in cursor.fetchall():