kadirnar / yolov7-pip

This repo is a packaged version of the Yolov7 model.
MIT License
26 stars 10 forks source link

win32gui #2

Closed Ahmet0691 closed 1 year ago

Ahmet0691 commented 1 year ago

Hello, I want to use win32gui to open the window of an application and read the data in that window using yolov7. Of course, it is possible to do this with yolov3, but you know that yolov7 is faster. How do I write code that only detects, without saving images, what I want to do? I think this is a somewhat more difficult question. Also, is it possible for me to get the x0, x1, x2, x3 coordinates of the rectangle of the detected image in another code for further processing? Thank you very much.

kadirnar commented 1 year ago

Hello @Ahmet0691

I don't know the Win32gui application. I didn't quite understand what you wanted to do. If you want to detect using the yolov7 model, you should use this code.

import yolov7

model_path = "yolov7.pt"
model = yolov7.load(model_path)

# set model parameters
model.conf = 0.25  # NMS confidence threshold
model.iou = 0.45  # NMS IoU threshold
model.classes = None  # (optional list) filter by class

# set images
imgs = 'inference/images' 

# inference with larger input size and test time augmentation
results = model(img, size=1280, augment=True)

# parse results
predictions = results.pred[0]
boxes = predictions[:, :4] # x1, y1, x2, y2
scores = predictions[:, 4]
categories = predictions[:, 5]

You can use win32gui supported visualization code using this information. Or you can visualize it directly with the results.show() code.

Yolov5 Detect and Visualize: Detect: https://github.com/kadirnar/dethub/blob/main/dethub/model.py#L36-L70 Vis: https://github.com/kadirnar/dethub/blob/main/dethub/utils/visualize.py#L254-L294

Yolov7 pip codes and yolov5 pip codes are similar.

Yolov7 Demo: https://huggingface.co/spaces/kadirnar/yolov7