概述
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <cv.h>
//#include "d:Program Filesopencv_build11installincludeopencv2gpugpu.hpp"
using namespace cv;
#define ROI_rows 178
#define ROI_cols 100
int main (int argc, char* argv[])
{ // CvCapture *Frame=cvCaptureFromCAM(-1);
VideoCapture cap("Load.avi");
if(!cap.isOpened())
return -1;
cv::Mat Image_frame,Lines_out;
//Mat element = getStructuringElement(MORPH_RECT, Size(15, 15));
while (1)
{ cap>>Image_frame;
// imshow("Cam",Image_frame);
// cv::Mat Image = cv::imread("load.jpg" );
cv::Mat ROI_Mat=Image_frame(Rect(ROI_cols,376-ROI_rows,672-2*ROI_cols,ROI_rows));
cv::Mat copy_mat(ROI_Mat);
cv::gpu::GpuMat Image_Src,Image_Dst,Lins ;
Image_Src.upload (ROI_Mat);
cv::gpu::cvtColor(Image_Src,Image_Dst,CV_BGR2GRAY);
// cv::erode(Image_Dst,Image_Dst,element);
// cv::gpu::Canny(Image_Dst,Image_Dst,120,255);
cv::gpu::Sobel(Image_Dst,Image_Dst,CV_8U,1,1);
vector<Vec2f> lines1;
//show line
cv::gpu::HoughLines(Image_Dst,Lins,1,CV_PI/180,50,1,5); //5 line long 7number of line
cv::gpu::HoughLinesDownload(Lins,lines1);
std::cout<<"Lines_out"<<lines1.size()<<std::endl;
for( int i = 0; i < lines1.size(); i++ )
{
float rho = lines1[i][0], theta = lines1[i][1];
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
line( copy_mat, pt1, pt2, Scalar(55,100,195), 1, CV_AA);
}
cv::Mat Image_sobel(Image_Dst);
std::cout<<"宽"<<Image_sobel.cols <<std::endl;
std::cout<<"高"<<Image_sobel.rows <<std::endl;
rectangle( Image_frame,cvPoint(ROI_cols,376-ROI_rows),cvPoint(672-ROI_cols,376),cvScalar(0,0255),1);
//show Image
cv::imshow("Sobel",Image_sobel);
cv::imshow("源图像",Image_frame);
cv::waitKey(5);
}
最后
以上就是温柔往事为你收集整理的opencv GPU HoughLines直线的全部内容,希望文章能够帮你解决opencv GPU HoughLines直线所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复