Ask Your Question
1

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;
   cvtColor(cropped_rgb,cropped,CV_RGB2GRAY);
  // 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) );
    it++;
}
cerr << Mat(buf) << endl;
    line(cropped,Point(0,cropped.rows/2),Point(cropped.cols,cropped.rows/2),Scalar(255),1);
    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

Comments

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
3

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 );
    it++;
}
edit flag offensive delete link more

Comments

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
1

like:

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

Question Tools

1 follower

Stats

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

Seen: 3,337 times

Last updated: Apr 16 '16