Ritu Singh
Problem:
To make it simple, I'm working with one contour, which is a very close approximation to a parallelogram. I need to draw a line through the contour such that the line fits under the contour perfectly.
Here's a minimum reproducible example:
Note: imshow() is a function that shows images on Jupyter Notebook - it's implementation is below:
This is what the code produces:
As you can see in the code, I've got the calculations correct for the angle of the line. It is based off of corners in the contour, which I've also labeled on the output image: c1: red, c2: green, c3: blue. The angle is simply found using c2 and c3 (the drawn line is parallel to the line between c2 and c3), and I found the thickness to be the distance between c1 and c2 (perpendicular to the drawn line). However, the line drawn is obviously more thick than it should be.
More interestingly, this issue goes away with a different contour. This is the result of the same code, but with the contour in the comment in the cnt = ... line:
As you can see, this is a much better fit of the contour. How can I consistently draw lines that fill the area as accurately as possible?
Solution:
The distance marked with the straight line is what I needed to find. Here is a calculation for thickness which works:
Suggested blogs:
>Authentication with Vue 3 and Firebase
>Build a minimal API using ASP.NET Core with Android Studio
>Build a minimal ASP.Net Core API with Android Studio for Mac
>Complete guide on Life Cycle of Angular Component
>Complete guide to Perform crud operation in angular using modal popup
>Create a Vue.js application with CLI Services