can somebody explain how to create a binary mat with values from a bitstring?
For example,
I want to create my Mat from bitstrings 11110000
and 01010101
, so I have a mat object with 2 rows and 1 colum.
For this I initialize the mat-object with Mat mat = new Mat(2,1,CvType.CV_8UC1);
Can I convert these strings to a byte array and use mat.put(0,0,bytearray)
or is there something else that I must conside?
Later I want to use this approach to create my own binary descriptor
that can compare wth other descriptors, extracted by ÒRB
.
With norm(descA,descB,NORM_HAMMING)
thank you and best regards
You can use Byte.parseByte()
with a radix
of 2 e.g byte b = Byte.parseByte(str, 2);
to first convert it to byte
and then create a byte array and then covert it to Mat
object as below:
Mat mat = Imgcodecs.imdecode(new MatOfByte(byteArray), Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);