Detecting circles and shots from paper target

前端 未结 1 897
無奈伤痛
無奈伤痛 2020-12-15 01:38

I\'m making a small project where i have to detect points scored from a given image of paper target. Something similar to TargetScan app for iPhone.

I\'m using open

1条回答
  •  离开以前
    2020-12-15 02:27

    Algo:

    1. create/clear mask for image
    2. binarize image (to black and white by some intensity threshold)
    3. process all pixels
    4. count how many pixels of the same color are there in x,y directions

      call it wx,wy

    5. detect circle,shot and mid section

      circles are thin so wx or wy should be less then thin threshold and the other one should be bigger. Shots are big so booth wx and wy must be in shot diameter range. Mid section is black and booth wx,wy above all thresholds (you can compute avg point here). Store this info into mask

    6. recolor image with mask info

    7. compute center and radiuses of the circles from found points

      center is avg point of mid section area, now process all the green points and compute radius for it. Do histogram for all found radiuses and sort it by count descending. The count should be consistent with 2*PI*r if not ignore such points.

    8. group shot pixels together

      so segmentate or flood fill recolor each hit to avoid multiple accounting of single shot

    I coded the #1..#6 for fun in C++ here is the code:

        picture pic0,pic1,pic2;
            // pic0 - source
            // pic1 - output
            // pic2 - mask
        int x,y,i,n,wx,wy;
        int r0=3;           // thin curve wide treshod [pixels]
        int r1a=15;         // shot diameter min treshod [pixels]
        int r1b=30;         // shot diameter max treshod [pixels]
        int x0,y0;          // avg point == center
        // init output as source image but in grayscale intensity only
        pic1=pic0;
        pic1.rgb2i();
        // init mask (size of source image)
        pic2.resize(pic0.xs,pic0.ys);
        pic2.clear(0);
        // binarize image and convert back to RGB
        for (y=r0;y
               pic1.p[y][x].dd=0x00000000; // Black in RGB
          else pic1.p[y][x].dd=0x00FFFFFF; // White in RGB
        // process pixels
        x0=0; y0=0; n=0;
        for (y=r1b;y=r0)||(wy>=r0))    // but still line
                {
                pic2.p[y][x].dd=1;      // thin line
                }
            if (pic1.p[y][x].dd==0)     // black
             if ((wx>=r0)&&(wy>=r0))    // and thick in both axises
                {
                pic2.p[y][x].dd=2;      // middle section
                x0+=x; y0+=y; n++;
                }
            if (pic1.p[y][x].dd)        // white (background color)
            if ((wx>r1a)&&(wy>r1a))     // size in range of shot
             if ((wxCanvas->Pen->Color=0x0000FF;
        pic1.bmp->Canvas->MoveTo(x0-i,y0);
        pic1.bmp->Canvas->LineTo(x0+i,y0);
        pic1.bmp->Canvas->MoveTo(x0,y0-i);
        pic1.bmp->Canvas->LineTo(x0,y0+i);
    

    I use my own picture class for images so some members are:


    xs,ys size of image in pixels
    p[y][x].dd is pixel at (x,y) position as 32 bit integer type
    clear(color) - clears entire image
    resize(xs,ys) - resizes image to new resolution

    This is the recolored result

    example

    • green - thin circles
    • blue mid section
    • red cross (center of circles)
    • red - shots

    as you can see it needs the further processing from bullets #7,#8 and also your image has no shot outside mid section so may be it will need some tweak for shot detection outside mid section too

    [edit1] radiuses

    // create & clear radius histogram
    n=xs; if (n>1]=wx; i=x-1;
        }
    // draw the valid circles
    pic1.bmp->Canvas->Pen->Color=0xFF00FF;  // magenta
    pic1.bmp->Canvas->Pen->Width=r0;
    pic1.bmp->Canvas->Brush->Style=bsClear;
    for (i=0;i=0.3)&&(a<=2.1))
         pic1.bmp->Canvas->Ellipse(x0-i,y0-i,x0+i,y0+i);
        }
    pic1.bmp->Canvas->Brush->Style=bsSolid;
    pic1.bmp->Canvas->Pen->Width=1;
    delete[] hist;
    

    radius circles

    detected circles are in Magenta ... pretty good I think. The mid section screw it a bit. You can compute average radius step and interpolate the missing circles ...

    0 讨论(0)
提交回复
热议问题