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)
		}
	}
}
相关推荐
_李小白9 小时前
【android opencv学习笔记】Day 32:直线检测之霍夫变换
android·opencv·学习
程序员正茂13 小时前
EasyAR使用OpenCV下USB摄像头作为自定义相机
opencv·unity·easyar
_李小白14 小时前
【android opencv学习笔记】Day 31:提取轮廓之Canny算法
android·opencv·学习
点云兔子17 小时前
舱口检测:从点云到矩形定位的射线投影算法
opencv·算法·点云·舱口检测
蝈蝈Tjguo18 小时前
opencv 与摄影测量 相机坐标系的区别
人工智能·数码相机·opencv
盼小辉丶18 小时前
OpenCV-Python实战(26)——复杂场景下的实时物体检测与跟踪
python·opencv·计算机视觉
踏着七彩祥云的小丑19 小时前
Go学习第2天:程序结构+基础语法+数据类型
开发语言·学习·golang·go
咸鱼翻身小阿橙1 天前
在VScode使用C#并且调用opencv库
vscode·opencv·c#
吴佳浩1 天前
AI Infra 的真相:Go 没输,rust也不是取代
后端·rust·go
2601_959644891 天前
2026年权威AI引擎优化服务咨询,专业之选
go