Ask Your Question

line scanning for the bar code

asked 2016-04-16 07:29:56 -0600

arash gravatar image

updated 2016-04-16 07:47:04 -0600

berak gravatar image

Hello dears, These days, I am working on reading bar code as a projects for school, since I do not have enough experience and familiarity with Opencv , I have been hanged on this projects ,but of course I did some thing to do. Briefly, I would like to create one scan line class in opencv with c++image description ///////////////////////////////code //////////////////////////////

   Mat cropped;
  // cout <<"cols " <<cropped.cols<< "\n" << "rows" << cropped.rows/2 << "\n"  << cropped.size()<< endl;
  LineIterator it(cropped,Point(0,cropped.rows/2),Point(cropped.cols,cropped.rows/2),8,false);  
  vector<Point> points(it.count);
  vector<Vec3b> buf;   

for(int i=0; i<it.count; i++)
    buf.push_back( Vec3b(*it) );
cerr << Mat(buf) << endl;
    imshow( "cropped", cropped );

the result: image description

as you can see my problem is here,there is <Vec3b> which is not desirable for me,just the values has been put inside the box are very important to me. So,is it possible guide me and tell me,how i should catch these values ????really appreciate it.

edit retag flag offensive close merge delete


happy decoding !

Description     Spectrum Naturals Organic Coconut Oil
Size/Weight     14 fl. oz.
Issuing Country     United States
berak gravatar imageberak ( 2016-04-16 07:57:45 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-04-16 08:03:10 -0600

berak gravatar image

updated 2016-04-16 08:10:00 -0600

LineIterator is overkill (for a horizontal line), you can just use:

int y = cropped.rows/2;
Mat line = cropped.row(y);

if you still want to use it, make sure, you use the right type (uchar, not Vec3b for a grayscale image)

vector<uchar> buf;   

for(int i=0; i<it.count; i++)
    buf.push_back( *it );
edit flag offensive delete link more


indeed, i have tried this code and the result of this is same as i have illustrated it. and "buf.push_back(Vec3b(*it))" is correct,anyway thank for reply me.

arash gravatar imagearash ( 2016-04-16 09:24:16 -0600 )edit

if i use int y = cropped.rows/2; Mat line = cropped.row(y);

how can i access to the values ?

arash gravatar imagearash ( 2016-04-16 11:03:31 -0600 )edit


uchar pixel =<uchar>(x);
berak gravatar imageberak ( 2016-04-16 11:30:08 -0600 )edit

Question Tools

1 follower


Asked: 2016-04-16 07:29:56 -0600

Seen: 3,257 times

Last updated: Apr 16 '16