1

In opencv a function takes a mask array as std::vector<char>. another method returns a std::vector<uchar> as a mask.

internally its using the mask to do

if(mask[i])
{

}

now, is there a way to cast std::vector<uchar> to std::vector<char> without having to loop over the array and the if statemetn will still hold?

Poul K. Sørensen
  • 16,950
  • 21
  • 126
  • 283
  • To help your casting part of the question: http://stackoverflow.com/questions/7899838/fastest-way-to-convert-a-stdvector-to-another-stdvector – Benjamin Trent Aug 12 '14 at 21:28
  • 1
    If you want to do it properly, no. If you want to take the risk, and uchar and char are the same size, and the only values are 0 and 1, then you can try `reinterpret_cast&>(mask)` AT YOUR OWN RISK. – Neil Kirk Aug 12 '14 at 21:41
  • 3
    If the performance of the conversion isn't a concern, just writing the code, it's easy to convert. `std::vector v2(v1.begin(), v1.end());` or use `assign` function. – Neil Kirk Aug 12 '14 at 21:45

0 Answers0