gosseract icon indicating copy to clipboard operation
gosseract copied to clipboard

SetImageFromBytes from gocv.mat Image format ?

Open AlexMcGopher opened this issue 4 years ago • 4 comments

Summary

Is the usage of SetImageFromBytes possible with a gocv.mat ? What conversion do I have to to between the gocv.mat and the []byte input image of SetImageFromBytes ? Currently I save the mat to a Image file, and use SetImage but it must be possible without using a Imagefile....

AlexMcGopher avatar Jan 07 '22 09:01 AlexMcGopher

Would be great if I get at least a small reaction to my question..

AlexMcGopher avatar Jan 20 '22 15:01 AlexMcGopher

Do you mean this? https://github.com/hybridgroup/gocv/blob/5730c4cf12d5fb4590fb7c97db8ed50c7020cc32/core.go#L183-L188

otiai10 avatar Jan 21 '22 03:01 otiai10

Exactly, this is what I am talking about. Sorry for being unprecise in this point.

AlexMcGopher avatar Jan 21 '22 08:01 AlexMcGopher

As of now, I would not fix this package to adjust to another specific package. I would recommend you to find a way to extract []byte from gocv.Mat.

What do you think?

otiai10 avatar Feb 01 '22 15:02 otiai10

I created image.Image object from gocv.Mat. Then got encoded bytes of image.Image object using png.Encode These encoded bytes are getting accepted by gosseract client for my use case.

        client := gosseract.NewClient()
        defer client.Close()

	img := gocv.IMRead("./processed_image.png", gocv.IMReadColor)
	defer img.Close()

	pngImg, _ := img.ToImage()

	buff := new(bytes.Buffer)
	_ = png.Encode(buff, pngImg)

	// client.SetImage("./processed_image.png")
	client.SetImageFromBytes(buff.Bytes())

Shinora007 avatar Sep 07 '22 18:09 Shinora007