opencv ubuntu golang

栏目: 编程工具 · 发布时间: 6年前

21天精品区块链课程免费学习,深入实战行家带路,助力开发者轻松玩转区块链! >>> opencv ubuntu golang

安装

#3.4.2
sudo apt-get install opencv

sudo apt-get install golang-1.9

vi ~/.profile

export GOPATH=$HOME/Desktop/GoPath
export PATH=$PATH:$GOPATH/bin

:wq!
#https://github.com/hybridgroup/gocv
#version 0.14.0
go get gocv.io/x/gocv

gocv

//灰度图
        gocv.CvtColor(img,&grayMat, gocv.ColorRGBAToGray)
        //均值滤波
        gocv.Blur(grayMat, &canny, image.Point{3,3})
        //边缘检测
        gocv.Canny(grayMat, &canny, 125, 225)
        //二值化处理,非黑即白图片
        gocv.Threshold(canny, &binaryMat, 165, 255, gocv.ThresholdBinary)
        //中值滤波
        gocv.MedianBlur(binaryMat,&binaryMat,3)
        //创建一个40x40的Mat
        element_9 := gocv.NewMatWithSizeFromScalar(gocv.NewScalar(1,1,1,255), 40, 40, gocv.MatTypeCV8U)
        defer element_9.Close()
        //将图片binaryMat 中 + - 40 距离的连通矩形 连在一起
        gocv.MorphologyEx(binaryMat,&element_9,gocv.MorphCross, element_9)
        //寻找连通矩形
        contoursList := gocv.FindContours(element_9, gocv.RetrievalCComp,gocv.ChainApproxNone)


        for _,contours := range(contoursList){
            rect := gocv.BoundingRect(contours)
            gocv.Rectangle(&img,rect,blue,1)
        }

准备数据

mkdir opencv_data
cd opencv_data
#放置训练数据图片(大小一致)
mkdir img
#放置纯背景图片
mkdir neg_img
#根据提示操作,选择需要识别的区域
opencv_annotation --annotations=positive.txt --images=img

#将positive.txt中的图片对应的矩阵放置到 positive_sample.vec中等待训练使用
opencv_createsamples -info positive.txt -vec positive_sample.vec -num 66 -w 100 -h 63

训练数据

mkdir data
opencv_traincascade -data data -vec positive_sample.vec -bg negative.txt -numPos 66 -numNeg 7 -numStage 15  -w 100 -h 63 -minHitRate 0.99 -maxFalseAlarmRate 0.5 -mode ALL -featureType HAAR -precalcValBufSize 4048 -precalcIdxBufSize 4048 -numThreads 24

//Required leaf false alarm rate achieved. Branch training terminated 
//样本太少

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Spring in Action

Spring in Action

Craig Walls / Manning Publications / 2011-6-29 / USD 49.99

Spring in Action, Third Edition has been completely revised to reflect the latest features, tools, practices Spring offers to java developers. It begins by introducing the core concepts of Spring and......一起来看看 《Spring in Action》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试