go调用opencv自带的车牌分类器加paddleocr识别

1.话不多说效果如下

OCR识别

代码demo

go 复制代码
func testCarClassifier() {

	dll, _ := syscall.LoadDLL("ppocr.dll")
	detect, _ := dll.FindProc("ImageProcess")

	path := "E:\\im\\car\\data\\voc\\VOCdevkit\\VOC2019\\Test"
	files, err := ioutil.ReadDir(path)
	if nil != err {
		fmt.Println("次目录不是个文件夹")
		return
	}
	pathSep := string(os.PathSeparator)
	var carPathFile []string
	for _, fil := range files {
		p := path + pathSep + fil.Name()
		fmt.Println(p)
		if !fil.IsDir() {
			temp := gocv.IMRead(p, gocv.IMReadColor)
			if !temp.Empty() {
				carPathFile = append(carPathFile, p)
			}
		}
	}
	fmt.Println("当前需要处理图片总数:%d", len(carPathFile))
	//newCarPath := [1]string{path + pathSep + "A5JU93.jpg"}
	for index, carPath := range carPathFile {
		fmt.Println(carPath)
		tempCar := gocv.IMRead(carPath, gocv.IMReadColor)
		defer tempCar.Close()

		tempCarGrag := gocv.NewMat()
		defer tempCarGrag.Close()
		gocv.CvtColor(tempCar, &tempCarGrag, gocv.ColorBGRToGray)

		// windowA := gocv.NewWindow("watch")
		// defer windowA.Close()1

		// load classifier to recognize faces
		classifier := gocv.NewCascadeClassifier()
		defer classifier.Close()
		classifier.Load("D:\\go_work\\opencv-4.7.0\\data\\haarcascades\\haarcascade_russian_plate_number.xml")
		rects := classifier.DetectMultiScale(tempCarGrag)
		fmt.Println("rects:%d", len(rects))
		for i := 0; i < len(rects); i++ {
			reactImg := tempCar.Region(rects[i])
			newPat := path + pathSep + strconv.Itoa(index) + "_" + strconv.Itoa(i) + ".jpg"
			fmt.Println("==%s", newPat)
			gocv.IMWrite(newPat, reactImg)

			bT := time.Now() // 开始时间
			res, _, _ := detect.Call(strPtr(newPat))
			p_result := (*C.char)(unsafe.Pointer(res))
			ocrresult := C.GoString(p_result)
			eT := time.Since(bT) // 从开始到当前所消耗的时间
			fmt.Println("Run time: ", eT)
			fmt.Println(ocrresult)
		}
	}
}
相关推荐
编码小哥1 小时前
OpenCV图像滤波技术详解:从均值滤波到双边滤波
人工智能·opencv·均值算法
格林威3 小时前
Baumer相机金属焊缝缺陷识别:提升焊接质量检测可靠性的 7 个关键技术,附 OpenCV+Halcon 实战代码!
人工智能·数码相机·opencv·算法·计算机视觉·视觉检测·堡盟相机
困死,根本不会4 小时前
OpenCV摄像头实时处理:基于 HSV 颜色空间的摄像头实时颜色筛选工具
人工智能·opencv·计算机视觉
Sagittarius_A*4 小时前
角点检测:Harris 与 Shi-Tomasi原理拆解【计算机视觉】
图像处理·人工智能·python·opencv·计算机视觉
困死,根本不会4 小时前
OpenCV实时摄像头处理:曝光调节、降噪与二值化实战
人工智能·opencv·计算机视觉
Sagittarius_A*6 小时前
形态学与多尺度处理:计算机视觉中图像形状与尺度的基础处理框架【计算机视觉】
图像处理·人工智能·python·opencv·计算机视觉
茶栀(*´I`*)6 小时前
【OpenCV 视觉全栈进阶】核心特征提取:模板匹配与霍夫变换(线/圆检测)深度技术指南
图像处理·opencv·计算机视觉
格林威8 小时前
Baumer相机金属弹簧圈数自动计数:用于来料快速检验的 6 个核心算法,附 OpenCV+Halcon 实战代码!
人工智能·数码相机·opencv·算法·计算机视觉·视觉检测·堡盟相机
困死,根本不会8 小时前
OpenCV摄像头实时处理:从单特征到联合识别(形状识别 + 颜色识别 + 形状颜色联合识别)
人工智能·opencv·计算机视觉