Пример #1
0
    def handle_client_traffic(self, client_socket, client_addr):
        """
        This method will handle incoming traffic from a given client.
        :param client_socket:
        :param client_addr:
        :return:
        """
        lot_id = client_socket.recv(4)
        lot_id = unpack('!I', lot_id)
        apiclient = openalpr_api.DefaultApi()

        file_name = str(getpid())
        img_file = open(file_name, 'wr+')
        payload = client_socket.recv(1024)
        while (payload):
            print "Receiving..."
            img_file.write(payload)
            payload = client_socket.recv(1024)
        img_file.close()

        response = apiclient.recognize_post('sk_6cb172cdd75b54826a2089b0',
                                            "plate,color,make,makemodel",
                                            'Users/mohammadsial/Desktop/test',
                                            country="us")
        plate = response.plate.results[0].plate
        confidence = response.plate.results[0].confidence

        self.write_to_log('Plate : ' + plate)
        self.write_to_log('Confidence : ' + str(confidence))
        self.put_entry_in_db(lot_id, plate)
Пример #2
0
    def __init__(self, region, confidence, api_key):
        """Init cloud api processing."""
        import openalpr_api

        super().__init__(region=region, confidence=confidence)
        self._api = openalpr_api.DefaultApi()
        self._api_key = api_key
Пример #3
0
def callAPI(image_url):
    target_path = _j('tmp', image_url.split('/')[-1])
    urllib.urlretrieve(image_url, target_path)
    with open(target_path, "rb") as image_file:
        image_bytes = base64.b64encode(image_file.read())
    api_instance = openalpr_api.DefaultApi()
    secret_key = 'sk_e014dacb3b70f1a4a902b301'
    country = "us"
    recognize_vehicle = 0
    state = ''
    return_image = 0
    topn = 10
    prewarp = ''

    try:
        api_response = api_instance.recognize_bytes(image_bytes,
                                                    secret_key,
                                                    country,
                                                    recognize_vehicle=0,
                                                    state='',
                                                    return_image=0,
                                                    topn=10,
                                                    prewarp='')
        return api_response
    except ApiException as e:
        print "Exception when calling DefaultApi->recognize_bytes: %s\n" % e
Пример #4
0
def process_car_image(image_path):
    # create an instance of the API class
    api_instance = openalpr_api.DefaultApi()
    secret_key = 'sk_4fb6feea66fb6b5524b2d984'  # str | The secret key used to authenticate your account.  You can view your  secret key by visiting  https://cloud.openalpr.com/
    country = 'br'  # str | Defines the training data used by OpenALPR.  \"us\" analyzes  North-American style plates.  \"eu\" analyzes European-style plates.  This field is required if using the \"plate\" task  You may use multiple datasets by using commas between the country  codes.  For example, 'au,auwide' would analyze using both the  Australian plate styles.  A full list of supported country codes  can be found here https://github.com/openalpr/openalpr/tree/master/runtime_data/config
    recognize_vehicle = 0  # int | If set to 1, the vehicle will also be recognized in the image This requires an additional credit per request  (optional) (default to 0)
    state = ''  # str | Corresponds to a US state or EU country code used by OpenALPR pattern  recognition.  For example, using \"md\" matches US plates against the  Maryland plate patterns.  Using \"fr\" matches European plates against  the French plate patterns.  (optional) (default to )
    return_image = 0  # int | If set to 1, the image you uploaded will be encoded in base64 and  sent back along with the response  (optional) (default to 0)
    topn = 10  # int | The number of results you would like to be returned for plate  candidates and vehicle classifications  (optional) (default to 10)
    prewarp = ''  # str | Prewarp configuration is used to calibrate the analyses for the  angle of a particular camera.  More information is available here http://doc.openalpr.com/accuracy_improvements.html#calibration  (optional) (default to )
    try:
        # call api
        api_response = api_instance.recognize_file(
            image_path,
            secret_key,
            country,
            recognize_vehicle=recognize_vehicle,
            state=state,
            return_image=return_image,
            topn=topn,
            prewarp=prewarp)

        # print(api_response)
        print('Start processing for ' + api_response.results[0].plate)
        try:
            # sucessful plate recognition
            plate = api_response.results[0].plate
            file_name = now.strftime("%Y-%m-%d") + '_logs.csv'

            # SINESP informations
            time = now.strftime("%Y-%m-%d %H:%M")
            columns = [time, plate] + get_car_info(plate)

            # writing log
            write_log(plate, file_name, columns)
        except:
            # fail plate recognition
            print('-> Fail Plate Recognition')
            return 'Fail'
    except ApiException as e:
        print("Exception when calling DefaultApi> recognize_file: %s\n" % e)
