0

I have a project where i want to detect a red rectangle marker in my image. For thresholding the color, i will use the CieLAB color space. Because converting the whole image is slow, my approach is to iterate through every pixel in a raster and compare only those pixels to initially find a region.

However, i can't find a way to efficiently convert a single color to a different color space in OpenCV. cvtColor is apparently quite slow with a 1-vector (and the vector feels unnecessary). I could develop my own color conversion algorithm, but i don't think this is trivial regarding border cases and code optimization in c++ (which i am rather new to).

This feels like a very basic thing to me, has anyone done this already?

  • 2
    _"Because converting the whole image is slow, my approach is to iterate through every pixel in a raster... "_ why don't you profile it before making such wierd assumptions? – Miki Feb 19 '19 at 17:57
  • And why cielab [instead of HSV](https://stackoverflow.com/q/32522989/5008845)? – Miki Feb 19 '19 at 18:01
  • @Miki I am getting much better result when thresholding using cielab instead of hsv. The conversion time should be roughly equal – Commodore Yournero Feb 19 '19 at 22:48
  • @Miki what do you mean by 'profile it' ? – Commodore Yournero Feb 19 '19 at 22:49
  • Both answers linked do not answer my question – Commodore Yournero Feb 19 '19 at 22:51
  • 1) ok, using cielab is wierd... but, hey, if it works for you... 2) yes, conversion times should basically the same. 3) I mean "profile your functions, and take decisions only after you know which one is the fastest". OpenCV `cvtColor` on the whole image is very likely to be much faster than your custom function. – Miki Feb 19 '19 at 23:12
  • 4) **Why?** the first one tells you how to convert a single color (You said: _"i can't find a way to efficiently convert a single color to a different color space in OpenCV"_). Just use the code COLOR_BGR2Lab instead of COLOR_BGR2HSV, obviously. The second is a custom implementation of the conversion (you said: _" but i don't think this is trivial regarding border cases"_ and _"has anyone done this already"_) – Miki Feb 19 '19 at 23:13
  • 'OpenCV cvtColor on the whole image is very likely to be much faster than your custom function' that is exactly why i am asking. So your answer would be: this is not possible using OpenCV and has to be done with a custom function in c++ – Commodore Yournero Feb 20 '19 at 10:42
  • @Miki i don't know if you're interested, but what i ended up doing is creating a small Mat containing all pixels from the grid (direct relation, not interpolating anything) and convert that one to LAB, which actually is really fast – Commodore Yournero Feb 21 '19 at 13:33

0 Answers0