最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Close button not enabled while rendering an image using OpenCV - Stack Overflow

programmeradmin1浏览0评论

I don't see the close button on a Mac machine, but this code works fine on a Windows machine while trying to render the image using OpenCV library on the imshow function.

def detect_objects_in_image(image_path: str):
    frame = cv2.imread(image_path)
    if frame is None:
        typer.echo(f"Error: Unable to load image {image_path}.")
        return

    results = model(frame, imgsz=640, conf=0.5)

    for result in results:
        for box in result.boxes:
            x1, y1, x2, y2 = map(int, box.xyxy[0])
            class_id, confidence = int(box.cls[0]), float(box.conf[0])

            cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
            cv2.putText(frame, f"Class {class_id}: {confidence:.2f}", (x1, y1 - 10),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)

    cv2.imshow("Image Analysis", frame)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
发布评论

评论列表(0)

  1. 暂无评论