Пример #5
0
def Number_plate(path,count):

    api_instance = openalpr_api.DefaultApi()
    with open(path, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read())
    
    image_bytes = encoded_string # str | The image file that you wish to analyze encoded in base64 
    secret_key = 'sk_DEMODEMODEMODEMODEMODEMO' 
    country = 'in' # A full list of supported country codes  can be found here https://github.com/openalpr/openalpr/tree/master/runtime_data/config 
    recognize_vehicle = 0 #If set to 1, the vehicle will also be recognized in the image This requires an additional credit per request  (optional) (default to 0)
    state = '' # str | Corresponds to a US state or EU country code used by OpenALPR pattern  recognition.  For example, using \"md\" matches US plates against the  Maryland plate patterns.  Using \"fr\" matches European plates against  the French plate patterns.  (optional) (default to )
    return_image = 0 # int | If set to 1, the image you uploaded will be encoded in base64 and  sent back along with the response  (optional) (default to 0)
    topn = 3 # int | The number of results you would like to be returned for plate  candidates and vehicle classifications  (optional) (default to 10)
    prewarp = '' # str | Prewarp configuration is used to calibrate the analyses for the  angle of a particular camera.  More information is available here http://doc.openalpr.com/accuracy_improvements.html#calibration  (optional) (default to )

    try:
        a=[]
        api_response = api_instance.recognize_bytes(image_bytes, secret_key, country, recognize_vehicle=recognize_vehicle, state=state, return_image=return_image, topn=topn, prewarp=prewarp)
        # pprint(api_response)
        i =0  
        if(len(api_response.results)!=0) :
            for i in api_response.results[0].candidates :
                a.append(i.plate)
            if len(a)==1 or len(a)==2:
                a.append(a[0])
                a.append(a[0])
            return a
        else :
            return ["NO_PLATE",'','']

    except ApiException as e:
        print ("Exception when calling DefaultApi->recognize_bytes: %s\n" % e)

# for i in range(1,41):
#     a=Number_plate("Vehicles\\1 ("+str(i)+").jpg",5)
#     print(a)

        print(a[0])
