| | |
| | | import ( |
| | | "gocv.io/x/gocv" |
| | | "image" |
| | | "log" |
| | | ) |
| | | // 按尺寸去切图 |
| | | func Subimg(dbyte []byte,x0,y0,x1,y1 int,) []byte{ |
| | |
| | | //f, _ := os.Create("./test.jpg") //创建文件 |
| | | //defer f.Close() //关闭文件 |
| | | //jpeg.Encode(f, subImg, nil) //写入文件 |
| | | |
| | | img,_ := gocv.NewMatFromBytes(int(y1-y0),int(x1-x0),gocv.MatTypeCV8UC3,dbyte) |
| | | region := img.Region(image.Rectangle{image.Point{x0,y0},image.Point{x1,y1}}) |
| | | log.Println("--------------------------四大金刚:",x0,y0,x1,y1) |
| | | img,_ := gocv.NewMatFromBytes(50,50,gocv.MatTypeCV8UC3,dbyte) |
| | | rect := image.Rect(x0,y0,x0+50,y0+50) |
| | | region := img.Region(rect) |
| | | bytes, _ := gocv.IMEncode(".jpg", region) |
| | | return bytes |
| | | } |
| | | } |