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)
		}
	}
}
相关推荐
王中阳Go8 小时前
告别调包侠!2026年Go/Java程序员的AI架构师实战转型指南
后端·go
却道天凉_好个秋9 小时前
OpenCV(四十二):图像分割原理
人工智能·opencv·计算机视觉·图像分割
王中阳Go11 小时前
攻克制造业知识检索难题:我们如何用Go+AI打造高可用RAG系统,将查询效率提升600%
人工智能·后端·go
喵个咪13 小时前
开箱即用的 GoWind Admin|风行,企业级前后端一体中后台框架:用 JavaScript/Lua 解锁动态业务扩展能力
javascript·go·lua
hero_heart13 小时前
opencv和摄影测量坐标系的转换
人工智能·opencv·计算机视觉
却道天凉_好个秋15 小时前
OpenCV(四十三):分水岭法
人工智能·opencv·计算机视觉·图像分割·分水岭法
编码小哥16 小时前
OpenCV几何变换详解:缩放、旋转与平移
人工智能·opencv·计算机视觉
喵个咪1 天前
开箱即用的 GoWind Admin|风行,企业级前后端一体中后台框架:kratos-bootstrap 入门教程(类比 Spring Boot)
后端·微服务·go
王中阳Go1 天前
12 Go Eino AI应用开发实战 | 消息队列架构
人工智能·后端·go
香吧香1 天前
go项目使用go build 与 MakeFile 构建项目
go