9

I'm compiling a program with gcc's -Wall flag. I do a comparison (with an unsigned int) on Mat::cols and Mat::rows at some point and get a warning about comparing signed and unsigned ints. Although it's not a big deal to cast this away, I'm curious as to what the rationale behind a Mat that has a negative size is.

Logically, a matrix can't be any emptier than an empty matrix (with 0 rows and 0 cols), so what would a matrix with -1 rows or -1 cols mean?

There doesn't seem to be much performance difference between computations on signed and unsigned ints either.

Community
  • 1
  • 1
Sveltely
  • 822
  • 1
  • 8
  • 22
  • 4
    I think it is simply a design flaw. A lot of people, including writers of many well-known and large libraries, make not so good use of integer types. Using `int` for all kinds of integers is a common mistake. – Siyuan Ren Mar 14 '14 at 05:16
  • I misunderstood the question, my bad. I thought about values in Mat. Deleting my post. – yutasrobot Mar 14 '14 at 07:45
  • i hate it too that .rows and .cols are signed... just got used to loop over unsigned types for std::vector... – Micka Mar 14 '14 at 10:37
  • I think what vlad said about int loop counters could be a reason. I personally always use size_t as loop counter type. Requires more typing, but is the correct type for sizes and indices – Manu343726 Mar 14 '14 at 11:51

1 Answers1

5

i think because mostly int i is used as loop counter. with uint as cols and rows many warnings will appear. Also bulding differences of dimensions would be a bit more error prone.

beside that. in my opinions OpenCv is not a good example of good design at all. there are dozens of examples of bad class design. Also the design of the generated documentation is terrible (all overloads of a function and its parameters are mixed together for example).

But it is a very comprehensive and good image processing library. and that excuses a lot :)

vlad_tepesch
  • 6,681
  • 1
  • 38
  • 80