def extract_plate(cropped, is_initialized):
    # Initialize zmq context and sockets when necessary
    if not is_initialized:
        print("Initializing plate sockets")
        extract_plate.ctx = zmq.Context(io_threads=1)
        plate_host = plate_configs.plate_server["host"]
        plate_port = plate_configs.plate_server["port"]
        plate_address = zmq_comm.get_tcp_address(plate_host, plate_port)
        extract_plate.plate_client = zmq_comm.init_client(
            extract_plate.ctx, plate_address)
        is_initialized = True

    found_plate = ""
    # Encode and send cropped car to detect plate location
    cv_encoded_img = cv2.imencode(".jpg", cropped)[1]
    encoded_img = base64.b64encode(cv_encoded_img)
    extract_plate.plate_client.send(encoded_img)
    plate_reply = extract_plate.plate_client.recv()
    plate_reply = json.loads(plate_reply.decode("utf-8"))
    # If there is an error, just return an empty plate
    if plate_reply['message'] != "OK":
        return found_plate, is_initialized

    found_plate = plate_reply['result']
    return found_plate, is_initialized
Beispiel #2
0
 def __init__(self, machine=None):
     try:
         self.config_man = ConfigManager()
         self.configure(machine)
         self.host, self.port = self.get_server_configs()
         self.address = zmqc.get_tcp_address(self.host, self.port)
         self.ctx = zmq.Context(io_threads=1)
         self.socket = zmqc.init_server(self.ctx, self.address)
     except Exception as e:
         print(str(e))
         self.terminate()
            if plate:
                if plate_pattern.search(plate):
                    cv2.imwrite(
                        out_path + "/" + str(plate) + '_' + str(uuid.uuid4()) +
                        '.jpg', cropped_plate_img)
                else:
                    print("Did not save this: ", plate)
    except Exception as e:
        print(str(e))


if __name__ == '__main__':
    host = PlateConfig.plate_server['host']
    port = PlateConfig.plate_server['port']
    address = zmq_comm.get_tcp_address(host, port)
    ctx = zmq.Context(io_threads=1)
    socket = zmq_comm.init_client(ctx, address)

    current_dir = os.path.dirname(os.path.realpath(__file__))
    unprocessed_imgs_path = "/home/taylan/local/plate_data/cropped"
    output_path = "/home/taylan/local/plate_data/plate_test_regex"

    # Recursively reads images under a given directory path, queries the plates in images one by one
    image_paths = []
    for dirName, subdirList, fileList in os.walk(unprocessed_imgs_path):
        print(dirName)
        for fname in fileList:
            p = dirName + '/' + fname
            if os.path.isfile(p):
                image_paths.append(p)