-2
weight_file = r'D:\deepak\Helmet-Detection-final\model\rider_helmet_number_medium.pt'
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = attempt_load(yolov5_weight_file, map_location=device)
cudnn.benchmark = True
names = model.module.names if hasattr(model, 'module') else model.name



def license_plate(frame):
    try:
        img = torch.from_numpy(frame)
        img = img.permute(2, 0, 1).float().to(device)
        img /= 255.0
        if img.ndimension() == 3:
            img = img.unsqueeze(0)

        # model = attempt_load(yolov5_weight_file, map_location=device)
        cudnn.benchmark = True
        # names = model.module.names if hasattr(model, 'module') else model.names

        pred = model(img, augment=False)[0]
        pred = non_max_suppression(pred, conf_set, 0.30)  # prediction, conf, iou

        detection_result = []
        for i, det in enumerate(pred):
            if len(det):
                for d in det:  # d = (x1, y1, x2, y2, conf, cls)
                    x1 = int(d[0].item())
                    y1 = int(d[1].item())
                    x2 = int(d[2].item())
                    y2 = int(d[3].item())
                    conf = round(d[4].item(), 2)
                    c = int(d[5].item())

                    detected_name = names[c]

                    print(f'Detected: {detected_name} conf: {conf}  bbox: x1:{x1}    y1:{y1}    
                    x2:{x2}    y2:{y2}')
                    detection_result.append([x1, y1, x2, y2, conf, c])
                    if c == 0 or c == 2:
                        frame = cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 0), 1) 
                        
                        frame = cv2.putText(frame, f'{[c]} {str(conf)}', (x1, y1), 
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5,(0, 0, 255), 1, cv2.LINE_AA)

        return frame
    except Exception as ex:
           print(ex)

Trying to detect the license plate.

This is the previous code I used for the PyTorch model. how can I change this code for openvino xml and bin file?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • You should just plug OV code in instead of the original framework calls. The basic OV API is what you need and you can find it in the docs at www.openvino.ai You can also have a look at and example which does exactly what you want to do: https://github.com/openvinotoolkit/openvino_notebooks/blob/main/notebooks/216-license-plate-recognition/216-license-plate-recognition.ipynb – tomdol Aug 01 '22 at 22:26

1 Answers1

0

Intel Open Model Zoo has demos that are used to detect license plates. You can refer to these demos for your code logic exploration:

Zul_Intel
  • 66
  • 4