在C ++中的blob检测 [英] blob detection in C++

查看:185
本文介绍了在C ++中的blob检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是计算机视觉的新手,但我需要在C ++中创建一个小功能,即使他打印出来的东西,他也会检测到白皮书,并且检索4个边缘,协调我真正需要的东西所以我可以使用这些坐标,并切割另一个jpg文件,并使用cutted图像作为opengl纹理。
我不知道如何检测纸张。
尝试搜索关于计算机视觉,并发现我必须阈值图像,做标签,然后使用边缘检测或哈里斯检测,但没有找到任何教程。
任何人都可以帮助我,或者告诉我一些可以帮助我的教程。



只要找到这个:

  int arDetectMarker(ARUint8 * dataPtr,int thresh,
ARMarkerInfo ** marker_info,int * marker_num)
{
ARInt16 * ;
int label_num;
int * area,* clip,* label_ref;
double * pos;
double rarea,rlen,rlenmin;
double diff,diffmin;
int cid,cdir;
int i,j,k;

* marker_num = 0;

limage = arLabeling(dataPtr,thresh,
& label_num,& area,& pos,& clip,& label_ref);
if(limage == 0)return -1;

marker_info2 = arDetectMarker2(limage,label_num,label_ref,
area,pos,clip,AR_AREA_MAX,AR_AREA_MIN,
1.0,& wmarker_num);
if(marker_info2 == 0)return -1;

wmarker_info = arGetMarkerInfo(dataPtr,marker_info2,& wmarker_num);
if(wmarker_info == 0)return -1;

for(i = 0; i

rlenmin = 10.0;
cid = -1;
for(j = 0; j rarea =(double)prev_info [i] .marker.area /(double)wmarker_info [j] .area;
if(rarea< 0.7 || rarea> 1.43)continue;
rlen =((wmarker_info [j] .pos [0] - prev_info [i] .marker.pos [0])
*(wmarker_info [j] .pos [0] - prev_info [i] .marker.pos [0])
+(wmarker_info [j] .pos [1] - prev_info [i] .marker.pos [1])$ ​​b $ b *(wmarker_info [j] .pos [1] ] - prev_info [i] .marker.pos [1]))/ wmarker_info [j] .area;
if(rlen< 0.5& rlen< rlenmin){
rlenmin = rlen;
cid = j;
}
}
if(cid> = 0&& wmarker_info [cid] .cf< prev_info [i] .marker.cf){
wmarker_info [cid ] .cf = prev_info [i] .marker.cf;
wmarker_info [cid]。id = prev_info [i] .marker.id;
diffmin = 10000.0 * 10000.0;
cdir = -1;
for(j = 0; j <4; j ++){
diff = 0;
for(k = 0; k <4; k ++){
diff + =(prev_info [i] .marker.vertex [k] [0] -wmarker_info [cid] .vertex [ + k)%4] [0])
*(prev_info [i] .marker.vertex [k] [0] -wmarker_info [cid] .vertex [(j + k)%4] [0]
+(prev_info [i] .marker.vertex [k] [1] - wmarker_info [cid] .vertex [(j + k)%4] [2] .marker.vertex [k] [3] - wmarker_info [cid] .vertex [(j + k)%4] [4]);
}
if(diff< diffmin){
diffmin = diff;
cdir =(prev_info [i] .marker.dir - j + 4)%4;
}
}
wmarker_info [cid] .dir = cdir;
}
}

for(i = 0; i / *
printf(cf =%g\\ \\ n,wmarker_info [i] .cf)
* /
if(wmarker_info [i] .cf <0.5)wmarker_info [i] .id = -1;
}


/ * ------------------------------- ----------------------------- * /

for(i = j = 0; i < prev_num; i ++){
prev_info [i] .count ++;
if(prev_info [i] .count <4){
prev_info [j] = prev_info [i];
j ++;
}
}
prev_num = j;

for(i = 0; i if(wmarker_info [i] .id <

for(j = 0; j

if(prev_info [j] .marker.id == wmarker_info [i] .id)break;
}
prev_info [j] .marker = wmarker_info [i];
prev_info [j] .count = 1;
if(j == prev_num)prev_num ++;
}

for(i = 0; i

for(j = 0; j rarea =(double)prev_info [i] .marker.area /(double)wmarker_info [j] .area;
if(rarea< 0.7 || rarea> 1.43)continue;
rlen =((wmarker_info [j] .pos [0] - prev_info [i] .marker.pos [0])
*(wmarker_info [j] .pos [0] - prev_info [i] .marker.pos [0])
+(wmarker_info [j] .pos [1] - prev_info [i] .marker.pos [1])$ ​​b $ b *(wmarker_info [j] .pos [1] ] - prev_info [i] .marker.pos [1]))/ wmarker_info [j] .area;
if(rlen <0.5)break;
}
if(j == wmarker_num){
wmarker_info [wmarker_num] = prev_info [i] .marker;
wmarker_num ++;
}
}


* marker_num = wmarker_num;
* marker_info = wmarker_info;

return 0;
}

他这个artoolkit用来检测一个标记?
如果我创建一个arDetectSheet(ARUint8 * dataPtr,int thresh,
ARMarkerInfo ** marker_info,int * marker_num)
并且说opencv中的图像是ARUint8 * dataPtr谁有来自网络摄像头的图像并尝试执行@karlPhilip 用于构建增强现实应用程序。它不能做你所描述的,除非这块纸上印有东西



如果您正在考虑其他框架来执行此任务,我建议您投资 OpenCV


