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)
		}
	}
}
相关推荐
白熊1882 小时前
【计算机视觉】OpenCV实战项目:基于Tesseract与OpenCV的字符识别系统深度解析
人工智能·opencv·计算机视觉
Ronin-Lotus3 小时前
图像处理篇---MJPEG视频流处理
图像处理·python·opencv
六bring个六5 小时前
qtcreater配置opencv
c++·qt·opencv·计算机视觉·图形渲染·opengl
多巴胺与内啡肽.5 小时前
OpenCV进阶操作:光流估计
人工智能·opencv·计算机视觉
alpszero6 小时前
YOLO11解决方案之物体模糊探索
人工智能·python·opencv·计算机视觉·yolo11
多巴胺与内啡肽.7 小时前
OpenCV进阶操作:风格迁移以及DNN模块解析
人工智能·opencv·dnn
zm-v-159304339867 小时前
解锁遥感数据密码:DeepSeek、Python 与 OpenCV 的协同之力
开发语言·python·opencv
jndingxin8 小时前
OpenCV CUDA 模块中在 GPU 上对图像或矩阵进行 翻转(镜像)操作的一个函数 flip()
人工智能·opencv
码农新猿类9 小时前
初入OpenCV
qt·opencv·计算机视觉
一丝晨光11 小时前
数值溢出保护?数值溢出应该是多少?Swift如何让整数计算溢出不抛出异常?类型最大值和最小值?
java·javascript·c++·rust·go·c·swift