Ask Your Question
0

Find projections of an image and divide it vertically and horizontally

asked 2018-08-01 05:37:37 -0500

hrishi22 gravatar image

I want to get vertical, horizontal projections and check if there are 2 or more zero values in the projection. I am working on a shelf image, where I want to detect all the shelves and for each shelf, segment the products vertically. I am thinking of the following approach.C:\fakepath\flow.png. I have attached the desired ouput image also.C:\fakepath\project.png. If I get that, I was thinking of getting a grid on the image so that i can get the coordinates for the line segments achieved vertically and horizontally.

FLOW:

Shelf Image - Horizontal shelf detection - vertical product segmentation - getting coordinates for the intersetions(output)

I am working with opencv. Appreciate assistance!

Thanks, Hrishi

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2018-08-03 18:22:54 -0500

have a look at this (from https://github.com/jsxyhelu/GOCvHelpe...)

void projection2(Mat src,vector<int>& vup,vector<int>& vdown,int direction,int gap){
        Mat tmp = src.clone();
        vector<int> vdate;
        if (DIRECTION_X == direction){
            for (int i=0;i<tmp.cols;i++){
                Mat data = tmp.col(i);
                int itmp = countNonZero(data);
                vdate.push_back(itmp);
            }
        }else{
            for (int i=0;i<tmp.rows;i++){
                Mat data = tmp.row(i);
                int itmp = countNonZero(data);
                vdate.push_back(itmp);
            }
        }
        //avoid gap
        if (vdate.size()<=gap)
            return;
        for (int i=0;i<vdate.size()-gap;i++){
            if (vdate[i]>0 && vdate[i+gap]>0){
                for (int j=i;j<i+gap;j++){
                    vdate[j] = 1;
                }
                i = i+gap-1;
            }
        }
        //up and down
        for (int i=1;i<vdate.size();i++){
            if (vdate[i-1] == 0 && vdate[i]>0)
                vup.push_back(i);
            if (vdate[i-1]>0 && vdate[i] == 0)
                vdown.push_back(i);
        }
}

and i do this to get the vector<int>

……
 threshold(matSplit[1],ostu,100,255,THRESH_OTSU);
 dstclone = ostu.clone();
 // get the vector<int>
 for (int i=0;i<ostu.cols;i++)
    {
        Mat data = ostu.col(i);
        int itmp = countNonZero(data);
        vectorV.push_back(itmp);
    }
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-08-01 05:37:37 -0500

Seen: 123 times

Last updated: Aug 03 '18