opencv绘图调用总结

直线:
    cvLine(img, cvPoint(x1,y1), cvPoint(x2,y2), CV_RGB(0, 0, 0));
    其中img为图像指针,cvPoint为直线的端点,CV_RGB宏为CvScalar结构体的RGB分量赋值,顺序为RGB,cvLine的最后两个参数thickness(直线宽度,默认为1像素)和connectivity(直线反走样模式,默认为8连通)保持默认值。

圆形:
    cvCircle(img, cvPoint(x,y), radius, CV_RGB(0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用OpenCV调用YoloV7模型的基本结构图: 1. 加载YoloV7模型:使用OpenCV的dnn模块加载YoloV7模型的权重文件和配置文件。 2. 准备输入图像:将待识别的图像读入内存,并且进行预处理,如缩放、裁剪等操作。 3. 对输入图像进行推理:将预处理后的图像输入到模型中,进行推理操作,得到目标检测结果。 4. 解析输出结果:将模型输出的结果进行解析,得到检测到的目标的位置、类别、置信度等信息。 5. 绘制检测结果:使用OpenCV绘图函数,将检测结果绘制在原图上,并显示出来。 6. 释放内存:释放使用的内存空间。 下面是一个简单的代码示例: ```python import cv2 # 加载YoloV7模型 net = cv2.dnn.readNetFromDarknet("yolov7.cfg", "yolov7.weights") # 准备输入图像 img = cv2.imread("test.jpg") blob = cv2.dnn.blobFromImage(img, 1/255.0, (416, 416), swapRB=True, crop=False) # 对输入图像进行推理 net.setInput(blob) outputs = net.forward(net.getUnconnectedOutLayersNames()) # 解析输出结果 boxes = [] confidences = [] classIds = [] for output in outputs: for detection in output: scores = detection[5:] classId = np.argmax(scores) confidence = scores[classId] if confidence > confThreshold: box = detection[0:4] * np.array([img.shape[1], img.shape[0], img.shape[1], img.shape[0]]) centerX, centerY, width, height = box.astype("int") x, y = int(centerX - (width / 2)), int(centerY - (height / 2)) boxes.append([x, y, int(width), int(height)]) confidences.append(float(confidence)) classIds.append(classId) # 绘制检测结果 indices = cv2.dnn.NMSBoxes(boxes, confidences, confThreshold, nmsThreshold) for i in indices: i = i[0] box = boxes[i] x, y, w, h = box label = str(classes[classIds[i]]) cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2) cv2.putText(img, label, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) # 显示检测结果 cv2.imshow("Detection result", img) cv2.waitKey(0) # 释放内存 cv2.destroyAllWindows() ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值