M
M
Matweytt2019-06-17 20:34:40
Python
Matweytt, 2019-06-17 20:34:40

Cropping an image by 3 points opencv?

There is an image, there are 3 points, how can you crop by 3 points, exactly with a triangle and not with a rectangle? And then find the most frequently occurring pixel color

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rPman, 2019-06-17
@rPman

Walk pixel by pixel over the area inside the triangle.
This is how they do it for the entire image, it remains to replace two nested loops over all points in it with the points of the triangle.
About a triangle, look for an algorithm for pixel-by-pixel filling of a triangle or write it yourself, to pixelate a line, take Bresenham's algorithm

F
f4f, 2019-06-24
@f4f

You can only cut a rectangular ROI.
However, it is possible to cut out a rectangular ROI that will describe the desired triangle. And using the cv2.fillConvexPoly() function, fill the extra parts of the image with black (0, 0, 0). When determining the average color, it is important to take into account the number of pixels in the triangle, and not everything in the rectangular ROI.
rPman's solution is basically the same.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question