垂钓检测模型

我要开发同款
匿名用户2024年07月31日
28阅读
所属分类aipytorch
开源地址https://modelscope.cn/models/copperfield/cv_tinynas_fishing-dectection_damoyalo
授权协议Apache License 2.0

作品详情

该模型当前使用的是默认介绍模版,处于“预发布”阶段,页面仅限所有者可见。
请根据模型贡献文档说明,及时完善模型卡片内容。ModelScope平台将在模型卡片完善后展示。谢谢您的理解。

Clone with HTTP

 git clone https://www.modelscope.cn/copperfield/cv_tinynas_fishing-dectection_damoyalo.git

推理代码

from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
import cv2
import numpy as np
import os

# Initialize the object detection pipeline
object_detect = pipeline(Tasks.image_object_detection, model='copperfield/cv_tinynas_fishing-dectection_damoyalo')

# Directory paths
input_dir = './test'
output_dir = './test_res'

# Create the output directory if it doesn't exist
if not os.path.exists(output_dir):
    os.makedirs(output_dir)

# Process each image in the input directory
for filename in os.listdir(input_dir):
    if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
        img_path = os.path.join(input_dir, filename)

        # Perform object detection
        result = object_detect(img_path)
        image = cv2.imread(img_path)

        # Parse detection results
        scores = result['scores']
        labels = result['labels']
        boxes = result['boxes']

        # Draw bounding boxes and labels
        for i in range(len(boxes)):
            box = boxes[i]
            label = labels[i]
            score = scores[i]

            # Extract bounding box coordinates
            x_min, y_min, x_max, y_max = box.astype(np.int32)

            # Draw the bounding box
            cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (0, 255, 0), 2)

            # Label and confidence
            label_text = f'{label}: {score:.2f}'
            cv2.putText(image, label_text, (x_min, y_min - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)

        # Save the processed image
        output_img_path = os.path.join(output_dir, filename)
        cv2.imwrite(output_img_path, image)
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论