gpt4 book ai didi

c++ - C++ 中的 Blob 检测

转载 作者:太空狗 更新时间:2023-10-29 23:08:14 25 4
gpt4 key购买 nike

我是计算机视觉方面的新手,但我需要在 C++ 中做一个小函数,即使他身上印有东西,他也会检测到一张白纸,并检索 4 个边缘坐标,这是我真正需要的所以我可以使用这些坐标并剪切另一个 jpg 文件并将剪切的图像用作 opengl 纹理。我不知道如何检测纸张。尝试搜索计算机视觉,发现我必须对图像进行阈值处理,进行标记,然后使用边缘检测或哈里斯检测,但没有找到任何教程。任何人都可以帮助我解决这个问题,或者给我一些可以帮助我的教程吗?

只需找到这个:

    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;
}

他的这个艺术工具包用来检测标记?如果我创建一个 arDetectSheet ( ARUint8 *dataPtr, int thresh, ARMarkerInfo **marker_info, int *marker_num )并说 opencv 中的图像是 ARUint8 *dataPtr 谁有来自网络摄像头的图像并尝试做 @karlPhilip example它会工作吗?我想检测纸张,这样我就可以得到边缘坐标,这样我就可以使用这些坐标来切割我的 jpg 文件。我想要的是: Detect paper Sheet and edges coordinates Upload a image without a marker and cut at same coordinate os the paper sheet And with the dusted area used as a texture And the create a polygon using the same coordinates and use the texture to hide the paper Sheet

最佳答案

Artoolkit用于构建增强现实应用程序。除非 paper has something printed in it 的片段,否则它无法执行您所描述的操作.

如果您正在考虑一些 other framework to do this task , 我建议你投资 OpenCV

关于c++ - C++ 中的 Blob 检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10366421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com