opencv2实现多张图片路线路牌检测_计算机视觉大作业2

linefinder.h同上一篇博文

main.cpp

/*------------------------------------------------------------------------------------------*This file contains material supporting chapter 7 of the cookbook:
Computer Vision Programming using the OpenCV Library.
by Robert Laganiere, Packt Publishing, 2011.

This program is free software; permission is hereby granted to use, copy, modify,
and distribute this source code, or portions thereof, for any purpose, without fee,
subject to the restriction that the copyright notice may not be removed
or altered from any source or altered source distribution.
The software is released on an as-is basis and without any warranties of any kind.
In particular, the software is not guaranteed to be fault-tolerant or free from failure.
The author disclaims all warranties with regard to this software, any use,
and any consequent failure, is purely the responsibility of the user.

Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
\*------------------------------------------------------------------------------------------*/

#include <iostream>
#include <vector>
#include <opencv2/core/core.hpp>
//#include <opencv2/imageproc/imageproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<string>
#include <sstream>
#include "linefinder.h"
//#include "edgedetector.h"

using namespace cv;
using namespace std;
#define PI 3.1415926

int main()
{
	stringstream ss;
    string str;
	for(int i=1;i<=80;i++)
    {
        str="D:\\大学课程\\智能技术2-2\\视觉作业\\视觉作业\\作业2014\\作业2\\";//选择F:\\图片\\中的5张图片
        ss.clear();
        ss<<str;
        ss<<i;
        ss<<".jpg";
        ss>>str;
        Mat image=imread(str,1);
	// Read input image
	//Mat image= imread("1.jpg",1);
	if (!image.data)
		return 0;
	/*namedWindow("Original Image");
	imshow("Original Image",image);*/

	Mat img=image(Rect(0.4*image.cols,0.58*image.rows,0.4*image.cols,0.3*image.rows));
	Mat contours;
	Canny(img,contours,80,100);

	cv::Mat contoursInv;
	cv::threshold(contours,contoursInv,128,255,cv::THRESH_BINARY_INV);

	// Display the image of contours
	/*cv::namedWindow("Canny Contours");
	cv::imshow("Canny Contours",contoursInv);*/

	// Create LineFinder instance
	LineFinder ld;

	// Set probabilistic Hough parameters
	ld.setLineLengthAndGap(80,30);
	ld.setMinVote(30);

	vector<Vec4i> li= ld.findLines(contours);
	ld.drawDetectedLines(img);

	/*namedWindow(" HoughP");
	imshow(" HoughP",img);*/
	/*namedWindow("Detected Lines with HoughP");
	imshow("Detected Lines with HoughP",image);*/

	Mat imgGry;
	cvtColor(image,imgGry,CV_BGR2GRAY);
	GaussianBlur(imgGry,imgGry,Size(5,5),1.5);
	vector<Vec3f> circles;
	HoughCircles(imgGry, circles, CV_HOUGH_GRADIENT,
		2,   // accumulator resolution (size of the image / 2)
		50,  // minimum distance between two circles
		200, // Canny high threshold
		100, // minimum number of votes
		25, 50); // min and max radius

	cout << "Circles: " << circles.size() << endl;

	// Draw the circles

	vector<Vec3f>::const_iterator itc= circles.begin();

	while (itc!=circles.end()) {

		circle(image,
			Point((*itc)[0], (*itc)[1]), // circle centre
			(*itc)[2], // circle radius
			Scalar(255), // color
			2); // thickness

		++itc;
	}

	namedWindow(str);
	imshow(str,image);
	}
	waitKey();
	return 0;
}
时间: 2024-10-26 19:07:48

opencv2实现多张图片路线路牌检测_计算机视觉大作业2的相关文章

opencv2实现路线路牌检测_计算机视觉大作业2终版

main.cpp #include<stdio.h> #include <iostream> #include <vector> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include<string> #include <sstream> #include "linefinder.h" #inclu

opencv2实现单张图片的路线路牌检测_计算机视觉大作业2

有好多代码没有用 linefiner.h #if !defined LINEF #define LINEF #include<cmath> #include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #define PI 3.1415926 class LineFinder { private: // original image cv::Mat img; // vector conta

opencv2实现多张图片路线路牌(直线和圆)检测并将处理后的图片合成视频_计算机视觉大作业2

linefinder.h #if !defined LINEF #define LINEF #include<cmath> #include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #define PI 3.1415926 using namespace cv; using namespace std; class LineFinder { private: // original i

opencv2实现n张图像拼接_stitcher具体之代码2(简化版)_计算机视觉大作业2

#include <iostream> #include <fstream> #include <string> #include "opencv2/opencv_modules.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/stitching/detail/autocalib.hpp" #include "opencv2/

任意n张图像拼接_效果很好_计算机视觉大作业1终版

#include <iostream> #include <fstream> #include <string> #include "opencv2/opencv_modules.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/stitching/detail/autocalib.hpp" #include "opencv2/

opencv2实现人脸眼鼻口检测_不大稳定

#include <opencv2/core/core.hpp> #include <opencv2/highgui//highgui.hpp> #include <opencv2/objdetect/objdetect.hpp> #include <string> #include <vector> using namespace std; int main() { cv::CascadeClassifier mFaceDetector; cv

深度学习与自然语言处理(4)_斯坦福cs224d 大作业测验1与解答

深度学习与自然语言处理(4)_斯坦福cs224d 大作业测验1与解答 作业内容翻译:@胡杨([email protected]) && @胥可([email protected]) 解答与编排:寒小阳 && 龙心尘 时间:2016年6月 出处: http://blog.csdn.net/han_xiaoyang/article/details/51760923 http://blog.csdn.net/longxinchen_ml/article/details/51765

opencv2实现人脸及人眼检测_相当稳定

//opencv2检测人脸人眼的方法有很多,我试了集中,下面的程序得到的结果最准确.人可以随意动,只要摄像头可以,就没有问题. [cpp] view plaincopyprint? /* */ #include "opencv2/objdetect/objdetect.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #includ

C零散_清空缓冲区_错误检测_数字转字符串

1 fflush(stdin) 清空输入缓存区,对于输入类型错误相当有用. 例: 1 int res, i; 2 while ( fflush(stdin), ( res = scanf("%d", i) ) != EOF ) 3 { 4 } 输入之前将输入缓存区清空,所以当将i错输入成字符时,只会影响当次结果,而不会影响下次正确输入的结果. 错误检测函数: 宏定义: 可将val(数字)转化为字符串 1 #define STR(val) #val