这个为最简单的单条光条的重心法检测。分别针对两种摆放形式的光条,分为行检测与列检侧。
针对硬件的图像像素点顺序读取的方式,行检测的代码更为合适。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)