亚像素算法是一种在像素级别上对图像进行更精确操作的技术。
下面是一个简单的亚像素平移算法示例:
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv)
{
// 读取输入图像
Mat image = imread("image.jpg");
// 定义平移矩阵
Mat translation = (Mat_<float>(2,3) << 1, 0, 0.5, 0, 1, 0.5);
// 应用平移变换
Mat shifted;
warpAffine(image, shifted, translation, image.size(), INTER_LINEAR, BORDER_CONSTANT);
// 显示结果图像
imshow("Shifted image", shifted);
waitKey(0);
return 0;
}
该代码将输入图像向右下方平移 0.5 个像素。要使用其他亚像素算法,请使用 OpenCV 中的相应函数。