Can data from Mat convert to bitset? [closed]

asked 2017-02-15 01:00:25 -0600

zms gravatar image

updated 2017-02-15 01:45:13 -0600

image description I have a binary mat array 20 x 20. I'm doing specific pixel line scanning example at Mat[1][10]. This array will consist a string of example, 11111000000000000000. This string will go through the bitset operation which is to #include <bitset>.

i sample the scan to look on the bit transition on the lane across the image. Because i should have a pattern o this process.

How can i manage to do read the string line from the mat array and complete the bitset operation?

i can read the pixel by pixel using this.

for(int x=0;x< frame_gray.cols;x+=1){
for (int y=0; y< frame_gray.rows; y+=1){
if (frame_gray.at<uchar>(y,x)==0)
{ cnt++; cout << "0 binary=" << cnt << endl;}
else
{  cnt++;cout << "1 binary=" << cnt << endl;width++;}
//waitKey(0);

}

After few question in the forum, i can read the line array but still failed to get the bitset operation to be completed. This is the bitset operation suggested by the team member in this forum. BUt how can i do this?

#include <bitset>
bitset<24> a("00001111100000111100000");
// 000001111100000111100000
auto b = a >> 1;
// 000000111110000011110000
auto c = a ^ b;
// 000001000010000100010000
auto len = c.count();  // popcnt() , if you use integers.
// 4
edit retag flag offensive reopen merge delete

Closed for the following reason too subjective and argumentative by sturkmen
close date 2020-09-28 12:46:19.213591

Comments

rrr, sorry for being confusing, but the bitset was only to demonstrate the general algorithm (can take strings and print out nicely). it should not be used for your "real life" problem (at least, you should not use strings as input). (it also can hold only a single ulong value)

nonetheleess, can you be a bit more specific, what is is your binary Mat, and also, which parts of it you intend to scan ? also, what is the purpose of the whole operation ?

berak gravatar imageberak ( 2017-02-15 01:11:45 -0600 )edit
1

@berak, i have edited the question and the binary image that i'm working right now. I scan every 10th pixel column and to get the times of transition from 0-->1 or 1-->0. Based on the pattern that i can get, i can manage to classify the image.

zms gravatar imagezms ( 2017-02-15 01:49:07 -0600 )edit

so, for a 20x20 image, you would scan 3 times ? (at the left, middle, right) and have 20 bits(pixels) per column ?

berak gravatar imageberak ( 2017-02-15 02:09:11 -0600 )edit

Yes. Would do that, and from the scan output, i would like to proceed to find the binary transition as per suggested using bitset. This is kind of feature which may be used to classify the object in the binary image. Is it still can be done by using bitset?

zms gravatar imagezms ( 2017-02-15 04:04:56 -0600 )edit