otiai10/gosseract

SetImageFromBytes from gocv.mat Image format ?

AlexMcGopher opened this issue · 5 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....

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

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

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?

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())