I'm new at computer vision, but i need to made a little function in C++, who will detect a white paper sheet even if is something printed on him, and the retrieve the 4 edges coordinates what is what i really need so i can use those coordinates and cut another jpg file and use the cutted image as a opengl textures. I dont know how to detect the paper. Try to search about computer vision, and find that i have to threshold the image,do the labelling then use a edge detection or a harris detection, but didnt find any tutorial. Can any one help me with this, or show me some tutorial who can help me?

Just find this:

    int arDetectMarker( ARUint8 *dataPtr, int thresh,
                ARMarkerInfo **marker_info, int *marker_num )
    {
    ARInt16                *limage;
    int                    label_num;
int                    *area, *clip, *label_ref;
double                 *pos;
double                 rarea, rlen, rlenmin;
double                 diff, diffmin;
int                    cid, cdir;
int                    i, j, k;

*marker_num = 0;

limage = arLabeling( dataPtr, thresh,
                     &label_num, &area, &pos, &clip, &label_ref );
if( limage == 0 )    return -1;

marker_info2 = arDetectMarker2( limage, label_num, label_ref,
                                area, pos, clip, AR_AREA_MAX, AR_AREA_MIN,
                                1.0, &wmarker_num);
if( marker_info2 == 0 ) return -1;

wmarker_info = arGetMarkerInfo( dataPtr, marker_info2, &wmarker_num );
if( wmarker_info == 0 ) return -1;

for( i = 0; i < prev_num; i++ ) {
    rlenmin = 10.0;
    cid = -1;
    for( j = 0; j < wmarker_num; j++ ) {
        rarea = (double)prev_info[i].marker.area / (double)wmarker_info[j].area;
        if( rarea < 0.7 || rarea > 1.43 ) continue;
        rlen = ( (wmarker_info[j].pos[0] - prev_info[i].marker.pos[0])
               * (wmarker_info[j].pos[0] - prev_info[i].marker.pos[0])
               + (wmarker_info[j].pos[1] - prev_info[i].marker.pos[1])
               * (wmarker_info[j].pos[1] - prev_info[i].marker.pos[1]) ) / wmarker_info[j].area;
        if( rlen < 0.5 && rlen < rlenmin ) {
            rlenmin = rlen;
            cid = j;
        }
    }
    if( cid >= 0 && wmarker_info[cid].cf < prev_info[i].marker.cf ) {
        wmarker_info[cid].cf = prev_info[i].marker.cf;
        wmarker_info[cid].id = prev_info[i].marker.id;
        diffmin = 10000.0 * 10000.0;
        cdir = -1;
        for( j = 0; j < 4; j++ ) {
            diff = 0;
            for( k = 0; k < 4; k++ ) {
                diff += (prev_info[i].marker.vertex[k][0] - wmarker_info[cid].vertex[(j+k)%4][0])
                      * (prev_info[i].marker.vertex[k][0] - wmarker_info[cid].vertex[(j+k)%4][0])
                      + (prev_info[i].marker.vertex[k][1] - wmarker_info[cid].vertex[(j+k)%4][2])
                      * (prev_info[i].marker.vertex[k][3] - wmarker_info[cid].vertex[(j+k)%4][4]);
            }
            if( diff < diffmin ) {
                diffmin = diff;
                cdir = (prev_info[i].marker.dir - j + 4) % 4;
            }
        }
        wmarker_info[cid].dir = cdir;
    }
}

for( i = 0; i < wmarker_num; i++ ) {
    /*
printf("cf = %g\n", wmarker_info[i].cf);
    */
    if( wmarker_info[i].cf < 0.5 ) wmarker_info[i].id = -1;
   }


    /*------------------------------------------------------------*/

for( i = j = 0; i < prev_num; i++ ) {
    prev_info[i].count++;
    if( prev_info[i].count < 4 ) {
        prev_info[j] = prev_info[i];
        j++;
    }
}
prev_num = j;

for( i = 0; i < wmarker_num; i++ ) {
    if( wmarker_info[i].id < 0 ) continue;

    for( j = 0; j < prev_num; j++ ) {
        if( prev_info[j].marker.id == wmarker_info[i].id ) break;
    }
    prev_info[j].marker = wmarker_info[i];
    prev_info[j].count  = 1;
    if( j == prev_num ) prev_num++;
}

for( i = 0; i < prev_num; i++ ) {
    for( j = 0; j < wmarker_num; j++ ) {
        rarea = (double)prev_info[i].marker.area / (double)wmarker_info[j].area;
        if( rarea < 0.7 || rarea > 1.43 ) continue;
        rlen = ( (wmarker_info[j].pos[0] - prev_info[i].marker.pos[0])
               * (wmarker_info[j].pos[0] - prev_info[i].marker.pos[0])
               + (wmarker_info[j].pos[1] - prev_info[i].marker.pos[1])
               * (wmarker_info[j].pos[1] - prev_info[i].marker.pos[1]) ) / wmarker_info[j].area;
        if( rlen < 0.5 ) break;
    }
    if( j == wmarker_num ) {
        wmarker_info[wmarker_num] = prev_info[i].marker;
        wmarker_num++;
    }
}


*marker_num  = wmarker_num;
*marker_info = wmarker_info;

return 0;
    }

his this artoolkit uses to detect a marker? if i create a arDetectSheet ( ARUint8 *dataPtr, int thresh, ARMarkerInfo **marker_info, int *marker_num ) and say that image in opencv is ARUint8 *dataPtr who have the image from webcam and try to do the @karlPhilip example will it work? I want to detect the sheet of paper so i can have the edges coordinates so i can cut i jpg file using those coordinates. What i want:

解决方案

Artoolkit is used for building Augmented Reality applications. It can't do what you described unless the piece of paper has something printed in it.

If you are considering some other framework to do this task, I suggest you invest in OpenCV.

这篇关于在C ++中的blob检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