码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-12-10 21:22:38      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:opencv2   计算机视觉   图片   lines   

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;
}


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

标签:opencv2   计算机视觉   图片   lines   

原文地址:http://blog.csdn.net/hanshuning/article/details/41849567

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!