How to fill borders when rotating images?

I use the following code to rotate images in opencv. However, after that the corners are painted black. I thought when I set borderMode to BORDER_CONSTANT , I can specify the color. But no matter what color I choose (the last parameter), the result is always black.

 cv::Mat rotated; float rotation = 3.0f; cv::warpAffine(img, rotated, rotation, img.size(), cv::INTER_CUBIC, cv::BORDER_CONSTANT, cv::Scalar(1.0, 1.0, 1.0, 0.0)); cv::imshow("rotated", rotated); 

Could someone explain to me what I'm doing wrong here?

I know that after that I could use cv::floodFill , but somehow this can be done using only warpAffine .

+4
source share
1 answer

Have you tried values ​​greater than 1? White should be

 Scalar(255,255,255); 

Blue:

 Scalar(255,0,0); 

And so on.

Values ​​in OpenCV matrices are expressed as uchars (0..255), not (0.0..1.0)

+5
source

Source: https://habr.com/ru/post/1381560/


All Articles