(args,frame)
| 252 | |
| 253 | # Main predict function that runs the model for given frame and calls other helper functions for processing and data updating. |
| 254 | def predict(args,frame): |
| 255 | |
| 256 | # Check if image exist |
| 257 | if not os.path.isfile(args.image): |
| 258 | print(TAG + "File doesn't exist: %s" % args.image) |
| 259 | assert False |
| 260 | |
| 261 | # Decode the image |
| 262 | image = Image.open(args.image) |
| 263 | #image = frame |
| 264 | |
| 265 | width, height = image.size |
| 266 | # Read the EXIF orientation value |
| 267 | exif = image._getexif() |
| 268 | exifOrientation = exif[ORIENTATION_TAG[0]] if len(ORIENTATION_TAG) == 1 and exif != None else 1 |
| 269 | |
| 270 | # Update JSON options using values from the command args |
| 271 | |
| 272 | global count |
| 273 | if count==0: |
| 274 | JSON_CONFIG["assets_folder"] = args.assets |
| 275 | JSON_CONFIG["charset"] = args.charset |
| 276 | JSON_CONFIG["car_noplate_detect_enabled"] = (args.car_noplate_detect_enabled == "True") |
| 277 | JSON_CONFIG["ienv_enabled"] = (args.ienv_enabled == "True") |
| 278 | JSON_CONFIG["openvino_enabled"] = (args.openvino_enabled == "True") |
| 279 | JSON_CONFIG["openvino_device"] = args.openvino_device |
| 280 | JSON_CONFIG["klass_lpci_enabled"] = (args.klass_lpci_enabled == "True") |
| 281 | JSON_CONFIG["klass_vcr_enabled"] = (args.klass_vcr_enabled == "True") |
| 282 | JSON_CONFIG["klass_vmmr_enabled"] = (args.klass_vmmr_enabled == "True") |
| 283 | JSON_CONFIG["klass_vbsr_enabled"] = (args.klass_vbsr_enabled == "True") |
| 284 | JSON_CONFIG["license_token_file"] = args.tokenfile |
| 285 | JSON_CONFIG["license_token_data"] = args.tokendata |
| 286 | |
| 287 | # Initialize the engine |
| 288 | |
| 289 | checkResult("Init", |
| 290 | ultimateAlprSdk.UltAlprSdkEngine_init(json.dumps(JSON_CONFIG)) |
| 291 | ) |
| 292 | count=1 |
| 293 | |
| 294 | # Recognize/Process |
| 295 | # Please note that the first time you call this function all deep learning models will be loaded |
| 296 | # and initialized which means it will be slow. In your application you've to initialize the engine |
| 297 | # once and do all the recognitions you need then, deinitialize it. |
| 298 | |
| 299 | warpedBox,texts_lst = checkResult("Process", |
| 300 | ultimateAlprSdk.UltAlprSdkEngine_process( |
| 301 | format, |
| 302 | image.tobytes(), # type(x) == bytes |
| 303 | width, |
| 304 | height, |
| 305 | 0, # stride |
| 306 | exifOrientation |
| 307 | ) |
| 308 | ) |
| 309 | return(warpedBox,texts_lst) |
| 310 | |
| 311 | # Run initially only. To check the FPS of input video. At the same time, it does some initializations too. So make sure you take care of them if dont want to checkFPS |
no test coverage detected