opencv库中的水平翻转

时间:2016-10-11 18:10:27

标签: c++ opencv

我有以下问题。我试图进行水平翻转,我的代码正在编译,但之后我有运行时错误。我在下面发布了我的代码,以及发生错误的mat.inl.hpp标题的某些部分。

int HorizontalFlip(Mat img)
{
Mat img4 = img.clone();
for (int i = 0; i < img4.rows; i++)
{
    for (int j = 0; j < ceil(img4.cols / 2); j++)
    {
        Vec3b &intensity = img4.at<Vec3b>(i, j);
        Vec3b &intensity2 = img4.at<Vec3b>(i, img4.cols);
        Vec3b bufor;
        int k = ceil(img4.cols / 2);
        for (int channel = 0; channel < img4.channels(); channel++)
        {
            do 
            {
                bufor = intensity;
                intensity = intensity2;
                intensity2 = bufor;
            } while (ceil(img4.cols / 2) < k);
        }
    }
}
namedWindow("Horizontal Flip", WINDOW_AUTOSIZE);
imshow("Horizontal Flip", img4);
return 0;
}


 CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));

感谢您花时间解决我的问题。

1 个答案:

答案 0 :(得分:2)

Mat img4 = img.clone();
for (int i = 0; i < img4.rows; i++)
{
    for (int j = 0; j < ceil(img4.cols); j++)
    {
        img4.at <cv::Vec3b (i,j) = img.at <cv::Vec3b (i, img.cols-1-j);
    }
}
if (img4.empty ()) return 1;
cv::imshow ("flipped", img4);
cv::waitKey (0);