Есть некоторые проблемы с вашим кодом. Как уже указывалось, ваши итерационные переменные go превышают фактические размеры изображения. Не используйте жестко закодированные границы, вместо этого вы можете использовать inputImage.cols
и inputImage.rows
для получения размеров изображения.
Существует переменная (BGR Vec3b), которая установлена, но не используется - Vec3b intensity = image.at<Vec3b>(r,c);
Самое главное, не ясно, чего вы пытаетесь достичь. Линия (uchar)(c, -r + (220)/2);
не дает много информации. Кроме того, в каком направлении вы переворачиваете оригинальное изображение? Ось X или Y?
Вот возможное решение, чтобы перевернуть изображение в направлении X:
//get input image:
cv::Mat testMat = cv::imread( "lena.png" );
//Get the input image size:
int matCols = testMat.cols;
int matRows = testMat.rows;
//prepare the output image:
cv::Mat imageReflectionFinal = cv::Mat::zeros( testMat.size(), testMat.type() );
//the image will be flipped around the x axis, so the "target"
//row will start at the last row of the input image:
int targetRow = matRows-1;
//loop thru the original image, getting the current pixel value:
for( int r = 0; r < matRows; r++ ){
for( int c = 0; c < matCols; c++ ) {
//get the source pixel:
cv::Vec3b sourcePixel = testMat.at<cv::Vec3b>( r , c );
//source and target columns are the same:
int targetCol = c;
//set the target pixel
imageReflectionFinal.at<cv::Vec3b>( targetRow , targetCol ) = sourcePixel;
}
//for every iterated source row, decrease the number of
//target rows, as we are flipping the pixels in the x dimension:
targetRow--;
}
Результат: