7、C++版本图像畸变校正

本文介绍了一段C++代码,该代码用于处理图像,包括读取图像数据、进行透视变换以校正图像,并保存处理后的图像。此外,还涉及了图像类型判断和数据拷贝等基本操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当使用python验证了原理,同时获取了校正的角点参数,则可以直接使用C++代码对图像处理,

 

int process_image(unsigned char *imgBuffer, int width, int height, int channels, char* file_name)
{
	int type = 0;

	if (channels == 3) {
		type = CV_8UC3;
	}
	else  if (channels == 1) {
		type = CV_8UC1;
	}
	Mat image_src = Mat(height, width, type);
	memcpy(image_src.data, imgBuffer, width* height*channels);
	
	//vector<Point2f> src_corner;
	//src_corner.push_back(Point2f(0, 190));
	//Point2f src_corner[4] = { Point2f(0, 190), Point2f(800, 200), Point2f(590, 460), Point2f(205, 460) };
	if (src_corner[2].y < 100)
	{
		if (read_config() != 0)
		{
			return -2;
		}
	}

	// TL BL BR BL 
	Point2f dst_corner[4] = { Point2f(0, 0), Point2f(static_cast<float>(m_camera_width), 0), Point2f(static_cast<float>(m_camera_width), static_cast<float>(m_camera_height)), Point2f(0, static_cast<float>(m_camera_height)) };

	Mat result_image;
	Mat warp_mat = getPerspectiveTransform(src_corner, dst_corner);
	warpPerspective(image_src, result_image, warp_mat, Size(m_camera_width, m_camera_height));

	//string save_file_name = get_date_time_string()+".bmp";
	//strcpy_s(file_name, sizeof(save_file_name), save_file_name.c_str());

	string save_file_name = file_name;

	//Mat normalize_image;
	//normalize(result_image, normalize_image, 255, 0, NORM_MINMAX);


	//Mat equal_image;
	//Mat blur_image;
	//Mat Median_image;
	//Mat bilate_image;
	//vector<Mat> splitRGB(result_image.channels());
	//cv::split(normalize_image, splitRGB);
	//for (auto i = 0; i < result_image.channels(); i++) {
	//	equalizeHist(splitRGB[i], splitRGB[i]);
	//}
	//Mat mergeImage;
	//merge(splitRGB, mergeImage);
	//mergeImage.copyTo(equal_image);
	//equal_image.convertTo(blur_image, -1, 1.5, 150);
	//Mat dstImage;
	//normalize_image.convertTo(dstImage, -1, 1.15,50);


	//draw_for_test(result_image);
	imwrite(save_file_name, result_image);
	return 0;
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值