fastcv 教程2:图像识别直线

Fastcv使用说明

本文件 所在目录包含了高通下使用fastcv静态库以及sdk的例程,由于fastcv使用交叉编译以及静态库,所以问文件生成略大,大约8M,所以不用往开发板推送动态库。

Fastcv  包含fastcv.h  libfastcv.a的静态库。

Api接口地址:

https://developer.qualcomm.com/docs/fastcv/api/modules.html

1      霍夫检测直线的原理:

YUV->Rgb888->单通道gray->高斯滤波->边缘检测->霍夫变换->结果

fastcv下对应的函数是

   //yuv—rgb888

fcvColorYCbCr422PseudoPlanarToRGB888u8    (ybuf,chrombuf,640,480,0,0,rgb,0);

int file_fd,gray_fd;

int write_size;

#if rgb

if ((file_fd = open("outimg.img",O_CREAT | O_RDWR | O_APPEND,777)) == -1)

{

        printf("create a picture file error!\n");

}

write_size=write(file_fd,rgb,sizeof(rgb));

printf("write_size = %d\n",write_size);

close(file_fd);

#endif

//Rgb565ConvertBmp((char*)outimg,640,480, "test.bmp");

#if bmp

rgb888bmp24((char*)rgb,"bmp24.bmp",640,480);

#endif

memcpy(readBuff,rgb,640*480*3);

//这里将rgb 转换bgr

for(i = 0; i < (640*480); i++)

{

        temp = *(readBuff + i*3);

        *(readBuff + i*3) = *(readBuff + i*3 + 2);

        *(readBuff + i*3 + 2) = temp;     

}

// myColorRGB888ToGray (readBuff, 640, 480);

//灰度转化

fcvColorRGB888ToGrayu8(readBuff, 640, 480,0, grayimg,0);

 memset(readBuff,0,sizeof(readBuff));

//高斯滤波

fcvFilterGaussian3x3u8 (grayimg, 640, 480,readBuff,0);

//边缘检测

fcvFilterCanny3x3u8(readBuff,640,480,cannyBuff,0,15);

//将生成的边缘检测保存成bmp  进行查看

RgbgrayConvertBmp((char *)cannyBuff,640,480,"canny.bmp");

    fcvHoughLineu8(cannyBuff,640,480,0,0.9,100,&linebuf, lineout);

原图yuv格式:


边缘后:

结果:

~ # ./fastcv_server

FastCV version 1.7.1

read 614400

file canny.bmp open success

Image size=307200, file size=308278, width=640, height=480

RgbgrayConvertBmp over

check line 5

check line START: 0.000000 2.117236

check line end: 640.000000 2.158375

check line START: 1.954749 0.000000

check line end: 2.007480 480.000000

check line START: 96.000000 381.228149

check line end: 608.000000 291.381042

check line START: 32.000000 399.263794

check line end: 640.000000 290.721497

check line START: 32.000000 391.076508

check line end: 64.000000 386.329926

说明:在结果中,反馈出来5条线,前两条线是边缘检测会生成两条对比线,水平和垂直的各一条,红框中是水平的。正好对应坐标(02---6402)和(1.90--2.0480

下图1-2  1’-2’  1”-2”分别对应剩下的三条,受环境影响如果照片不够清晰,干扰太多就会出现这种情况,将一条线识别成多条线的可能

我们将fcvHoughLineu8(cannyBuff,640,480,0,0.9,100,&linebuf, lineout);种的0.9 变成0.1

fcvHoughLineu8(cannyBuff,640,480,0,0.1,100,&linebuf, lineout);后会出现7条直线

前两条依旧是对比线。

~ # ./fastcv_server

FastCV version 1.7.1

read 614400

file canny.bmp open success

Image size=307200, file size=308278, width=640, height=480

RgbgrayConvertBmp over

check line 7

check line START: 0.000000 2.117236

check line end: 640.000000 2.158375

check line START: 1.954749 0.000000

check line end: 2.007480 480.000000

check line START: 32.000000 400.639923

check line end: 640.000000 287.543457

check line START: 32.000000 392.301483

check line end: 512.000000 308.120605

check line START: 576.000000 302.354980

check line end: 640.000000 291.278809

check line START: 608.000000 299.494934

check line end: 640.000000 289.787903

check line START: 96.000000 378.592285

check line end: 128.000000 383.339355

sitemap