E
E
Evgeny_A2020-03-21 22:37:06
Python
Evgeny_A, 2020-03-21 22:37:06

How to "colorize" a part of a picture using OpenCV?

Hello!

There is such a picture:

5e766bcc740aa648560514.png
I use my algorithm to align the pictures. Rotation can be clockwise or counterclockwise. The center of the picture and the center of rotation always converge. The result is:

5e766c08d1e8e489668056.png
Question: how to use OpenCV to tile the black areas that appear at the corners (which are always 0,0,0) so that it looks "native"?

I wrote nested loops that go through the image pixel by pixel and if the color of the pixel == (0,0,0), then the nearest pixel is searched != (0,0,0) and this color is applied to the selected pixel. The problem is that it works very slowly, and there is not enough imagination to come up with an alternative solution.

Tell me ideas or directions on how to paint over the corners as natively as possible from a human point of view.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2020-03-21
@xmoonlight

No way.
Crop through the gaps, using the maximum height of the black corners in the corners of the resulting image after rotation.
Those. cut around the perimeter of all black areas that are not included in the maximum possible central rectangular area.

U
U235U235, 2020-04-05
@U235U235

Yes, it's easy, when rotating through warpAffine, set BorderTypes to the desired type.
For example:
cv.warpAffine(src, dst, M, dsize, cv.INTER_LINEAR, cv.BORDER_REFLECT , new cv.Scalar());
Here you can practice on Lena:
https://docs.opencv.org/3.4/dd/d52/tutorial_js_geo...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question