0
点赞
收藏
分享

微信扫一扫

学习opencv第11章图像变换部分习题

认真的老去 2022-04-14 阅读 80
c++opencv

最近一直在看深度学习,不能荒废cv,这两天啃完了图像变换部分的知识。

11-1脸上找瞳孔,提示用拉普拉斯算法。用完效果还是不理想,目前没想到办法。等学成在回头来看看吧

//查找眼睛,根据提示使用拉普拉斯算法
	Mat src = imread("D:\\编程\\opencv\\opencv\\opencv\\sources\\samples\\data\\VX_work.png");//读取opencv自带的图像库中截取经典lena脸
	Mat dst_lap,dst_sobel_x,src_gray;
	CV_Assert(src_gray.depth() == CV_8U);
	cvtColor(src, src_gray, COLOR_BGR2GRAY);//转为灰度图
	Laplacian(src_gray, dst_lap, CV_16S,3);//拉普拉斯变换求导
	convertScaleAbs(dst_lap, dst_lap);
	//Sobel(src_gray, dst_sobel_x, CV_16S, 1, 1);
	//convertScaleAbs(dst_sobel_x, dst_sobel_x);//转回uint8图像
	//morphologyEx(dst, dst, MORPH_OPEN, cv::Mat());
	namedWindow("raw");
	imshow("raw", src);
	namedWindow("test", 0);
	imshow("test", dst_lap);
	waitKey(0);

                            

 11-2

1)将正方形一个角作为对数极点,绘制对数极坐标结果

Mat src = Mat::zeros(500, 500, CV_8UC1), dst;
	//绘制正方形
	for (int i = 200; i < 400; i++)
	{
		src.at<uchar>(200, i) = 255;
		src.at<uchar>(400, i) = 255;
		src.at<uchar>(i, 200) = 255;
		src.at<uchar>(i, 400) = 255;

	}
	logPolar(src, dst, Point2f(200, 200), 500, INTER_LINEAR | WARP_FILL_OUTLIERS);
	namedWindow("rect");
	imshow("rect", src);
	namedWindow("logpolar",0);
	imshow("logpolar", dst);
	waitKey(0);

 

结果

  

 

 2)将接近圆圈边界内一点作为对数极点,绘制对数极坐标结果

3)将接近圆圈边界外一点作为对数极点,绘制对数极坐标结果

Mat src = Mat::zeros(500, 500, CV_8UC1),dst;
	circle(src, Point(250, 250), 50, Scalar(255, 255, 255));
	logPolar(src, dst, Point2f(201, 250), 100, INTER_LINEAR | WARP_FILL_OUTLIERS);
	namedWindow("circle");
	imshow("circle", src);
	namedWindow("in_logpolar");
	imshow("in_logpolar", dst);
	logPolar(src, dst, Point2f(199, 250), 100, INTER_LINEAR | WARP_FILL_OUTLIERS);
	namedWindow("out_logpolar");
	imshow("out_logpolar", dst);
    waitKey(0);

               结果                                        圆圈内作为极点                              圆圈外作为极点

           

 11-3太深奥,才疏学浅不会

 11-4前面课本有例子

 11-5载入一张图像,进行透视变换。注意与仿射变换变化(可以想象成平行四边形被各种蹂躏,但是不能扭曲变弯)

Mat src = imread("D:\\编程\\opencv\\opencv\\opencv\\sources\\samples\\data\\flower.jpg"),dst;
	int height = src.size[0];
	int weigh = src.size[1];
	//获取透视映射矩阵
	Point2f src_p[4] = { Point2f(0, 0),Point2f(height, weigh), Point2f(0,weigh),Point2f(height, 0) };
	Point2f dst_p[4] = { Point2f(0, 0),Point2f(height, weigh), Point2f(0,weigh/2),Point2f(height/1.5, 0) };
	Mat mtx = getPerspectiveTransform(src_p, dst_p);
	//透视变换
	warpPerspective(src,dst,mtx,src.size());
	namedWindow("raw");
	imshow("raw", src);
	namedWindow("perspect");
	imshow("perspect", dst);
	waitKey(0);

           

 11-6估计会模糊边缘

 11-7图像均值化

Mat src = imread("D:\\编程\\opencv\\opencv\\opencv\\sources\\samples\\data\\text_defocus.jpg"), dst;
	cvtColor(src, src, COLOR_BGR2GRAY);
	equalizeHist(src, dst);
	namedWindow("raw");
	imshow("raw", src);
	namedWindow("hist");
	imshow("hist", dst);
	waitKey(0);

结果

              

 

 

举报

相关推荐

0 条评论