#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 Files\opencv_build11\install\include\opencv2\gpu\gpu.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直线
最新推荐文章于 2023-09-11 09:11:53 发布