Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Matrix constructor width/height reversed. #30

gluxon opened this Issue · 7 comments

2 participants


Documentation defines this.

new Matrix(width, height)

In my tests, this was incorrect. The width and height are reversed. I came across this in the Contours.js demo while using a rectangle image.

new Matrix(height, width)

Judging by how width is commonly before height in most applications, the code to handle this input is reversed?


I took a look at the source - we're just using the default opencv constructor format, so not sure how they could be reversed unless opencv does it the other way - see:


Are you able to confirm that the Contours.js output is reversed compared to the original dimensions? Something doesn't seem right.


Yeah, cv::Mat takes rows (height), then columns (width). So the the code you just referenced to should have the cv::Mat arguments swapped.


You're totally right. Although you make a good point that this is the opposite way for most applications, I think I'd prefer to keep it this way round so it's consistent with the opencv constructor, and just update the documentation to make it clear that this is the case.

I'll take a stab at clarifying this - thanks for catching this!


This makes sense if we look at the cv::Mat as a matrix in mathematics. We should probably start calling it rows and cols in this case then.


Wait, it's rows, then cols. Code is right and should act as intended though.


Ah, got it, that makes sense, I'll switch them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.