当前位置: 首页 > news >正文

C++调用SSD caffe模型进行物体检测-Opencv3.4.3

本文参考:https://blog.csdn.net/hunzhangzui9837/article/details/82837873

源代码

#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include <iostream>using namespace cv;
using namespace cv::dnn;
using namespace std;const size_t width = 300;
const size_t height = 300;
const float meanVal = 127.5;
const float scaleFactor = 0.007843f;
const char* classNames[] = { "background",
"aeroplane", "bicycle", "bird", "boat",
"bottle", "bus", "car", "cat", "chair",
"cow", "diningtable", "dog", "horse",
"motorbike", "person", "pottedplant",
"sheep", "sofa", "train", "tvmonitor" };String modelFile = "C:/Users/18301/Desktop/models_VGGNet_VOC0712Plus_SSD_300x300/models/VGGNet/VOC0712Plus/SSD_300x300/VGG_VOC0712Plus_SSD_300x300_iter_240000.caffemodel";
String model_text_file = "C:/Users/18301/Desktop/models_VGGNet_VOC0712Plus_SSD_300x300/models/VGGNet/VOC0712Plus/SSD_300x300/deploy.prototxt";int main() 
{VideoCapture capture;capture.open(0);namedWindow("input", CV_WINDOW_AUTOSIZE);int w = capture.get(CAP_PROP_FRAME_WIDTH);int h = capture.get(CAP_PROP_FRAME_HEIGHT);printf("frame width : %d, frame height : %d", w, h);// set up netNet net = readNetFromCaffe(model_text_file, modelFile);Mat frame;//while (capture.read(frame)) //注意:这里提供了两种模式,调用摄像头的时候把该句取消注释即可while (1){frame = imread("C:/Users/18301/Desktop/car.jpg");imshow("input", frame);//预测Mat inputblob = blobFromImage(frame, scaleFactor, Size(width, height), meanVal, false);net.setInput(inputblob, "data");Mat detection = net.forward("detection_out");//检测Mat detectionMat(detection.size[2], detection.size[3], CV_32F, detection.ptr<float>());float confidence_threshold = 0.3;for (int i = 0; i < detectionMat.rows; i++) {float confidence = detectionMat.at<float>(i, 2);if (confidence > confidence_threshold) {size_t objIndex = (size_t)(detectionMat.at<float>(i, 1));float tl_x = detectionMat.at<float>(i, 3) * frame.cols;float tl_y = detectionMat.at<float>(i, 4) * frame.rows;float br_x = detectionMat.at<float>(i, 5) * frame.cols;float br_y = detectionMat.at<float>(i, 6) * frame.rows;Rect object_box((int)tl_x, (int)tl_y, (int)(br_x - tl_x), (int)(br_y - tl_y));rectangle(frame, object_box, Scalar(0, 0, 255), 2, 8, 0);putText(frame, format("%s", classNames[objIndex]), Point(tl_x, tl_y), FONT_HERSHEY_SIMPLEX, 1.0, Scalar(255, 0, 0), 2);}}imshow("ssd-video-demo", frame);char c = waitKey(5);if (c == 27) { // ESC退出break;}}capture.release();waitKey(0);return 0;
}

实验结果

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

不过说实话效果不是太好,因为这个SSD模型是基于VGG16的,可能特征表征能力不是太强吧~视频检测就更差了,就不展示了。

实验中的模型链接:SSD Caffe模型


http://www.taodudu.cc/news/show-1782121.html

相关文章:

  • 【physx/wasm】在physx中添加自定义接口并重新编译wasm
  • excel---常用操作
  • Lora训练Windows[笔记]
  • linux基础指令讲解(ls、pwd、cd、touch、mkdir)
  • InnoDB 事务处理机制
  • 启明云端ESP32 C3 模组WT32C3通过 MQTT 连接 AWS
  • C++调用tensorflow训练好的SSD物体检测模型-opencv3.4.3
  • C++调用mask rcnn进行实时检测--opencv4.0
  • tensorflow线下训练SSD深度学习物体检测模型,C++线上调用模型进行识别定位(干货满满)
  • python训练Faster RCNNC++调用训练好的模型进行物体检测-基于opencv3.4.3(超详细)
  • mask rcnn数据转换为tfrecord数据
  • opencv3.4.2调用训练好的Openpose模型
  • python训练mask rcnn模型C++调用训练好的模型--基于opencv4.0(干货满满)
  • leetcode之移除链表的元素
  • leetcode之奇偶链表
  • leetcode之回文链表
  • ubuntu16.04下安装配置caffe2和detectron(亲测有效,非常简单)
  • leetcode之字符串中的第一个唯一字符
  • 哈希表中处理冲突的方法
  • SENet算法解析
  • SNIP物体检测算法理解
  • yolov3聚类自己数据的anchor box
  • Ubuntu下安装qt57creator-plugin-ros,在QT中进行ROS开发(亲测有效)
  • ROS下面调用自定义的头文件和.cpp/.so文件(亲测有效)
  • C++调用编译好的darknet来进行物体监测
  • hard-negative mining详细介绍
  • yolov3中如何进行聚类得到anchor box的
  • ubuntu16.04下编译安装Autoware
  • catkin_make和cmake
  • 深度学习三种分割定义
  • 基于激光雷达点云数据的目标检测
  • 递归和循环两种方式求解连续数的相加
  • PCL中把txt文件转换成.pcd文件(很简单)
  • pcl对点云进行直通滤波
  • error: (-205:Formats of input arguments do not match) All the matrices must have the same data type
  • ubuntu16.04下Qt无法输入中文注释