Gregor Trplan
Gregor Trplan

Reputation: 33

Confusion about the reshape function in OpenCV

This will be a messy question with a lot of code but you need the context in order to understand the problem.
So I am starting to learn OpenCV and I ran into a problem with understanding something. The code works perfectly but I don't know how it works. So I'm following this post and it is quite good. Just one line at the end of the post confuses me. It's the line number 62. I understand why is the screenCnt multiplied by ratio but what is the purpose of the reshape function there. And what does it really do? I couldn't find documentation that I could understand.
In order to understand my question look at this post too.

Upvotes: 1

Views: 331

Answers (1)

bowo299
bowo299

Reputation: 43

He needs to reshape because screenCnt is an np-array produced by approxPolyDP so it's the transpose a different matrix of what the four_point_transform function accepts as parameter pts. Essentially pts should be a 4x2 matrix and screenCnt is 2x4 so he has to reshape.

edit: I run the commands on a different image and it seems that screenCnt has 4 elements of type [[num1,num2]] whereas pts elements should be [num1,num2]. That's what reshape on that particular case accomplishes. My answer is correct for the general use of the reshape function.

Upvotes: 2

Related Questions