opencv 识别机车

效果1 识别摩托

摩托识别

效果 公路场景撞击现场

公路场景撞击现场

定义识别名称

const char* classNames[] = { “背景”,
“飞机”, “自行车”, “鸟”, “船”,
“瓶子”, “大汽车”, “小汽车”, “猫”, “椅子”,
“奶牛”, “餐桌”, “狗”, “马”,
“机车”, “人”, “花盆植物”,
“羊”, “沙发”, “火车”, “tv监视器” };

    String file_path = parser.getPathToApplication() + "/"; 
	String modelConfiguration = file_path + "xx.prototxt";
	String modelBinary = file_path + "model.caffemodel";
	try
	{
      //加载深度神经网络模型
		dnn::Net net = readNetFromCaffe(modelConfiguration, modelBinary);
		if (net.empty())
		{
			cerr << "Can't load network by using the following files: " << endl;
			cerr << "prototxt:   " << modelConfiguration << endl;
			cerr << "caffemodel: " << modelBinary << endl;
			cerr << "Models can be downloaded here:" << endl;
			cerr << "https://github.com/chuanqi305/MobileNet-SSD" << endl;
			exit(-1);
		}
		net.setPreferableTarget(DNN_TARGET_OPENCL);

//定义图片,也可以从rtsp摄像头读取后 解码放到mat中,具体看我文章
rtsp读取摄像头进行算法识别

string image_file_name = "J:/bbbbb.jpg";
cv::Mat frame = cv::imread(image_file_name, CV_LOAD_IMAGE_COLOR);

判别过程

			Mat inputBlob = blobFromImage(frame, inScaleFactor,
				Size(inWidth, inHeight),
				Scalar(meanVal, meanVal, meanVal),
				false, false); //Convert Mat to batch of images


			net.setInput(inputBlob); //set the network input
			Mat detection = net.forward(); //compute output

			vector<double> layersTimings;
			double freq = getTickFrequency() / 1000;
			double time = net.getPerfProfile(layersTimings) / freq;

			Mat detectionMat(detection.size[2], detection.size[3], CV_32F, detection.ptr<float>());
			float confidenceThreshold = 0.5;// parser.get<float>("min_confidence");
			for (int i = 0; i < detectionMat.rows; i++)
			{
				float confidence = detectionMat.at<float>(i, 2);

				if (confidence > confidenceThreshold)
				{
					size_t objectClass = (size_t)(detectionMat.at<float>(i, 1));

					int left = static_cast<int>(detectionMat.at<float>(i, 3) * frame.cols);
					int top = static_cast<int>(detectionMat.at<float>(i, 4) * frame.rows);
					int right = static_cast<int>(detectionMat.at<float>(i, 5) * frame.cols);
					int bottom = static_cast<int>(detectionMat.at<float>(i, 6) * frame.rows);

					rectangle(frame, Point(left, top), Point(right, bottom), Scalar(0, 255, 0),2);
					String label = format("%s: %.2f", classNames[objectClass], confidence);
					int baseLine = 0;
					Size labelSize = getTextSize(label, FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
					top = max(top, labelSize.height);
					rectangle(frame, Point(left, top - labelSize.height),
						Point(left + labelSize.width, top + baseLine+2),
						Scalar(0, 0, 255),FILLED);
					
					putTextZH(frame, label.c_str(), Point(left, top), Scalar(255, 255, 255), 18);
					/*putText(frame, label, Point(left, top),
						FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 0, 0));*/
				}
			}

以上使用opencv3.4.1 win7 win10 调试通过,在linux下面都是一样的过程,整个的

训练过程描述

可以使用多种方式,一种是yolo,一种是tensorflow模式训练模型,比较难的是逻辑模型,也就是行为识别,没有好的显卡很难做,这里没有写真正的详细过程,后续文章会写两种模式来训练模型。请关注我.

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qianbo_insist

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值