Ask Your Question

Golang binding for C++ API

asked 2015-02-07 06:38:58 -0500

lazywei gravatar image


I maintain a Golang binding for OpenCV, see It uses CGO for bridging C & Go, which means I can only use C API interface.

However, I notice that in OpenCV 2 (and afterward), there is only C++ API. After some googling, I know that you're not gonna support C API anymore after 2.x. Therefore, I decide to try to make a wrapper for C++ API instead. I'm wondering if you could give me suggestion on how I can make it or how I can start with?

Currently, I'm looking into SWIG. My concern is ... when I make a repository (or Go package) for OpenCV wrapper, do I must include the header files of OpenCV if I want to use SWIG? Can I use SWIG without include OpenCV's header files (e.g., leave them in /usr/local/opt/opencv/include)?


edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2015-02-20 03:17:08 -0500

lazywei gravatar image

I finally found a way to use SWIG to build C++ wrapper for Go. In case someone is interested in it, please refer to the gocvpackage under Thanks.

edit flag offensive delete link more


@lazywei How do I compare 2 images in Golang? I need to check the similarity using histogram and compare them. No able to find methods like calcHist() or compareHist() which are there in openCV c/c++ code.

KaustubhD gravatar imageKaustubhD ( 2016-09-14 05:29:31 -0500 )edit

answered 2017-11-14 03:45:36 -0500

Hello, everyone

For anyone who is interested, I've started a new project called GoCV ( which is a Golang wrapper around OpenCV 3+

It uses C wrappers around the C++ wrappers, to avoid the need for SWIG, and make it easier to call OpenCV from Go.

Please check it out, and thanks to @lazywei for the previous work.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-02-07 06:38:58 -0500

Seen: 3,954 times

Last updated: Feb 20 '15