【发布时间】:2019-06-14 16:19:36
【问题描述】:
我在 C++ 中使用 OpenCV 和 Qt 旋转图像函数时遇到问题。 它有点像他的工作,但没有像预期的那样,除了灰度之外,图像的一部分似乎在右上角重复。
之前
之后
void ImgProcessing::rotate(cv::Mat &img, cv::Mat &tmp, int angle){
float rads = angle*3.1415926/180.0;
float cs = cos(-rads);
float ss = sin(-rads);
float xcenter = (float)(img.cols)/2.0;
float ycenter = (float)(img.rows)/2.0;
for(int i = 0; i < img.rows; i++)
for(int j = 0; j < img.cols; j++){
int rorig = ycenter + ((float)(i)-ycenter)*cs - ((float)(j)-xcenter)*ss;
int corig = xcenter + ((float)(i)-ycenter)*ss + ((float)(j)-xcenter)*cs;
int pixel = 0;
if (rorig >= 0 && rorig < img.rows && corig >= 0 && corig < img.cols) {
tmp.at<int>(i ,j) = img.at<int>(rorig, corig);
}else tmp.at<int>(i ,j) = 0;
}
}
问题可能在于访问图像像素吗?
【问题讨论】:
-
如果您使用的是 OpenCV,为什么不使用 OpenCV's builtin functionality 呢?效率会高很多。
img.at<>函数效率不高。 -
知道,但该项目将由我的教授审查,所以我自己实现所有线性和非线性转换,因为我们同意使用 opencv 来读取和保存图像矩阵.
标签: c++ image opencv image-processing