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)
		}
	}
}
相关推荐
我不会起名字3222 小时前
未接入最终读上限的参数:`websocketMaxMsgLen` 与 12.5 倍差距
后端·websocket·go·即时通讯·im·故障排查
王中阳Go4 小时前
100 件货卖出 116 件,库存停在 -16
后端·mysql·go
我不会起名字3221 天前
req.Seqs[len-1]:空切片防御缺口与 RPC 二次校验
后端·mongodb·go·即时通讯·im·故障排查
Rattenking1 天前
OpenCV 轨迹栏操作和键盘响应操作
人工智能·opencv·计算机外设
我不会起名字3222 天前
会话缓存失效排查:区分 Redis 失效与节点广播
redis·后端·go·即时通讯·im·故障排查
大然Ryan3 天前
我用 Go 和 AI 做了一个 macOS 磁盘清理工具:Vole(开源)
go
我不会起名字3223 天前
seq 空洞排查:Mongo 的 51 只是预留上界,Redis CURR 才是已消耗边界
redis·后端·mongodb·go·即时通讯·im·故障排查
ahccqw4 天前
OpenCV 车辆数量统计
人工智能·opencv·计算机视觉
喵个咪4 天前
GoWind 拆解:全链 ID 类型体系——int64 定版与前端字符串化契约
前端·后端·go
喵个咪4 天前
GoWind CMS 拆解:发布审批——多级推进、逐级角色与全程留痕
前端·后端·go