| | |
| | | package util |
| | | |
| | | import ( |
| | | "basic.com/pubsub/protomsg.git" |
| | | "gocv.io/x/gocv" |
| | | "image" |
| | | "log" |
| | | ) |
| | | // 按尺寸去切图 |
| | | func Subimg(dbyte []byte,x0,y0,x1,y1 int,) []byte{ |
| | | func SubImg(i protomsg.Image,x0,y0,x1,y1 int,) []byte{ |
| | | |
| | | //bbb := bytes.NewBuffer(dbyte) // 必须加一个buffer 不然没有read方法就会报错 |
| | | ////log.Println("==================看看这个buffer",bbb) |
| | |
| | | //f, _ := os.Create("./test.jpg") //创建文件 |
| | | //defer f.Close() //关闭文件 |
| | | //jpeg.Encode(f, subImg, nil) //写入文件 |
| | | |
| | | img,_ := gocv.NewMatFromBytes(100,100,gocv.MatTypeCV8UC3,dbyte) |
| | | log.Println("--------------------------四大金刚:",x0,y0,x1,y1) |
| | | img,_ := gocv.NewMatFromBytes(int(i.Height),int(i.Width),gocv.MatTypeCV8UC3,i.Data) |
| | | rect := image.Rect(x0,y0,x1,y1) |
| | | region := img.Region(rect) |
| | | bytes, _ := gocv.IMEncode(".jpg", region) |