OpenCV Ubuntu Golang

Source: Internet
Author: User

21-day Boutique blockchain free learning, in-depth expert led the way, to help developers easily play the blockchain! >>>

Installation

#3.4.2sudo apt-get install opencvsudo apt-get install golang-1.9vi ~/.profileexport GOPATH=$HOME/Desktop/GoPathexport PATH=$PATH:$GOPATH/bin:wq!#https://github.com/hybridgroup/gocv#version 0.14.0go 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)        }

Preparing data

mkdir opencv_datacd 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

Training data

mkdir dataopencv_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 //样本太少

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.