基于hls格式的光条检测纯c++代码——重心法
这个为最简单的单条光条的重心法检测。分别针对两种摆放形式的光条,分为行检测与列检侧。
针对硬件的图像像素点顺序读取的方式,行检测的代码更为合适。hls的代码后续放出。
目录:
1、以硬件思想的列检测c++代码
2、以硬件思想的行检测c++代码
3、hls代码
原图:
1、列检测
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
//#include <vector>
#include <windows.h>
#include <opencv2\opencv.hpp>
#include <opencv2\core\core.hpp>
//#include <opencv2\nonfree\features2d.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
//#include <opencv2\gpu\gpu.hpp>
#include <fstream>
using namespace cv;
using namespace std;namespace cv
{using std::vector;
}int main()
{Mat srcimg;//srcimg = imread("C:\\Users\\健尔\\Desktop\\Project1\\image.jpg");srcimg = imread("C:\\Users\\健尔\\Desktop\\1.png");Mat grayimg;cvtColor(srcimg, grayimg, CV_BGR2GRAY);GaussianBlur(grayimg, grayimg, Size(0, 0), 6, 6);//遍历每一列//int vector1 [ 783 * 443];//int vector_num = 0;float x0 = 0;for (int i = 0; i < grayimg.cols; i++) {float sum_value = 0;float sum_valuecoor = 0;float current_value[443];float current_coordinat[443];int vector_num = 0;// vector<float>current_value;// vector<float>current_coordinat;for (int j = 0; j < grayimg.rows; j++) {// cout << grayimg.rows;float current = grayimg.at<uchar>(j, i);//将符合阈值的点灰度值和坐标存入数组if (current > 30) {current_value[vector_num]= current;current_coordinat[vector_num]= j;vector_num++;}}//计算灰度重心for (int k = 0; k < vector_num; k++) {sum_valuecoor += current_value[k] * current_coordinat[k];sum_value += current_value[k];}/*for (int k = 0; k < current_value.size(); k++) {sum_valuecoor += current_value[k] * current_coordinat[k];sum_value += current_value[k];}*/float x = sum_valuecoor / sum_value;x0 = x;//circle(srcimg, Point(i, x), 1, Scalar(0, 0, 255), -1, 8);circle(srcimg, Point(i, x), 1, Scalar(0, 0, 255));// cout << "i" << i << "y" << y << endl;/*current_value.clear();current_coordinat.clear();*/string src;src = "src" + i;/*if (i % 100 == 0)imshow(src, srcimg);*/}imshow("srcimg", srcimg);waitKey(0);
}
2、行检测
结果图:
代码:
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
//#include <vector>
#include <windows.h>
#include <opencv2\opencv.hpp>
#include <opencv2\core\core.hpp>
//#include <opencv2\nonfree\features2d.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
//#include <opencv2\gpu\gpu.hpp>
#include <fstream>
using namespace cv;
using namespace std;namespace cv
{using std::vector;
}int main()
{Mat srcimg;//srcimg = imread("C:\\Users\\健尔\\Desktop\\Project1\\image.jpg");srcimg = imread("C:\\Users\\健尔\\Desktop\\3.png");Mat grayimg;cvtColor(srcimg, grayimg, CV_BGR2GRAY);GaussianBlur(grayimg, grayimg, Size(0, 0), 6, 6);//遍历每一列//int vector1 [ 783 * 443];//int vector_num = 0;float x0 = 0;for (int i = 0; i < grayimg.rows; i++) {float sum_value = 0;float sum_valuecoor = 0;float current_value[783];float current_coordinat[783];int vector_num = 0;// vector<float>current_value;// vector<float>current_coordinat;for (int j = 0; j < grayimg.cols; j++) {// cout << grayimg.rows;float current = grayimg.at<uchar>(i, j);//将符合阈值的点灰度值和坐标存入数组if (current > 30) {current_value[vector_num] = current;current_coordinat[vector_num] = j;vector_num++;}}//计算灰度重心for (int k = 0; k < vector_num; k++) {sum_valuecoor += current_value[k] * current_coordinat[k];sum_value += current_value[k];}/*for (int k = 0; k < current_value.size(); k++) {sum_valuecoor += current_value[k] * current_coordinat[k];sum_value += current_value[k];}*/float x = sum_valuecoor / sum_value;x0 = x;//circle(srcimg, Point(i, x), 1, Scalar(0, 0, 255), -1, 8);circle(srcimg, Point(x,i), 1, Scalar(0, 0, 255));// cout << "i" << i << "y" << y << endl;/*current_value.clear();current_coordinat.clear();*/string src;src = "src" + i;/*if (i % 100 == 0)imshow(src, srcimg);*/}imshow("srcimg", srcimg);waitKey(0);
}
hls代码:
https://github.com/wje36/hls_-
性能以及资源利用
基于hls格式的光条检测纯c++代码——重心法相关推荐
- 基于HLS格式的低延时互动直播技术
在不牺牲服务质量(卡顿率.画面清晰度)的前提下,越低的延时能带来越好的互动性用户体验.为达成可扩展性.服务质量.互动性的三赢,Twitch团队研发了基于HLS格式的低延时互动直播技术.本文来自Twit ...
- OpenFace库(Tadas Baltrusaitis)中基于Haar Cascade Classifiers进行人脸检测的测试代码
Tadas Baltrusaitis的OpenFace是一个开源的面部行为分析工具,它的源码可以从 https://github.com/TadasBaltrusaitis/OpenFace 下载.O ...
- OpenFace库(Tadas Baltrusaitis)中基于HOG进行正脸人脸检测的测试代码
Tadas Baltrusaitis的OpenFace是一个开源的面部行为分析工具,它的源码可以从https://github.com/TadasBaltrusaitis/OpenFace下载.Ope ...
- 【图像检测】基于Itti模型实现图像显著性检测附matlab代码
1 简介 视觉显著性计算模型以心理学.神经科学.认知理论等领域的研究成果或假说为前提,建立数学模型来模拟人类视觉系统指引注意力分配和视觉认知的过程,通过模拟和仿真人类视觉感知机理,将存在待检测目标的人 ...
- 独家 | 基于NLP的COVID-19虚假新闻检测(附代码)
作者:Susan Li 翻译:杨毅远 校对:吴金笛 本文长度为4400字,建议阅读8分钟 本文为大家介绍了基于自然语言处理的COVID-19虚假新闻检测方法以及可视化方法,并结合真实的新闻数据集与完整 ...
- 光流 | 基于光流的实时运动物体检测(MATLAB代码)
===================================================== github:https://github.com/MichaelBeechan CSDN: ...
- 【信号处理】基于蚁群优化随机共振检测附matlab代码
1 内容介绍 信号检测在机械故障诊断领域有着广泛应用.由于该领域的背景噪声很强,而待检信号非常微弱,检测出有效信号非常困难.传统的信号检测方法主要有相关检测.高阶谱分析.经验模态分解和卡尔曼滤波等.这 ...
- 【显著性检测】基于HC算法实现图像显著性检测附MATLAB代码
1 简介 图像融合是一种重要的增强图像信息的技术方法,如何对同一目标的多源遥感图像数据进行有效的融合,最大限度地利用多源遥感数据中的有用信息,提高系统的正确识别.判断和决策能力,这是遥感数据融合研究的 ...
- 【图像检测】基于AC算法实现图像显著性检测附matlab代码
1 简介 AC算法也是Achanta等提出的,与FT算法类似,只是在求欧式距离时使用的均值不再是整幅图像的均值,而是选取不同大小邻域内的均值(三种大小)分别求取欧式距离,再相加得到. 2 部分代码 ...
最新文章
- Cell Reports:中科院动物所魏辅文组解析大熊猫肠道菌群季节性变化的功能
- Filter过滤不了Action的问题
- SQL Server:向 SQL Server 自增字段插入值 (转)
- disconf-自动注入属性变化
- ionic4页面常用判断
- 计算机毕业设计ssm电影院售票系统java项目mysql数据库
- ANC降噪蓝牙耳机软件工程的数学原理
- 重邮第八届ACM大赛-预赛题解报告
- 跟着团子学SAP PS:项目计划成本与项目预算设计思路
- CWnd与CDialog-DoModal与ShowWindow区别
- 多种代码生成炫酷代码雨(推荐)
- html小游戏——看你有多色
- OOP Class具体解释
- Ubuntu安装常用Linux桌面系统
- 初创公司股权结构应该怎么设计?举例三种模型
- 虚拟机解压.rar文件
- Android实现按住缩小 松开放大的效果
- LeeCode1715. 苹果和橘子的个数
- 7-5小组日报 最终版的发布
- 解决某些软件无法在虚拟机中运行的方法