Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToImage too slow? #93

Open
evan176 opened this issue Nov 27, 2016 · 2 comments
Open

ToImage too slow? #93

evan176 opened this issue Nov 27, 2016 · 2 comments

Comments

@evan176
Copy link
Contributor

evan176 commented Nov 27, 2016

Hi,

I want to convert IplImage to go's image type, but ToImage function is too slow. Is this project alive?

Thanks

@evan176
Copy link
Contributor Author

evan176 commented Nov 29, 2016

I think overhead is in calling C/C++ code. Maybe we can firstly convert IplImage to custom structure and passed to Go, rather than frequent use of Get2D function.

@lbeeon
Copy link

lbeeon commented Mar 14, 2017

@evan176 I suggest that don't use ToImage method. The implementation had some problems while assign channels. I write a new ToImage method, see blow

func ToImage(img *opencv.IplImage) image.Image {
	dst := image.NewRGBA(image.Rectangle{
		Min: image.Point{X: 0, Y: 0},
		Max: image.Point{X: img.Width(), Y: img.Height()},
	})
	for x := 0; x < img.Width(); x++ {
		for y := 0; y < img.Height(); y++ {
			channels := img.Get2D(x, y).Val()
			dst.SetRGBA(x, y, color.RGBA{
				B: uint8(channels[0]),
				G: uint8(channels[1]),
				R: uint8(channels[2]),
				A: uint8(channels[3]),
			})
		}
	}
	return dst
}

Inspired by the method 'FromImage'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants