所以这个想法是我通过一个矩形窗口从圆柱形相机中记录和拍摄的图像。我们得到的图像是一张矩形图片,但它必须是圆形的。我正在使用OpenCV逐个像素地逐行移动图像,从给定的矩形图片逐行移动到一个圆圈。问题是像素分布根据半径不均匀。您建议使用什么算法使分布更均匀?这是代码:
int main( int argc, char** argv ) {
Mat src = imread( "srcImg.jpg", 1 );
Mat dst = imread( "dstImg.jpg", 1 );
int srcH = src.rows; int srcW = src.cols;
int dstH = dst.rows; int dstW = src.cols;
//convert chamber radius to pixels
double alpha, alpha_double, alpha_triple;
int r = 1500;
double k = 210 / (500 * PI);
int l = 1;
//take pixels from source and arrange them into circles
for (int i = srcH - 1; i > 0; i--) {
for (int j = 1; j <= srcW ; j++) {
alpha = (double) (2 * PI * (r * k + i)) / j;
alpha_double = (double) (2 * PI * ((r + 15) * k + i)) / j;
alpha_triple = alpha_double = (double) (2 * PI * ((r + 30) * k + i)) / j;
int x_new = abs((int) (dstW / 2 - (r * k + i) * cos(alpha)) - 200);
int y_new = abs((int) (dstH / 2 - (3.5*(r * k + i) * sin(alpha))) + 1000);
int x_new_double = abs((int) (dstW / 2 - (r * k + i) * cos(alpha_double)) - 200);
int y_new_double = abs((int) (dstH / 2 - (3.5*(r * k + i) * sin(alpha_double))) + 1000);
int x_new_triple = abs((int) (dstW / 2 - (r * k + i) * cos(alpha_triple)) - 200);
int y_new_triple = abs((int) (dstH / 2 - (3.5*(r * k + i) * sin(alpha_triple))) + 1000);
dst.at<uchar>(x_new, y_new) = src.at<uchar>(srcH - i, srcW - j);
dst.at<uchar>(x_new_double, y_new_double) = src.at<uchar>(srcH - i, srcW - j);
dst.at<uchar>(x_new_triple, y_new_triple) = src.at<uchar>(srcH - i, srcW - j);
}
}
//make dst image grey and show all images
Mat dstGray;
cvtColor(dst, dstGray, CV_RGB2GRAY);
imshow("Source", src);
imshow("Result", dstGray);
waitKey();
return 0;
答案 0 :(得分:0)
这不是一个完整的答案,但我会尝试某种投影映射,而不是手动访问每个像素。必须有一个openCV方式来创建目标形状,然后说:“拍摄我的原始图像并使其适合目标形状”
对于you can see here这样的矩形来说,这是相当微不足道的,但是你在中间的洞让它变得更难。