c++ - 图像旋转给出灰度图像

标签 c++ image opencv image-processing

我在 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;
        }

}

问题可能出在访问图像像素上吗?

最佳答案

这取决于您如何阅读图像,但我认为您访问图像的方式不正确。它应该是这样的:

Vec3b intensity = image.at<Vec3b>(j, i);

关于c++ - 图像旋转给出灰度图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56601966/

相关文章:

c++ - OpenCV cpp 运动检测

python-3.x - 通过网络将数据并行发送到多个接收者

c++ - QTcpSocket 或 QSslSocket 是否自动创建读/写线程?

c++ - Windows 消息异常

java - Android 中循环随机图像

c++ - 如何从 OpenCV C++ 中的图像中裁剪特定的矩形部分(ROI)

c++ - 在 SDL 中渲染带正方形的二维数组

c++ - fatal error LNK1169 : one or more multiply defined symbols found in game programming

swift - 图像变化取决于 UISlider 值

python - HED 算法中检测大颗粒和小颗粒的替代方法