Пример #6
0
def detectNumberPlate(fileName):
	import time
	import openalpr_api
	from openalpr_api.rest import ApiException
	from pprint import pprint
	import json
	# create an instance of the API class
	api_instance = openalpr_api.DefaultApi()
	import base64
	encoded = base64.b64encode(open(fileName, "rb").read())
	image_bytes = encoded # str | The image file that you wish to analyze encoded in base64 
	secret_key = 'sk_97a11cda807cbf257bffa0fd' # str | The secret key used to authenticate your account.  You can view your  secret key by visiting  https://cloud.openalpr.com/ 
	country = 'in' # str | Defines the training data used by OpenALPR.  \"us\" analyzes  North-American style plates.  \"eu\" analyzes European-style plates.  This field is required if using the \"plate\" task  You may use multiple datasets by using commas between the country  codes.  For example, 'au,auwide' would analyze using both the  Australian plate styles.  A full list of supported country codes  can be found here https://github.com/openalpr/openalpr/tree/master/runtime_data/config 
	recognize_vehicle = 0 # int | If set to 1, the vehicle will also be recognized in the image This requires an additional credit per request  (optional) (default to 0)
	state = '' # str | Corresponds to a US state or EU country code used by OpenALPR pattern  recognition.  For example, using \"md\" matches US plates against the  Maryland plate patterns.  Using \"fr\" matches European plates against  the French plate patterns.  (optional) (default to )
	return_image = 1 # int | If set to 1, the image you uploaded will be encoded in base64 and  sent back along with the response  (optional) (default to 0)
	topn = 10 # int | The number of results you would like to be returned for plate  candidates and vehicle classifications  (optional) (default to 10)
	prewarp = '' # str | Prewarp configuration is used to calibrate the analyses for the  angle of a particular camera.  More information is available here http://doc.openalpr.com/accuracy_improvements.html#calibration  (optional) (default to )

	try:
		api_response = api_instance.recognize_bytes(image_bytes, secret_key, country, recognize_vehicle=recognize_vehicle, state=state, return_image=return_image, topn=topn, prewarp=prewarp)
		pprint(api_response)
		jsonFormat =str(api_response)
		jsonFormat = jsonFormat.replace('\'','"')
		jsonFormat = jsonFormat.replace('None','"None"')
		myDict = json.loads(jsonFormat)
		#print(some)
		#print('dic type is : '+ str(type(dic)))
		try:
			nplate = myDict["results"][0]["candidates"][0]['plate']
			import data
			return data.doQuery(nplate)
		except:
			print("No number plate detected")
		
	except ApiException as e:
		print "Exception when calling DefaultApi->recognize_bytes: %s\n" % e
from utils import label_map_util

from utils import visualization_utils as vis_util

# What model to download.
MODEL_NAME = 'Cars'

# Path to frozen detection graph. This is the actual model that is used for the object detection.
PATH_TO_CKPT = MODEL_NAME + '/output_inference_graph.pb'

# List of the strings that is used to add correct label for each box.
PATH_TO_LABELS = os.path.join('Cars', 'car_label_map.pbtxt')

NUM_CLASSES = 1

api = openalpr_api.DefaultApi()
secret_key = ''
country = 'us'
recognize_vehicle = 0
state = ''
return_image = 0
topn = 1
prewarp = ''


def getLicensePlateNumber(filer):
    try:
        js = api.recognize_file(filer,
                                secret_key,
                                country,
                                recognize_vehicle=recognize_vehicle,
Пример #8
0
import time
import openalpr_api
import os
from os import walk
from openalpr_api.rest import ApiException
from pprint import pprint
# create an instance of the API class
api_instance = openalpr_api.DefaultApi()
#with open("7.png", "rb") as f:
#data = f.read()
#image_bytes = data.encode("base64")
import base64
import glob
SIZE = []
txtfiles = []
cls_id = 0
for file1 in glob.glob1(os.getcwd() + '/Images/', "*.png"):
    print(file1)
    with open('Images/' + file1, "rb") as image_file:
        image_bytes = base64.b64encode(image_file.read())
#image_bytes = '7.png' # str | The image file that you wish to analyze encoded in base64
    secret_key = 'sk_DEMODEMODEMODEMODEMODEMO'
    country = 'in'
    recognize_vehicle = 0
    state = ''
    return_image = 1
    topn = 1
    prewarp = ''
    try:
        api_response = api_instance.recognize_bytes(
            image_bytes,
Пример #9
0
import openalpr_api


apiclient = openalpr_api.DefaultApi()

response = apiclient.recognize_post("sk_DEMODEMODEMODEMODEMODEMO", "plate,color,make,makemodel", image="/storage/projects/alpr/samples/testing/car1.jpg", country="us")


for plate_obj in response.plate.results:
	print "Plate:      %s - %f percent" % (plate_obj.plate, plate_obj.confidence)

print "Color:      %s - %f percent" % (response.color[0].value, response.color[0].confidence)
print "Make:       %s - %f percent" % (response.make[0].value, response.make[0].confidence)
print "Make-model: %s - %f percent" % (response.makemodel[0].value, response.makemodel[0].confidence)