GithubHelp home page GithubHelp logo

hybridgroup / gocv Goto Github PK

View Code? Open in Web Editor NEW
6.3K 154.0 847.0 5.64 MB

Go package for computer vision using OpenCV 4 and beyond. Includes support for DNN, CUDA, and OpenCV Contrib.

Home Page: https://gocv.io

License: Other

C++ 16.13% Go 76.56% C 5.32% Makefile 1.38% Shell 0.06% Batchfile 0.23% Dockerfile 0.02% Roff 0.30%
opencv golang video computer-vision video-capture face-tracking mjpeg mjpeg-stream image-processing tensorflow

gocv's Introduction

GoCV

GoCV

Go Reference Linux Windows Go Report Card License

The GoCV package provides Go language bindings for the OpenCV 4 computer vision library.

The GoCV package supports the latest releases of Go and OpenCV (v4.9.0) on Linux, macOS, and Windows. We intend to make the Go language a "first-class" client compatible with the latest developments in the OpenCV ecosystem.

GoCV supports CUDA for hardware acceleration using Nvidia GPUs. Check out the CUDA README for more info on how to use GoCV with OpenCV/CUDA.

GoCV also supports Intel OpenVINO. Check out the OpenVINO README for more info on how to use GoCV with the Intel OpenVINO toolkit.

How to use

Hello, video

This example opens a video capture device using device "0", reads frames, and shows the video in a GUI window:

package main

import (
	"gocv.io/x/gocv"
)

func main() {
	webcam, _ := gocv.OpenVideoCapture(0)
	window := gocv.NewWindow("Hello")
	img := gocv.NewMat()

	for {
		webcam.Read(&img)
		window.IMShow(img)
		window.WaitKey(1)
	}
}

Face detect

GoCV

This is a more complete example that opens a video capture device using device "0". It also uses the CascadeClassifier class to load an external data file containing the classifier data. The program grabs each frame from the video, then uses the classifier to detect faces. If any faces are found, it draws a green rectangle around each one, then displays the video in an output window:

package main

import (
	"fmt"
	"image/color"

	"gocv.io/x/gocv"
)

func main() {
    // set to use a video capture device 0
    deviceID := 0

	// open webcam
	webcam, err := gocv.OpenVideoCapture(deviceID)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer webcam.Close()

	// open display window
	window := gocv.NewWindow("Face Detect")
	defer window.Close()

	// prepare image matrix
	img := gocv.NewMat()
	defer img.Close()

	// color for the rect when faces detected
	blue := color.RGBA{0, 0, 255, 0}

	// load classifier to recognize faces
	classifier := gocv.NewCascadeClassifier()
	defer classifier.Close()

	if !classifier.Load("data/haarcascade_frontalface_default.xml") {
		fmt.Println("Error reading cascade file: data/haarcascade_frontalface_default.xml")
		return
	}

	fmt.Printf("start reading camera device: %v\n", deviceID)
	for {
		if ok := webcam.Read(&img); !ok {
			fmt.Printf("cannot read device %v\n", deviceID)
			return
		}
		if img.Empty() {
			continue
		}

		// detect faces
		rects := classifier.DetectMultiScale(img)
		fmt.Printf("found %d faces\n", len(rects))

		// draw a rectangle around each face on the original image
		for _, r := range rects {
			gocv.Rectangle(&img, r, blue, 3)
		}

		// show the image in the window, and wait 1 millisecond
		window.IMShow(img)
		window.WaitKey(1)
	}
}

More examples

There are examples in the cmd directory of this repo in the form of various useful command line utilities, such as capturing an image file, streaming mjpeg video, counting objects that cross a line, and using OpenCV with Tensorflow for object classification.

How to install

To install GoCV, you must first have the matching version of OpenCV installed on your system. The current release of GoCV requires OpenCV 4.9.0.

Here are instructions for Ubuntu, Raspian, macOS, and Windows.

Ubuntu/Linux

Installation

You can use make to install OpenCV 4.9.0 with the handy Makefile included with this repo. If you already have installed OpenCV, you do not need to do so again. The installation performed by the Makefile is minimal, so it may remove OpenCV options such as Python or Java wrappers if you have already installed OpenCV some other way.

Quick Install

First, change directories to where you want to install GoCV, and then use git to clone the repository to your local machine like this:

cd $HOME/folder/with/your/src/
git clone https://github.com/hybridgroup/gocv.git

Make sure to change $HOME/folder/with/your/src/ to where you actually want to save the code.

Once you have cloned the repo, the following commands should do everything to download and install OpenCV 4.9.0 on Linux:

cd gocv
make install

If you need static opencv libraries

make install BUILD_SHARED_LIBS=OFF

If it works correctly, at the end of the entire process, the following message should be displayed:

gocv version: 0.36.1
opencv lib version: 4.9.0

That's it, now you are ready to use GoCV.

Using CUDA with GoCV

See the cuda directory for information.

Using OpenVINO with GoCV

See the openvino directory for information.

Make Install for OpenVINO and Cuda

The following commands should do everything to download and install OpenCV 4.9.0 with CUDA and OpenVINO on Linux. Make sure to change $HOME/folder/with/your/src/ to the directory you used to clone GoCV:

cd $HOME/folder/with/gocv/
make install_all

If you need static opencv libraries

make install_all BUILD_SHARED_LIBS=OFF

If it works correctly, at the end of the entire process, the following message should be displayed:

gocv version: 0.36.1
opencv lib version: 4.9.0-openvino
cuda information:
  Device 0:  "GeForce MX150"  2003Mb, sm_61, Driver/Runtime ver.10.0/10.0

Complete Install

If you have already done the "Quick Install" as described above, you do not need to run any further commands. For the curious, or for custom installations, here are the details for each of the steps that are performed when you run make install.

First, change directories to where you want to install GoCV, and then use git to clone the repository to your local machine like this:

cd $HOME/folder/with/your/src/
git clone https://github.com/hybridgroup/gocv.git

Make sure to change $HOME/folder/with/your/src/ to where you actually want to save the code.

Install required packages

First, you need to change the current directory to the location where you cloned the GoCV repo, so you can access the Makefile:

cd $HOME/folder/with/your/src/gocv

Next, you need to update the system, and install any required packages:

make deps

Download source

Now, download the OpenCV 4.9.0 and OpenCV Contrib source code:

make download

Build

Build everything. This will take quite a while:

make build

If you need static opencv libraries

make build BUILD_SHARED_LIBS=OFF

Install

Once the code is built, you are ready to install:

make sudo_install

Verifying the installation

To verify your installation you can run one of the included examples.

First, change the current directory to the location of the GoCV repo:

cd $HOME/src/gocv.io/x/gocv

Now you should be able to build or run any of the examples:

go run ./cmd/version/main.go

The version program should output the following:

gocv version: 0.36.1
opencv lib version: 4.9.0

Cleanup extra files

After the installation is complete, you can remove the extra files and folders:

make clean

Custom Environment

By default, pkg-config is used to determine the correct flags for compiling and linking OpenCV. This behavior can be disabled by supplying -tags customenv when building/running your application. When building with this tag you will need to supply the CGO environment variables yourself.

For example:

export CGO_CPPFLAGS="-I/usr/local/include"
export CGO_LDFLAGS="-L/usr/local/lib -lopencv_core -lopencv_face -lopencv_videoio -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_objdetect -lopencv_features2d -lopencv_video -lopencv_dnn -lopencv_xfeatures2d"

Please note that you will need to run these 2 lines of code one time in your current session in order to build or run the code, in order to setup the needed ENV variables. Once you have done so, you can execute code that uses GoCV with your custom environment like this:

go run -tags customenv ./cmd/version/main.go

Docker

The project now provides Dockerfile which lets you build GoCV Docker image which you can then use to build and run GoCV applications in Docker containers. The Makefile contains docker target which lets you build Docker image with a single command:

make docker

By default Docker image built by running the command above ships Go version 1.20.2, but if you would like to build an image which uses different version of Go you can override the default value when running the target command:

make docker GOVERSION='1.22.0'

Running GUI programs in Docker on macOS

Sometimes your GoCV programs create graphical interfaces like windows eg. when you use gocv.Window type when you display an image or video stream. Running the programs which create graphical interfaces in Docker container on macOS is unfortunately a bit elaborate, but not impossible. First you need to satisfy the following prerequisites:

  • install xquartz. You can also install xquartz using homebrew by running brew cask install xquartz
  • install socat brew install socat

Note, you will have to log out and log back in to your machine once you have installed xquartz. This is so the X window system is reloaded.

Once you have installed all the prerequisites you need to allow connections from network clients to xquartz. Here is how you do that. First run the following command to open xquart so you can configure it:

open -a xquartz

Click on Security tab in preferences and check the "Allow connections" box:

app image

Next, you need to create a TCP proxy using socat which will stream X Window data into xquart. Before you start the proxy you need to make sure that there is no process listening in port 6000. The following command should not return any results:

lsof -i TCP:6000

Now you can start a local proxy which will proxy the X Window traffic into xquartz which acts a your local X server:

socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"

You are now finally ready to run your GoCV GUI programs in Docker containers. In order to make everything work you must set DISPLAY environment variables as shown in a sample command below:

docker run -it --rm -e DISPLAY=docker.for.mac.host.internal:0 your-gocv-app

Note, since Docker for MacOS does not provide any video device support, you won't be able run GoCV apps which require camera.

Alpine 3.7 Docker image

There is a Docker image with Alpine 3.7 that has been created by project contributor @denismakogon. You can find it located at https://github.com/denismakogon/gocv-alpine.

Raspbian

Installation

We have a special installation for the Raspberry Pi that includes some hardware optimizations. You use make to install OpenCV 4.9.0 with the handy Makefile included with this repo. If you already have installed OpenCV, you do not need to do so again. The installation performed by the Makefile is minimal, so it may remove OpenCV options such as Python or Java wrappers if you have already installed OpenCV some other way.

Quick Install

First, change directories to where you want to install GoCV, and then use git to clone the repository to your local machine like this:

cd $HOME/folder/with/your/src/
git clone https://github.com/hybridgroup/gocv.git

Make sure to change $HOME/folder/with/your/src/ to where you actually want to save the code.

The following make command should do everything to download and install OpenCV 4.9.0 on Raspbian:

cd $HOME/folder/with/your/src/gocv
make install_raspi

If it works correctly, at the end of the entire process, the following message should be displayed:

gocv version: 0.36.1
opencv lib version: 4.9.0

That's it, now you are ready to use GoCV.

macOS

Installation

You can install OpenCV 4.9.0 using Homebrew.

If you already have an earlier version of OpenCV (3.4.x) installed, you should probably remove it before installing the new version:

brew uninstall opencv

You can then install OpenCV 4.9.0:

brew install opencv

pkgconfig Installation

pkg-config is used to determine the correct flags for compiling and linking OpenCV. You can install it by using Homebrew:

brew install pkgconfig

Verifying the installation

To verify your installation you can run one of the included examples.

First, change the current directory to the location of the GoCV repo:

cd $HOME/folder/with/your/src/gocv

Now you should be able to build or run any of the examples:

go run ./cmd/version/main.go

The version program should output the following:

gocv version: 0.36.1
opencv lib version: 4.9.0

Custom Environment

By default, pkg-config is used to determine the correct flags for compiling and linking OpenCV. This behavior can be disabled by supplying -tags customenv when building/running your application. When building with this tag you will need to supply the CGO environment variables yourself.

For example:

export CGO_CXXFLAGS="--std=c++11"
export CGO_CPPFLAGS="-I/usr/local/Cellar/opencv/4.9.0/include"
export CGO_LDFLAGS="-L/usr/local/Cellar/opencv/4.9.0/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dpm -lopencv_face -lopencv_photo -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_dnn -lopencv_plot -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ml -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_flann -lopencv_xobjdetect -lopencv_imgcodecs -lopencv_objdetect -lopencv_xphoto -lopencv_imgproc -lopencv_core"

Please note that you will need to run these 3 lines of code one time in your current session in order to build or run the code, in order to setup the needed ENV variables. Once you have done so, you can execute code that uses GoCV with your custom environment like this:

go run -tags customenv ./cmd/version/main.go

Windows

Installation

The following assumes that you are running a 64-bit version of Windows 10.

In order to build and install OpenCV 4.9.0 on Windows, you must first download and install MinGW-W64 and CMake, as follows.

MinGW-W64

Download and run the MinGW-W64 compiler installer from https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/8.1.0/.

The latest version of the MinGW-W64 toolchain is 8.1.0, but any version from 8.X on should work.

Choose the options for "posix" threads, and for "seh" exceptions handling, then install to the default location c:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0.

Add the C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin path to your System Path.

CMake

Download and install CMake https://cmake.org/download/ to the default location. CMake installer will add CMake to your system path.

OpenCV 4.9.0 and OpenCV Contrib Modules

The following commands should do everything to download and install OpenCV 4.9.0 on Windows:

chdir %GOPATH%\src\gocv.io\x\gocv
win_build_opencv.cmd

It might take up to one hour.

Last, add C:\opencv\build\install\x64\mingw\bin to your System Path.

Verifying the installation

Change the current directory to the location of the GoCV repo:

chdir %GOPATH%\src\gocv.io\x\gocv

Now you should be able to build or run any of the command examples:

go run cmd\version\main.go

The version program should output the following:

gocv version: 0.36.1
opencv lib version: 4.9.0

That's it, now you are ready to use GoCV.

Custom Environment

By default, OpenCV is expected to be in C:\opencv\build\install\include. This behavior can be disabled by supplying -tags customenv when building/running your application. When building with this tag you will need to supply the CGO environment variables yourself.

Due to the way OpenCV produces DLLs, including the version in the name, using this method is required if you're using a different version of OpenCV.

For example:

set CGO_CXXFLAGS="--std=c++11"
set CGO_CPPFLAGS=-IC:\opencv\build\install\include
set CGO_LDFLAGS=-LC:\opencv\build\install\x64\mingw\lib -lopencv_core490 -lopencv_face490 -lopencv_videoio490 -lopencv_imgproc490 -lopencv_highgui490 -lopencv_imgcodecs490 -lopencv_objdetect490 -lopencv_features2d490 -lopencv_video490 -lopencv_dnn490 -lopencv_xfeatures2d490 -lopencv_plot490 -lopencv_tracking490 -lopencv_img_hash490

Please note that you will need to run these 3 lines of code one time in your current session in order to build or run the code, in order to setup the needed ENV variables. Once you have done so, you can execute code that uses GoCV with your custom environment like this:

go run -tags customenv cmd\version\main.go

Android

There is some work in progress for running GoCV on Android using Gomobile. For information on how to install OpenCV/GoCV for Android, please see: https://gist.github.com/ogero/c19458cf64bd3e91faae85c3ac887490

See original discussion here: #235

Profiling

Since memory allocations for images in GoCV are done through C based code, the go garbage collector will not clean all resources associated with a Mat. As a result, any Mat created must be closed to avoid memory leaks.

To ease the detection and repair of the resource leaks, GoCV provides a Mat profiler that records when each Mat is created and closed. Each time a Mat is allocated, the stack trace is added to the profile. When it is closed, the stack trace is removed. See the runtime/pprof documentation.

In order to include the MatProfile custom profiler, you MUST build or run your application or tests using the -tags matprofile build tag. For example:

go run -tags matprofile cmd/version/main.go

You can get the profile's count at any time using:

gocv.MatProfile.Count()

You can display the current entries (the stack traces) with:

var b bytes.Buffer
gocv.MatProfile.WriteTo(&b, 1)
fmt.Print(b.String())

This can be very helpful to track down a leak. For example, suppose you have the following nonsense program:

package main

import (
	"bytes"
	"fmt"

	"gocv.io/x/gocv"
)

func leak() {
	gocv.NewMat()
}

func main() {
	fmt.Printf("initial MatProfile count: %v\n", gocv.MatProfile.Count())
	leak()

	fmt.Printf("final MatProfile count: %v\n", gocv.MatProfile.Count())
	var b bytes.Buffer
	gocv.MatProfile.WriteTo(&b, 1)
	fmt.Print(b.String())
}

Running this program produces the following output:

initial MatProfile count: 0
final MatProfile count: 1
gocv.io/x/gocv.Mat profile: total 1
1 @ 0x40b936c 0x40b93b7 0x40b94e2 0x40b95af 0x402cd87 0x40558e1
#	0x40b936b	gocv.io/x/gocv.newMat+0x4b	/go/src/gocv.io/x/gocv/core.go:153
#	0x40b93b6	gocv.io/x/gocv.NewMat+0x26	/go/src/gocv.io/x/gocv/core.go:159
#	0x40b94e1	main.leak+0x21			/go/src/github.com/dougnd/gocvprofexample/main.go:11
#	0x40b95ae	main.main+0xae			/go/src/github.com/dougnd/gocvprofexample/main.go:16
#	0x402cd86	runtime.main+0x206		/usr/local/Cellar/go/1.11.1/libexec/src/runtime/proc.go:201

We can see that this program would leak memory. As it exited, it had one Mat that was never closed. The stack trace points to exactly which line the allocation happened on (line 11, the gocv.NewMat()).

Furthermore, if the program is a long running process or if GoCV is being used on a web server, it may be helpful to install the HTTP interface )). For example:

package main

import (
	"net/http"
	_ "net/http/pprof"
	"time"

	"gocv.io/x/gocv"
)

func leak() {
	gocv.NewMat()
}

func main() {
	go func() {
		ticker := time.NewTicker(time.Second)
		for {
			<-ticker.C
			leak()
		}
	}()

	http.ListenAndServe("localhost:6060", nil)
}

This will leak a Mat once per second. You can see the current profile count and stack traces by going to the installed HTTP debug interface: http://localhost:6060/debug/pprof/gocv.io/x/gocv.Mat.

How to contribute

Please take a look at our CONTRIBUTING.md document to understand our contribution guidelines.

Then check out our ROADMAP.md document to know what to work on next.

Why this project exists

The https://github.com/go-opencv/go-opencv package for Go and OpenCV does not support any version above OpenCV 2.x, and work on adding support for OpenCV 3 had stalled for over a year, mostly due to the complexity of SWIG. That is why we started this project.

The GoCV package uses a C-style wrapper around the OpenCV 4 C++ classes to avoid having to deal with applying SWIG to a huge existing codebase. The mappings are intended to match as closely as possible to the original OpenCV project structure, to make it easier to find things, and to be able to figure out where to add support to GoCV for additional OpenCV image filters, algorithms, and other features.

For example, the OpenCV videoio module wrappers can be found in the GoCV package in the videoio.* files.

This package was inspired by the original https://github.com/go-opencv/go-opencv project, the blog post https://medium.com/@peterleyssens/using-opencv-3-from-golang-5510c312a3c and the repo at https://github.com/sensorbee/opencv thank you all!

License

Licensed under the Apache 2.0 license. Copyright (c) 2017-2024 The Hybrid Group.

Logo generated by GopherizeMe - https://gopherize.me

gocv's People

Contributors

221bytes avatar acharyab15 avatar berak avatar cartermel avatar covrom avatar danile71 avatar dbatishchev avatar deadprogram avatar denismakogon avatar dlion avatar dougnd avatar edwvee avatar golubaca avatar kylycht avatar littledot avatar longlene avatar maruel avatar masashiyokota avatar mbalayil avatar mh-cbon avatar michaelarusso avatar milosgajdos avatar netbrain avatar pericles-tpt avatar sshibs avatar swdee avatar toffentoffen avatar vcabbage avatar viktor-ferenczi avatar willdurand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gocv's Issues

Some const are missing

Hi,

I'm working on HAAR classifier and wanted to use DetectMultiscaleWithParams. "flags" should be picked from consts that are not listed. Eg. CV_HAAR_FIND_BIGGEST_OBJECT that is found in cpp source file: opencv-3.4.0/modules/objdetect/include/opencv2/objdetect/objdetect_c.h

For now, I'm using the int value (eg. 4)

How can I help to add that const in gocv sources ? What are the rules and tools to add them ?

Thanks

Can you give me a sample about the function HoughCircles?

gocv.CvtColor(img, edges, gocv.ColorBGRToGray)
gocv.GaussianBlur(edges, edges, image.Pt(9, 9), 2, 2, gocv.BorderDefault)
gocv.HoughCircles(edges, circles, 3, 1.5, float64(edges.Rows()/8))
fmt.Println(circles.Mean(), circles.Rows(), circles.Cols())

I want to detect circles.
I can't use the HoughCircles because no samples for HoughCircles.

How to use the circles?

please help me, tks

Standalone distributions for Windows 10

everything works perfect, but is there any way for opencv to compile and run the .exe in Windows 10 without installing the opencv libraries? great job man, keep it up

add param1, param2, minRadius, maxRadius params to HoughCircles

Currently HoughCircles takes in 4 parameters
func HoughCircles(src Mat, circles Mat, method int, dp float64, minDist float64)

the OpenCV HoughCircles methods lets you pass in double param1, double param2, int minRadius, int maxRadius as well as the 4 params currently present.

any chance HoughCircles will be updated to allow for the extra 4 params?

Motion Tracking

Hi there! Thanks for the great package, I've been using it recently in a Raspberry Pi project and had a couple of questions.

While trying to get basic motion detection working on a Pi Zero W with the pi camera I noticed that the face detect easily consumed 100% cpu and would result in less than 1 frame per second (even at only 640x480 resolution). I've since looked into implementing algorithms akin to https://www.pyimagesearch.com/2015/05/25/basic-motion-detection-and-tracking-with-python-and-opencv/ since I don't really need to detect faces, just motion, but seem to be missing some functions (like threshold, contours, etc). I'm not sure if it's an OpenCV 2 vs 3 thing (this is my first attempt at really using OpenCV) but I was curious as to how motion tracking could be implemented given the functions/bindings that are available? I noticed that there are "trackers" in OpenCV 3 as well but couldn't tell if they were available in this Go package. Thanks again!

Get Mat Channels

In python and c++ I can get the height, width, and channels which is the whole shape of the mat. Maybe I just missed it but I can only figure out how to get the rows and cols of the Mats in gocv, how would I access the channels?

I see in the RoadMap it says "Structural Analysis and Shape Descriptors" but I'm not sure if channels would fall under this because you already have rows and columns.

Thanks

memory leak in motion-detection sample

Hi all,
Thanks for a great library, I find the API much simpler than any other Go open-cv library.
If you'd run the motion-detection sample, you'll see memory always grows. I came a full circle to this porting an open-cv 2.x project I have to gocv, and I knew I should be looking for leaks, from previous experience. I then validated the case with your sample, as an isolated example of the problem.

I think here the leak comes from FindContours, somehow.

env problem: more than one version on mac

brew info opencv
opencv: stable 3.4.0 (bottled)
Open source computer vision library
https://opencv.org/
/usr/local/Cellar/opencv/3.4.0 (531 files, 97.7MB)
  Poured from bottle on 2018-01-08 at 16:12:33
/usr/local/Cellar/opencv/3.4.0_1 (531 files, 97.7MB) *
  Poured from bottle on 2018-02-01 at 11:24:33
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/opencv.rb
==> Dependencies
Build: cmake ✘, pkg-config ✔
Required: eigen ✔, ffmpeg ✔, jpeg ✔, libpng ✔, libtiff ✔, openexr ✔, python ✔, python3 ✔, numpy ✔, tbb ✔
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
  mkdir -p /Users/verystar/Library/Python/2.7/lib/python/site-packages
  echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/verystar/Library/Python/2.7/lib/python/site-packages/homebrew.pth
echo $(brew info opencv | grep -E "opencv/3\.([3-9]|[1-9]\d{1,})" | sed -e "s/ (.*//g")
/usr/local/Cellar/opencv/3.4.0 /usr/local/Cellar/opencv/3.4.0_1

Windows 10: Fresh Install - exit status 3221225785

I followed the Windows instructions and when trying to verify the install with the version program it gives an exit status of 3221225785. Did I miss a step?

C:\gopath\src\gocv.io\x\gocv>echo %CGO_CPPFLAGS%
-IC:\opencv\build\install\include

C:\gopath\src\gocv.io\x\gocv>echo %CGO_LDFLAGS%
-LC:\opencv\build\install\x64\mingw\lib -lopencv_core331 -lopencv_videoio331 -lopencv_imgproc331 -lopencv_highgui331 -lopencv_imgcodecs331 -lopencv_objdetect331 -lopencv_features2d331 -lopencv_video331 -lopencv_face331 -lopencv_xfeatures2d331

C:\gopath\src\gocv.io\x\gocv>go run .\cmd\version\main.go
exit status 3221225785
>gcc --version
gcc (x86_64-posix-seh-rev1, Built by MinGW-W64 project) 7.2.0

>go version
go version go1.9.2 windows/amd64

C:\opencv\build\install\x64\mingw\bin>opencv_version.exe
3.3.1

Ubuntu 17.10 - Webcam not detected

Hi !

I'm using this awesome library, thank you !
I was using it with MacOs X for dev, it worked well.

But, with ubuntu 17.10 it doesn't work, and no error is displayed. I can see my webcam with mplayer for instance, but opencv doesn't start it.

Do you have any idea ?

Thanks,
Alexandre.

Installation errors [osx]

go version go1.9.1 darwin/amd64
osx high sierra

Installed opencv first

$ brew install opencv

Next

$ go get github.com/hybridgroup/gocv
# github.com/hybridgroup/gocv
Undefined symbols for architecture x86_64:
  "cv::HoughLines(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, double, double, double, double)", referenced from:
      _HoughLines in imgproc.cpp.o
  "cv::HoughLinesP(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, double, double)", referenced from:
      _HoughLinesP in imgproc.cpp.o
  "cv::VideoWriter::fourcc(char, char, char, char)", referenced from:
      _VideoWriter_Open in videoio.cpp.o
  "cv::VideoWriter::VideoWriter()", referenced from:
      _VideoWriter_New in videoio.cpp.o
  "cv::getTextSize(cv::String const&, int, double, int, int*)", referenced from:
      _GetTextSize in imgproc.cpp.o
  "cv::namedWindow(cv::String const&, int)", referenced from:
      _Window_New in highgui.cpp.o
  "cv::GaussianBlur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)", referenced from:
      _GaussianBlur in imgproc.cpp.o
  "cv::VideoCapture::VideoCapture()", referenced from:
      _VideoCapture_New in videoio.cpp.o
  "cv::destroyWindow(cv::String const&)", referenced from:
      _Window_Close in highgui.cpp.o
  "cv::CascadeClassifier::detectMultiScale(cv::_InputArray const&, std::__1::vector<cv::Rect_<int>, std::__1::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>)", referenced from:
      _CascadeClassifier_DetectMultiScale in objdetect.cpp.o
  "cv::CascadeClassifier::load(cv::String const&)", referenced from:
      _CascadeClassifier_Load in objdetect.cpp.o
  "cv::CascadeClassifier::CascadeClassifier()", referenced from:
      _CascadeClassifier_New in objdetect.cpp.o
  "cv::CascadeClassifier::~CascadeClassifier()", referenced from:
      _CascadeClassifier_Close in objdetect.cpp.o
  "cv::Mat::deallocate()", referenced from:
      _Mat_Close in core.cpp.o
      _Mat_Clone in core.cpp.o
      _Image_IMRead in imgcodecs.cpp.o
  "cv::Mat::create(int, int const*, int)", referenced from:
      _Mat_NewWithSize in core.cpp.o
  "cv::Mat::copySize(cv::Mat const&)", referenced from:
      _Image_IMRead in imgcodecs.cpp.o
  "cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)", referenced from:
      _Mat_Region in core.cpp.o
  "cv::Mat::operator=(cv::Scalar_<double> const&)", referenced from:
      _Mat_NewWithSize in core.cpp.o
  "cv::blur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, cv::Point_<int>, int)", referenced from:
      _Blur in imgproc.cpp.o
  "cv::Canny(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, bool)", referenced from:
      _Canny in imgproc.cpp.o
  "cv::String::deallocate()", referenced from:
      cvflann::anyimpl::big_any_policy<cv::String>::static_delete(void**) in core.cpp.o
      cvflann::anyimpl::big_any_policy<cv::String>::move(void* const*, void**) in core.cpp.o
      _Window_New in highgui.cpp.o
      _Window_Close in highgui.cpp.o
      _Window_IMShow in highgui.cpp.o
      cvflann::anyimpl::big_any_policy<cv::String>::static_delete(void**) in highgui.cpp.o
      cvflann::anyimpl::big_any_policy<cv::String>::move(void* const*, void**) in highgui.cpp.o
      ...
  "cv::String::allocate(unsigned long)", referenced from:
      _Window_New in highgui.cpp.o
      _Window_Close in highgui.cpp.o
      _Window_IMShow in highgui.cpp.o
      _Image_IMRead in imgcodecs.cpp.o
      _Image_IMWrite in imgcodecs.cpp.o
      _Image_IMEncode in imgcodecs.cpp.o
      _GetTextSize in imgproc.cpp.o
      ...
  "cv::imread(cv::String const&, int)", referenced from:
      _Image_IMRead in imgcodecs.cpp.o
  "cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
      _Window_IMShow in highgui.cpp.o
  "cv::imwrite(cv::String const&, cv::_InputArray const&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
      _Image_IMWrite in imgcodecs.cpp.o
  "cv::putText(cv::_InputOutputArray const&, cv::String const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)", referenced from:
      _PutText in imgproc.cpp.o
  "cv::waitKey(int)", referenced from:
      _Window_WaitKey in highgui.cpp.o
  "cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)", referenced from:
      _CvtColor in imgproc.cpp.o
  "cv::fastFree(void*)", referenced from:
      _Mat_Close in core.cpp.o
      _Mat_Clone in core.cpp.o
      _Image_IMRead in imgcodecs.cpp.o
  "cv::imencode(cv::String const&, cv::_InputArray const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
      _Image_IMEncode in imgcodecs.cpp.o
  "cv::rectangle(cv::_InputOutputArray const&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)", referenced from:
      _Rectangle in imgproc.cpp.o
  "cv::Mat::copyTo(cv::_OutputArray const&) const", referenced from:
      _Mat_Clone in core.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

MacOS High Sierra 10.13.2 error while face detection

I have installed the library and run a couple of examples successfully but got this error message while running face detection code from documentation

OpenCV Error: Assertion failed (!empty()) in detectMultiScale, file /tmp/opencv-20180113-80339-d8g5mw/opencv-3.4.0/modules/objdetect/src/cascadedetect.cpp, line 1698
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv-20180113-80339-d8g5mw/opencv-3.4.0/modules/objdetect/src/cascadedetect.cpp:1698: error: (-215) !empty() in function detectMultiScale

SIGABRT: abort
PC=0x7fff6dbc6e3e m=0 sigcode=0
signal arrived during cgo execution

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x409ef30, 0xc420057dd0, 0xc420057df8)
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/cgocall.go:132 +0xe4 fp=0xc420057da0 sp=0xc420057d60 pc=0x40041a4
gocv.io/x/gocv._Cfunc_CascadeClassifier_DetectMultiScale(0xb112c10, 0xb135390, 0x0, 0x0)
	gocv.io/x/gocv/_obj/_cgo_gotypes.go:644 +0x57 fp=0xc420057dd0 sp=0xc420057da0 pc=0x409a9e7
gocv.io/x/gocv.(*CascadeClassifier).DetectMultiScale.func1(0xb112c10, 0xb135390, 0x0, 0x0)
	/Users/Dmitry/go/src/gocv.io/x/gocv/objdetect.go:53 +0xb5 fp=0xc420057e18 sp=0xc420057dd0 pc=0x409c5f5
gocv.io/x/gocv.(*CascadeClassifier).DetectMultiScale(0xc420057f20, 0xb135390, 0x0, 0x0, 0x0)
	/Users/Dmitry/go/src/gocv.io/x/gocv/objdetect.go:53 +0x63 fp=0xc420057e90 sp=0xc420057e18 pc=0x409bcc3
main.main()
	/Users/Dmitry/go/src/github.com/0just0/test_cv/cv.go:49 +0x24b fp=0xc420057f80 sp=0xc420057e90 pc=0x409cd8b
runtime.main()
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/proc.go:195 +0x226 fp=0xc420057fe0 sp=0xc420057f80 pc=0x402b7f6
runtime.goexit()
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc420057fe8 sp=0xc420057fe0 pc=0x4053641

rax    0x0
rbx    0x7fffa6add340
rcx    0x7ffeefbfdc58
rdx    0x0
rdi    0x307
rsi    0x6
rbp    0x7ffeefbfdc90
rsp    0x7ffeefbfdc58
r8     0x7ffeefbfdb20
r9     0x0
r10    0x0
r11    0x206
r12    0x307
r13    0x30
r14    0x6
r15    0x2d
rip    0x7fff6dbc6e3e
rflags 0x206
cs     0x7
fs     0x0
gs     0x0
exit status 2

GetStructuringElement func could work as not expected

func GetStructuringElement(shape MorphShape, ksize image.Point) Mat {
	sz := C.struct_Size{
		height: C.int(ksize.X),
		width:  C.int(ksize.Y),
	}

	return Mat{p: C.GetStructuringElement(C.int(shape), sz)}
}

Here X used as height and Y as width. Sometimes it leads to unexpected result.
For example old C++ code looks like this :
morphKernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(9, 1));
but new gocv code should look like this :
morphKernel := gocv.GetStructuringElement(gocv.MorphRect, image.Point{1, 9})

It's not issue, but it would be nice to add comment there.

Packaging apps using gocv on macOS

My use case is fairly simple - I need OpenCV to analyze image file and return true/false result, nothing too fancy, really a single call to function from imgproc module.

Creating Windows dist package was easy: take a go generated binary, pack it up with OpenCV DLLs, and call it a day.

However, doing same thing on macOS seems to be almost impossible task, but to be fair, I might be missing few tricks here and there.

In order to get the go binary to run, I need to pull in half of my /opt/local/lib folder into the dist package, only to have it running on the latest macOS version (if built on 10.13, it only runs on 10.12/10.13). Attempting to run on 10.10 throws an error about missing CoreImage - quite understandably, as this is system framework available starting with 10.11.

Mentioning /opt/local/lib means that I used OpenCV package from MacPorts (it uses ffmpeg compiled on the spot, meaning it links to other libraries from MacPorts universe), but from what I've noticed, OpenCV distributed via Homebrew has exact same problem.

Does anyone here have some practical take on this?

I know that opencv-python team managed to solve distribution problem somehow, and on PyPi you can get wheel package with staticallly linked dependencies that work on every macOS version since 10.6. I haven't really analyzed that yet, but I guess taking some hints from there would be the best way forward!

Unable to build on OSX: Undefined symbols for architecture x86_64

OSX:

  1. Installed opencv
$ brew install opencv
==> Downloading https://homebrew.bintray.com/bottles/opencv-3.3.1_1.sierra.bottle.tar.gz
Already downloaded: /Users/mike/Library/Caches/Homebrew/opencv-3.3.1_1.sierra.bottle.tar.gz
==> Pouring opencv-3.3.1_1.sierra.bottle.tar.gz
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
  mkdir -p /Users/mike/Library/Python/2.7/lib/python/site-packages
  echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/mike/Library/Python/2.7/lib/python/site-packages/homebrew.pth
==> Summary
🍺  /usr/local/Cellar/opencv/3.3.1_1: 519 files, 95.9MB
  1. installed gocv
$ go get -u -d gocv.io/x/gocv
  1. compiled sample program (1st example of the readme.md)
$ go build main.go
# gocv.io/x/gocv
Undefined symbols for architecture x86_64:
  "cv::HoughLines(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, double, double, double, double)", referenced from:
      _HoughLines in imgproc.cpp.o
  "cv::bitwise_or(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&)", referenced from:
      _Mat_BitwiseOr in core.cpp.o
  "cv::medianBlur(cv::_InputArray const&, cv::_OutputArray const&, int)", referenced from:
      _MedianBlur in imgproc.cpp.o
  "cv::HoughLinesP(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, double, double)", referenced from:
      _HoughLinesP in imgproc.cpp.o
  "cv::VideoWriter::fourcc(char, char, char, char)", referenced from:
      _VideoWriter_Open in videoio.cpp.o
  "cv::VideoWriter::VideoWriter()", referenced from:
      _VideoWriter_New in videoio.cpp.o
  "cv::addWeighted(cv::_InputArray const&, double, cv::_InputArray const&, double, double, cv::_OutputArray const&, int)", referenced from:
      _Mat_AddWeighted in core.cpp.o
  "cv::arrowedLine(cv::_InputOutputArray const&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int, double)", referenced from:
      _ArrowedLine in imgproc.cpp.o
  "cv::bitwise_and(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&)", referenced from:
      _Mat_BitwiseAnd in core.cpp.o
  "cv::bitwise_not(cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&)", referenced from:
      _Mat_BitwiseNot in core.cpp.o
  "cv::bitwise_xor(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&)", referenced from:
      _Mat_BitwiseXor in core.cpp.o
  "cv::getTextSize(cv::String const&, int, double, int, int*)", referenced from:
      _GetTextSize in imgproc.cpp.o
  "cv::namedWindow(cv::String const&, int)", referenced from:
      _Window_New in highgui.cpp.o
  "cv::GaussianBlur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)", referenced from:
      _GaussianBlur in imgproc.cpp.o
  "cv::HoughCircles(cv::_InputArray const&, cv::_OutputArray const&, int, double, double, double, double, int, int)", referenced from:
      _HoughCircles in imgproc.cpp.o
  "cv::VideoCapture::VideoCapture()", referenced from:
      _VideoCapture_New in videoio.cpp.o
  "cv::morphologyEx(cv::_InputArray const&, cv::_OutputArray const&, int, cv::_InputArray const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&)", referenced from:
      _MorphologyEx in imgproc.cpp.o
  "cv::HOGDescriptor::getDefaultPeopleDetector()", referenced from:
      _HOG_GetDefaultPeopleDetector in objdetect.cpp.o
  "cv::destroyWindow(cv::String const&)", referenced from:
      _Window_Close in highgui.cpp.o
  "cv::createTrackbar(cv::String const&, cv::String const&, int*, int, void (*)(int, void*), void*)", referenced from:
      _Trackbar_Create in highgui.cpp.o
  "cv::getTrackbarPos(cv::String const&, cv::String const&)", referenced from:
      _Trackbar_GetPos in highgui.cpp.o
  "cv::setTrackbarMax(cv::String const&, cv::String const&, int)", referenced from:
      _Trackbar_SetMax in highgui.cpp.o
  "cv::setTrackbarMin(cv::String const&, cv::String const&, int)", referenced from:
      _Trackbar_SetMin in highgui.cpp.o
  "cv::setTrackbarPos(cv::String const&, cv::String const&, int)", referenced from:
      _Trackbar_SetPos in highgui.cpp.o
  "cv::bilateralFilter(cv::_InputArray const&, cv::_OutputArray const&, int, double, double, int)", referenced from:
      _BilateralFilter in imgproc.cpp.o
  "cv::CascadeClassifier::detectMultiScale(cv::_InputArray const&, std::__1::vector<cv::Rect_<int>, std::__1::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>)", referenced from:
      _CascadeClassifier_DetectMultiScale in objdetect.cpp.o
  "cv::CascadeClassifier::load(cv::String const&)", referenced from:
      _CascadeClassifier_Load in objdetect.cpp.o
  "cv::CascadeClassifier::CascadeClassifier()", referenced from:
      _CascadeClassifier_New in objdetect.cpp.o
  "cv::CascadeClassifier::~CascadeClassifier()", referenced from:
      _CascadeClassifier_Close in objdetect.cpp.o
  "cv::getOptimalDFTSize(int)", referenced from:
      _Mat_GetOptimalDFTSize in core.cpp.o
  "cv::getStructuringElement(int, cv::Size_<int>, cv::Point_<int>)", referenced from:
      _GetStructuringElement in imgproc.cpp.o
  "cv::createBackgroundSubtractorKNN(int, double, bool)", referenced from:
      _BackgroundSubtractor_CreateKNN in video.cpp.o
  "cv::createBackgroundSubtractorMOG2(int, double, bool)", referenced from:
      _BackgroundSubtractor_CreateMOG2 in video.cpp.o
  "cv::Mat::deallocate()", referenced from:
      _Mat_Close in core.cpp.o
      _Mat_Clone in core.cpp.o
      _Image_IMRead in imgcodecs.cpp.o
  "cv::Mat::create(int, int const*, int)", referenced from:
      _Mat_NewWithSize in core.cpp.o
      _Mat_NewFromScalar in core.cpp.o
  "cv::Mat::copySize(cv::Mat const&)", referenced from:
      _Image_IMRead in imgcodecs.cpp.o
  "cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)", referenced from:
      _Mat_Region in core.cpp.o
  "cv::Mat::operator=(cv::Scalar_<double> const&)", referenced from:
      _Mat_NewWithSize in core.cpp.o
      _Mat_NewFromScalar in core.cpp.o
  "cv::add(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, int)", referenced from:
      _Mat_Add in core.cpp.o
  "cv::dft(cv::_InputArray const&, cv::_OutputArray const&, int, int)", referenced from:
      _Mat_DFT in core.cpp.o
  "cv::blur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, cv::Point_<int>, int)", referenced from:
      _Blur in imgproc.cpp.o
  "cv::line(cv::_InputOutputArray const&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)", referenced from:
      _Line in imgproc.cpp.o
  "cv::Canny(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, bool)", referenced from:
      _Canny in imgproc.cpp.o
  "cv::erode(cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&)", referenced from:
      _Erode in imgproc.cpp.o
  "cv::merge(cv::Mat const*, unsigned long, cv::_OutputArray const&)", referenced from:
      _Mat_Merge in core.cpp.o
  "cv::String::deallocate()", referenced from:
      cvflann::anyimpl::big_any_policy<cv::String>::static_delete(void**) in core.cpp.o
      cvflann::anyimpl::big_any_policy<cv::String>::move(void* const*, void**) in core.cpp.o
      _Window_New in highgui.cpp.o
      _Window_Close in highgui.cpp.o
      _Window_IMShow in highgui.cpp.o
      _Trackbar_Create in highgui.cpp.o
      _Trackbar_GetPos in highgui.cpp.o
      ...
  "cv::String::allocate(unsigned long)", referenced from:
      _Window_New in highgui.cpp.o
      _Window_Close in highgui.cpp.o
      _Window_IMShow in highgui.cpp.o
      _Trackbar_Create in highgui.cpp.o
      _Trackbar_GetPos in highgui.cpp.o
      _Trackbar_SetPos in highgui.cpp.o
      _Trackbar_SetMin in highgui.cpp.o
      ...
  "cv::circle(cv::_InputOutputArray const&, cv::Point_<int>, int, cv::Scalar_<double> const&, int, int, int)", referenced from:
      _Circle in imgproc.cpp.o
  "cv::dilate(cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, cv::Point_<int>, int, int, cv::Scalar_<double> const&)", referenced from:
      _Dilate in imgproc.cpp.o
  "cv::imread(cv::String const&, int)", referenced from:
      _Image_IMRead in imgcodecs.cpp.o
  "cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
      _Window_IMShow in highgui.cpp.o
  "cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)", referenced from:
      _Resize in imgproc.cpp.o
  "cv::absdiff(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&)", referenced from:
      _Mat_AbsDiff in core.cpp.o
  "cv::imwrite(cv::String const&, cv::_InputArray const&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
      _Image_IMWrite in imgcodecs.cpp.o
  "cv::inRange(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&)", referenced from:
      _Mat_InRange in core.cpp.o
  "cv::noArray()", referenced from:
      _Mat_Add in core.cpp.o
      _Mat_BitwiseAnd in core.cpp.o
      _Mat_BitwiseNot in core.cpp.o
      _Mat_BitwiseOr in core.cpp.o
      _Mat_BitwiseXor in core.cpp.o
      _Mat_Normalize in core.cpp.o
  "cv::putText(cv::_InputOutputArray const&, cv::String const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)", referenced from:
      _PutText in imgproc.cpp.o
  "cv::waitKey(int)", referenced from:
      _Window_WaitKey in highgui.cpp.o
  "cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)", referenced from:
      _CvtColor in imgproc.cpp.o
  "cv::fastFree(void*)", referenced from:
      _Mat_Close in core.cpp.o
      _Mat_Clone in core.cpp.o
      _Image_IMRead in imgcodecs.cpp.o
  "cv::imencode(cv::String const&, cv::_InputArray const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
      _Image_IMEncode in imgcodecs.cpp.o
  "cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)", referenced from:
      _Mat_Normalize in core.cpp.o
  "cv::rectangle(cv::_InputOutputArray const&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)", referenced from:
      _Rectangle in imgproc.cpp.o
  "cv::Mat::copyTo(cv::_OutputArray const&) const", referenced from:
      _Mat_Clone in core.cpp.o
      _Mat_CopyTo in core.cpp.o
  "vtable for cv::HOGDescriptor", referenced from:
      _HOGDescriptor_New in objdetect.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Add function to cast Mat into io.Reader

When I use this code:

imgFace := img.Region(r)

Then to be able to get image data, I need to save into file using:

gocv.IMWrite(imgName, imgFace)

And then I can use os.Open and get io.Reader type. But I think it can be helpful to have this in gocv.

Win 10 Instructions - Something missing?

Followed docs for Win 10 to the letter, upon attempting to run cmd/version:

C:\Work\src\gocv.io\x\gocv>set CGO_CPPFLAGS=-IC:\opencv\build\install\include

C:\Work\src\gocv.io\x\gocv>set CGO_LDFLAGS=-LC:\opencv\build\install\x64\mingw\lib -lopencv_core330 -lopencv_videoio330 -lopencv_imgproc331 -lopencv_highgui331 -lopencv_imgcodecs331 -lopencv_objdetect331 -lopencv_calib3d331 -lopencv_video331

C:\Work\src\gocv.io\x\gocv> go run .\cmd\version\main.go
# gocv.io/x/gocv
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lopencv_core330
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lopencv_videoio330
collect2.exe: error: ld returned 1 exit status

C:\Work\src\gocv.io\x\gocv>opencv_version
3.3.1

Any ideas?

Installation on ArchLinux

Hello,

I would like to run gocv on my machine running with an ArchLinux distrib.

The Makefile is compatible only with Debian based distrib, so if you know the equivalent dependencies in Arch repo it would be helpful.

Crash with face example in readme.md

Hello. I try the example face detect, launch sources env.sh and finally go run main.go.
I have this issue:

VIDIOC_QUERYCTRL: Input/output error
start reading camera device: 0
OpenCV Error: Assertion failed (!empty()) in detectMultiScale, file /build/opencv/src/opencv-3.3.1/modules/objdetect/src/cascadedetect.cpp, line 1698
terminate called after throwing an instance of 'cv::Exception'
  what():  /build/opencv/src/opencv-3.3.1/modules/objdetect/src/cascadedetect.cpp:1698: 
error: (-215) !empty() in function detectMultiScale

SIGABRT: abort
PC=0x7fe6c2ab08a0 m=0 sigcode=18446744073709551610
signal arrived during cgo execution

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x49ebd0, 0xc42004fdf0, 0xc42004fe18)
    /usr/lib/go/src/runtime/cgocall.go:132 +0xe4 fp=0xc42004fdc0 sp=0xc42004fd80 
pc=0x411704
gocv.io/x/gocv._Cfunc_CascadeClassifier_DetectMultiScale(0x1535f10, 0x163e620, 0x0, 0x0)
    gocv.io/x/gocv/_obj/_cgo_gotypes.go:291 +0x57 fp=0xc42004fdf0 sp=0xc42004fdc0 pc=0x49c207
gocv.io/x/gocv.(*CascadeClassifier).DetectMultiScale.func1(0x1535f10, 0x163e620, 0x0, 0x0)
    /home/julien/.golang/src/gocv.io/x/gocv/objdetect.go:53 +0xb5 fp=0xc42004fe38 sp=0xc42004fdf0 pc=0x49d995
gocv.io/x/gocv.(*CascadeClassifier).DetectMultiScale(0xc42004ff28, 0x163e620, 0x0, 0x0, 0x0)
    /home/julien/.golang/src/gocv.io/x/gocv/objdetect.go:53 +0x63 fp=0xc42004feb0 sp=0xc42004fe38 pc=0x49d143
main.main()
    /home/julien/Programmation/Golang/hogg/hogg.go:50 +0x230 fp=0xc42004ff80 sp=0xc42004feb0 pc=0x49dfe0
runtime.main()
    /usr/lib/go/src/runtime/proc.go:195 +0x226 fp=0xc42004ffe0 sp=0xc42004ff80 pc=0x438a56
runtime.goexit()
    /usr/lib/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc42004ffe8 sp=0xc42004ffe0 pc=0x4612e1

rax    0x0
rbx    0x6
rcx    0x7fe6c2ab08a0
rdx    0x0
rdi    0x2
rsi    0x7ffc2ad0b460
rbp    0x7fe6c2e2e680
rsp    0x7ffc2ad0b460
r8     0x0
r9     0x7ffc2ad0b460
r10    0x8
r11    0x246
r12    0x1642920
r13    0x7ffc2ad0c860
r14    0x6a2
r15    0x10
rip    0x7fe6c2ab08a0
rflags 0x246
cs     0x33
fs     0x0
gs     0x0
exit status 2

I use openCV-3.3.1 on ArchLinux. I try to comment some lines and, as soon as i uncomment rects := classifier.DetectMultiScale(img), i have this error

OSX install: go get fails ...

go get is failing...
open cv installed via brew.

brew install opencv
go get gocv.io/x/gocv/...


brew install opencv
Warning: opencv 3.3.0_3 is already installed
go get gocv.io/x/gocv/...
# gocv.io/x/gocv
Undefined symbols for architecture x86_64:
  "cv::HoughLines(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, double, double, double, double)", referenced from:
      _HoughLines in imgproc.cpp.o
  "cv::HoughLinesP(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, double, double)", referenced from:
      _HoughLinesP in imgproc.cpp.o
  "cv::VideoWriter::fourcc(char, char, char, char)", referenced from:
      _VideoWriter_Open in videoio.cpp.o
  "cv::VideoWriter::VideoWriter()", referenced from:
      _VideoWriter_New in videoio.cpp.o
  "cv::getTextSize(cv::String const&, int, double, int, int*)", referenced from:
      _GetTextSize in imgproc.cpp.o
  "cv::namedWindow(cv::String const&, int)", referenced from:
      _Window_New in highgui.cpp.o
  "cv::GaussianBlur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)", referenced from:
      _GaussianBlur in imgproc.cpp.o
  "cv::VideoCapture::VideoCapture()", referenced from:
      _VideoCapture_New in videoio.cpp.o
  "cv::destroyWindow(cv::String const&)", referenced from:
      _Window_Close in highgui.cpp.o
  "cv::CascadeClassifier::detectMultiScale(cv::_InputArray const&, std::__1::vector<cv::Rect_<int>, std::__1::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>)", referenced from:
      _CascadeClassifier_DetectMultiScale in objdetect.cpp.o
  "cv::CascadeClassifier::load(cv::String const&)", referenced from:
      _CascadeClassifier_Load in objdetect.cpp.o
  "cv::CascadeClassifier::CascadeClassifier()", referenced from:
      _CascadeClassifier_New in objdetect.cpp.o
  "cv::CascadeClassifier::~CascadeClassifier()", referenced from:
      _CascadeClassifier_Close in objdetect.cpp.o
  "cv::Mat::deallocate()", referenced from:
      _Mat_Close in core.cpp.o
      _Mat_Clone in core.cpp.o
      _Image_IMRead in imgcodecs.cpp.o
  "cv::Mat::create(int, int const*, int)", referenced from:
      _Mat_NewWithSize in core.cpp.o
  "cv::Mat::copySize(cv::Mat const&)", referenced from:
      _Image_IMRead in imgcodecs.cpp.o
  "cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)", referenced from:
      _Mat_Region in core.cpp.o
  "cv::Mat::operator=(cv::Scalar_<double> const&)", referenced from:
      _Mat_NewWithSize in core.cpp.o
  "cv::blur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, cv::Point_<int>, int)", referenced from:
      _Blur in imgproc.cpp.o
  "cv::Canny(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, bool)", referenced from:
      _Canny in imgproc.cpp.o
  "cv::String::deallocate()", referenced from:
      cvflann::anyimpl::big_any_policy<cv::String>::static_delete(void**) in core.cpp.o
      cvflann::anyimpl::big_any_policy<cv::String>::move(void* const*, void**) in core.cpp.o
      _Window_New in highgui.cpp.o
      _Window_Close in highgui.cpp.o
      _Window_IMShow in highgui.cpp.o
      cvflann::anyimpl::big_any_policy<cv::String>::static_delete(void**) in highgui.cpp.o
      cvflann::anyimpl::big_any_policy<cv::String>::move(void* const*, void**) in highgui.cpp.o
      ...
  "cv::String::allocate(unsigned long)", referenced from:
      _Window_New in highgui.cpp.o
      _Window_Close in highgui.cpp.o
      _Window_IMShow in highgui.cpp.o
      _Image_IMRead in imgcodecs.cpp.o
      _Image_IMWrite in imgcodecs.cpp.o
      _Image_IMEncode in imgcodecs.cpp.o
      _GetTextSize in imgproc.cpp.o
      ...
  "cv::imread(cv::String const&, int)", referenced from:
      _Image_IMRead in imgcodecs.cpp.o
  "cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
      _Window_IMShow in highgui.cpp.o
  "cv::imwrite(cv::String const&, cv::_InputArray const&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
      _Image_IMWrite in imgcodecs.cpp.o
  "cv::putText(cv::_InputOutputArray const&, cv::String const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)", referenced from:
      _PutText in imgproc.cpp.o
  "cv::waitKey(int)", referenced from:
      _Window_WaitKey in highgui.cpp.o
  "cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)", referenced from:
      _CvtColor in imgproc.cpp.o
  "cv::fastFree(void*)", referenced from:
      _Mat_Close in core.cpp.o
      _Mat_Clone in core.cpp.o
      _Image_IMRead in imgcodecs.cpp.o
  "cv::imencode(cv::String const&, cv::_InputArray const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
      _Image_IMEncode in imgcodecs.cpp.o
  "cv::rectangle(cv::_InputOutputArray const&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)", referenced from:
      _Rectangle in imgproc.cpp.o
  "cv::Mat::copyTo(cv::_OutputArray const&) const", referenced from:
      _Mat_Clone in core.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [dep] Error 2
x-MacBook-Pro:opencv apple$ make build
cd /Users/apple/workspace/go/src/github.com/gedw99/gitty/exp/opencv/cam && go run main.go
# gocv.io/x/gocv
Undefined symbols for architecture x86_64:
  "cv::HoughLines(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, double, double, double, double)", referenced from:
      _HoughLines in imgproc.cpp.o
  "cv::HoughLinesP(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, double, double)", referenced from:
      _HoughLinesP in imgproc.cpp.o
  "cv::VideoWriter::fourcc(char, char, char, char)", referenced from:
      _VideoWriter_Open in videoio.cpp.o
  "cv::VideoWriter::VideoWriter()", referenced from:
      _VideoWriter_New in videoio.cpp.o
  "cv::getTextSize(cv::String const&, int, double, int, int*)", referenced from:
      _GetTextSize in imgproc.cpp.o
  "cv::namedWindow(cv::String const&, int)", referenced from:
      _Window_New in highgui.cpp.o
  "cv::GaussianBlur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)", referenced from:
      _GaussianBlur in imgproc.cpp.o
  "cv::VideoCapture::VideoCapture()", referenced from:
      _VideoCapture_New in videoio.cpp.o
  "cv::destroyWindow(cv::String const&)", referenced from:
      _Window_Close in highgui.cpp.o
  "cv::CascadeClassifier::detectMultiScale(cv::_InputArray const&, std::__1::vector<cv::Rect_<int>, std::__1::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>)", referenced from:
      _CascadeClassifier_DetectMultiScale in objdetect.cpp.o
  "cv::CascadeClassifier::load(cv::String const&)", referenced from:
      _CascadeClassifier_Load in objdetect.cpp.o
  "cv::CascadeClassifier::CascadeClassifier()", referenced from:
      _CascadeClassifier_New in objdetect.cpp.o
  "cv::CascadeClassifier::~CascadeClassifier()", referenced from:
      _CascadeClassifier_Close in objdetect.cpp.o
  "cv::Mat::deallocate()", referenced from:
      _Mat_Close in core.cpp.o
      _Mat_Clone in core.cpp.o
      _Image_IMRead in imgcodecs.cpp.o
  "cv::Mat::create(int, int const*, int)", referenced from:
      _Mat_NewWithSize in core.cpp.o
  "cv::Mat::copySize(cv::Mat const&)", referenced from:
      _Image_IMRead in imgcodecs.cpp.o
  "cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)", referenced from:
      _Mat_Region in core.cpp.o
  "cv::Mat::operator=(cv::Scalar_<double> const&)", referenced from:
      _Mat_NewWithSize in core.cpp.o
  "cv::blur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, cv::Point_<int>, int)", referenced from:
      _Blur in imgproc.cpp.o
  "cv::Canny(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, bool)", referenced from:
      _Canny in imgproc.cpp.o
  "cv::String::deallocate()", referenced from:
      cvflann::anyimpl::big_any_policy<cv::String>::static_delete(void**) in core.cpp.o
      cvflann::anyimpl::big_any_policy<cv::String>::move(void* const*, void**) in core.cpp.o
      _Window_New in highgui.cpp.o
      _Window_Close in highgui.cpp.o
      _Window_IMShow in highgui.cpp.o
      cvflann::anyimpl::big_any_policy<cv::String>::static_delete(void**) in highgui.cpp.o
      cvflann::anyimpl::big_any_policy<cv::String>::move(void* const*, void**) in highgui.cpp.o
      ...
  "cv::String::allocate(unsigned long)", referenced from:
      _Window_New in highgui.cpp.o
      _Window_Close in highgui.cpp.o
      _Window_IMShow in highgui.cpp.o
      _Image_IMRead in imgcodecs.cpp.o
      _Image_IMWrite in imgcodecs.cpp.o
      _Image_IMEncode in imgcodecs.cpp.o
      _GetTextSize in imgproc.cpp.o
      ...
  "cv::imread(cv::String const&, int)", referenced from:
      _Image_IMRead in imgcodecs.cpp.o
  "cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
      _Window_IMShow in highgui.cpp.o
  "cv::imwrite(cv::String const&, cv::_InputArray const&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
      _Image_IMWrite in imgcodecs.cpp.o
  "cv::putText(cv::_InputOutputArray const&, cv::String const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)", referenced from:
      _PutText in imgproc.cpp.o
  "cv::waitKey(int)", referenced from:
      _Window_WaitKey in highgui.cpp.o
  "cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)", referenced from:
      _CvtColor in imgproc.cpp.o
  "cv::fastFree(void*)", referenced from:
      _Mat_Close in core.cpp.o
      _Mat_Clone in core.cpp.o
      _Image_IMRead in imgcodecs.cpp.o
  "cv::imencode(cv::String const&, cv::_InputArray const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
      _Image_IMEncode in imgcodecs.cpp.o
  "cv::rectangle(cv::_InputOutputArray const&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)", referenced from:
      _Rectangle in imgproc.cpp.o
  "cv::Mat::copyTo(cv::_OutputArray const&) const", referenced from:
      _Mat_Clone in core.cpp.o
ld: symbol(s) not found for architecture x86_64

iteration times on Windows seem unbearable

I'm using Windows 10 with an i7-7700 CPU. I followed the installation instructions from https://gocv.io/getting-started/windows/ (very well written, by the way--better than the opencv officials docs imo!) and everything did work.

Unfortunately, even toy 10-line programs that do something like "load an image from a file, do Canny edge detection, and display it in a window," are taking 10-15 seconds to compile and link. Is it possible I've misconfigured something? Is this unusual? Or is this just "how things are" with the current state of cgo and large C++ libraries?

I don't want to be overly melodramatic, but as someone who's not already an OpenCV expert, this kind of iteration time is a deal breaker for experimenting and learning the library.

!empty() in function detectMultiScale

Hi there,

go version                                                                                                                                      
go version go1.9.3 linux/amd64                                                                                                                   

trying out your face recognition example:
https://gocv.io/writing-code/face-detect/

I bumped into the following error.

  what():  /tmp/opencv/opencv-3.4.0/modules/objdetect/src/cascadedetect.cpp:1698: error: (-215) !empty() in function detectMultiScale

SIGABRT: abort
PC=0x7f313f54f428 m=0 sigcode=18446744073709551610
signal arrived during cgo execution

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4ab1d0, 0xc420055df0, 0xc420055e18)
  /usr/local/go/src/runtime/cgocall.go:132 +0xe4 fp=0xc420055dc0 sp=0xc420055d80 pc=0x41c684
gocv.io/x/gocv._Cfunc_CascadeClassifier_DetectMultiScale(0xef5720, 0xf7da50, 0x0, 0x0)
  gocv.io/x/gocv/_obj/_cgo_gotypes.go:645 +0x57 fp=0xc420055df0 sp=0xc420055dc0 pc=0x4a72f7
gocv.io/x/gocv.(*CascadeClassifier).DetectMultiScale.func1(0xef5720, 0xf7da50, 0x0, 0x0)
  /home/users/me/workspace/go/src/gocv.io/x/gocv/objdetect.go:53 +0xb5 fp=0xc420055e38 sp=0xc420055df0 pc=0x4a8f05
gocv.io/x/gocv.(*CascadeClassifier).DetectMultiScale(0xc420055f30, 0xf7da50, 0x0, 0x0, 0x0)
  /home/users/me/workspace/go/src/gocv.io/x/gocv/objdetect.go:53 +0x63 fp=0xc420055eb0 sp=0xc420055e38 pc=0x4a85d3
main.main()
  /home/users/me/workspace/go/src/facedetect/main.go:49 +0x23c fp=0xc420055f80 sp=0xc420055eb0 pc=0x4a968c
runtime.main()
  /usr/local/go/src/runtime/proc.go:195 +0x226 fp=0xc420055fe0 sp=0xc420055f80 pc=0x443a86
runtime.goexit()
  /usr/local/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc420055fe8 sp=0xc420055fe0 pc=0x46c3a1

Cross Compile for Raspberry Pi

Hi,
first of all, thanks for your great work. I really like it and will be happy to integrate mjpeg streamer into my little robot project.

One thing which I have not found so far. Is there a way to corss compile gocv based projects for raspberry? I tried GOARM=6 GOARCH=arm GOOS=linux go build but this is not working.

Cheers
Johannes

How to rotate an image?

When try the example code in go(cpp -> golang) to rotate an image.

M = cv::getRotationMatrix2D(center, rotationAngle, scale);
cout << M << endl;
// Rotate the source and store in result
cv::warpAffine(source, result, M, Size(source.cols, source.rows));

I cannot find the counter-part in gocv.

So, how to rotate an image in golang without cv::getRotationMatrix2D or cv::warpAffine? Please help me, thank you.

compiler ld errors on features2d

Hi, previously used the gocv 6.0 or earlier. Decided to upgrade today and recived bunch of errors regarding features2d.

Oh and i'm on Windows 10. Using openCV version 3.3.1 .

# gocv.io/x/gocv
C:\Users\ERDEM.KES\AppData\Local\Temp\go-build004497082\gocv.io\x\gocv\_obj\features2d.cpp.o: In function `AKAZE_Create':
..\gocv.io\x\gocv/features2d.cpp:5: undefined reference to `cv::AKAZE::create(int, int, int, float, int, int, int)'
C:\Users\ERDEM.KES\AppData\Local\Temp\go-build004497082\gocv.io\x\gocv\_obj\features2d.cpp.o: In function `AgastFeatureDetector_Create':
..\gocv.io\x\gocv/features2d.cpp:42: undefined reference to `cv::AgastFeatureDetector::create(int, bool, int)'
C:\Users\ERDEM.KES\AppData\Local\Temp\go-build004497082\gocv.io\x\gocv\_obj\features2d.cpp.o: In function `BRISK_Create':
..\gocv.io\x\gocv/features2d.cpp:65: undefined reference to `cv::BRISK::create(int, int, float)'
C:\Users\ERDEM.KES\AppData\Local\Temp\go-build004497082\gocv.io\x\gocv\_obj\features2d.cpp.o: In function `FastFeatureDetector_Create':
..\gocv.io\x\gocv/features2d.cpp:102: undefined reference to `cv::FastFeatureDetector::create(int, bool, int)'
C:\Users\ERDEM.KES\AppData\Local\Temp\go-build004497082\gocv.io\x\gocv\_obj\features2d.cpp.o: In function `ORB_Create':
..\gocv.io\x\gocv/features2d.cpp:125: undefined reference to `cv::ORB::create(int, float, int, int, int, int, int, int, int)'
C:\Users\ERDEM.KES\AppData\Local\Temp\go-build004497082\gocv.io\x\gocv\_obj\features2d.cpp.o: In function `SimpleBlobDetector_Create':
..\gocv.io\x\gocv/features2d.cpp:162: undefined reference to `cv::SimpleBlobDetector::Params::Params()'
..\gocv.io\x\gocv/features2d.cpp:162: undefined reference to `cv::SimpleBlobDetector::create(cv::SimpleBlobDetector::Params const&)'
collect2.exe: error: ld returned 1 exit status

suggest add a type to imcodecs.go

type FileExt string
const(
    PngFileExt FileExt = ".png"
   JPEGFileExt FileExt = ".jpg"
 ...
)
func IMEncode(fileExt string, img Mat) (buf []byte, err error) {
	cfileExt := C.CString(fileExt)
	defer C.free(unsafe.Pointer(cfileExt))

	b := C.Image_IMEncode(cfileExt, img.Ptr())
	defer C.ByteArray_Release(b)
	return toGoBytes(b), nil
}

I use IMEncode("png", img) evoke a panic

Running examples on OSX(10.13.2)

Hi,

I am running on:

High Sierra (10.13.2)
go version go1.9.2 darwin/amd64
I have installed OpenCV using brew and tried to run your examples and getting following error:
(Any guidance would be much appreciated.)

tkila@tkilabook ~/work/src/gocv.io/x/gocv (master) $ go run ./cmd/version/main.go
# gocv.io/x/gocv
In file included from core.cpp:1:
In file included from ./core.h:23:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/opencv.hpp:52:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core.hpp:3281:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core/cvstd.inl.hpp:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/complex:247:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:138:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/mutex:189:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__mutex_base:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/chrono:303:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:56:9: error: no member named 'clock_t' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:58:9: error: no member named 'time_t' in the global namespace; did you mean 'size_t'?
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include/stddef.h:62:23: note: 'size_t' declared here
In file included from core.cpp:1:
In file included from ./core.h:23:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/opencv.hpp:52:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core.hpp:3281:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core/cvstd.inl.hpp:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/complex:247:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:138:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/mutex:189:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__mutex_base:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/chrono:303:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:60:9: error: no member named 'clock' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:61:9: error: no member named 'difftime' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:62:9: error: no member named 'mktime' in the global namespace; did you mean 'mktemp'?
/usr/include/stdlib.h:221:7: note: 'mktemp' declared here
In file included from core.cpp:1:
In file included from ./core.h:23:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/opencv.hpp:52:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core.hpp:3281:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core/cvstd.inl.hpp:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/complex:247:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:138:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/mutex:189:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__mutex_base:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/chrono:303:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:63:9: error: no member named 'time' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:65:9: error: no member named 'asctime' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:66:9: error: no member named 'ctime' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:67:9: error: no member named 'gmtime' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:68:9: error: no member named 'localtime' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:70:9: error: no member named 'strftime' in the global namespace
In file included from core.cpp:1:
In file included from ./core.h:23:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/opencv.hpp:52:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core.hpp:3281:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core/cvstd.inl.hpp:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/complex:247:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:138:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/mutex:189:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__mutex_base:15:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/chrono:1057:12: error: unknown type name 'time_t'; did you mean 'size_t'?
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:57:9: note: 'size_t' declared here
In file included from core.cpp:1:
In file included from ./core.h:23:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/opencv.hpp:52:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core.hpp:3281:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core/cvstd.inl.hpp:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/complex:247:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:138:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/mutex:189:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__mutex_base:15:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/chrono:1058:35: error: unknown type name 'time_t'; did you mean 'size_t'?
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:57:9: note: 'size_t' declared here
In file included from core.cpp:1:
In file included from ./core.h:23:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/opencv.hpp:52:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core.hpp:3281:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core/cvstd.inl.hpp:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/complex:247:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:140:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/locale:2156:27: error: member access into incomplete type 'tm'
/usr/include/wchar.h:131:19: note: forward declaration of 'tm'
In file included from core.cpp:1:
In file included from ./core.h:23:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/opencv.hpp:52:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core.hpp:3281:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core/cvstd.inl.hpp:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/complex:247:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:140:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/locale:2168:25: error: member access into incomplete type 'tm'
/usr/include/wchar.h:131:19: note: forward declaration of 'tm'
In file included from core.cpp:1:
In file included from ./core.h:23:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/opencv.hpp:52:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core.hpp:3281:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core/cvstd.inl.hpp:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/complex:247:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:140:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/locale:2180:20: error: member access into incomplete type 'tm'
/usr/include/wchar.h:131:19: note: forward declaration of 'tm'
In file included from core.cpp:1:
In file included from ./core.h:23:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/opencv.hpp:52:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core.hpp:3281:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core/cvstd.inl.hpp:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/complex:247:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:140:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/locale:2197:31: error: member access into incomplete type 'tm'
/usr/include/wchar.h:131:19: note: forward declaration of 'tm'
In file included from core.cpp:1:
In file included from ./core.h:23:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/opencv.hpp:52:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core.hpp:3281:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core/cvstd.inl.hpp:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/complex:247:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:140:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/locale:2202:29: error: member access into incomplete type 'tm'
/usr/include/wchar.h:131:19: note: forward declaration of 'tm'
In file included from core.cpp:1:
In file included from ./core.h:23:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/opencv.hpp:52:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core.hpp:3281:
In file included from /usr/local/Cellar/opencv/3.4.0_1/include/opencv2/core/cvstd.inl.hpp:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/complex:247:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:140:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/locale:2212:23: error: member access into incomplete type 'tm'
/usr/include/wchar.h:131:19: note: forward declaration of 'tm'
fatal error: too many errors emitted, stopping now [-ferror-limit=]

examples should be in their own folders

go-opencv3/examples/facedetect.go > go-opencv3/cmd/facedetect/main.go

We should have 1 main per folder/package and the convention is to use have a cmd folder containing those CLI tools/examples.

Error while building MJPEG-Streamer

i get this error while building https://github.com/hybridgroup/gocv/blob/master/cmd/mjpeg-streamer/main.go

# github.com/Shashwatsh/personal-surveillance
./main.go:49:14: cannot assign *gocv.VideoCapture to webcam (type gocv.VideoCapture) in multiple assignment

any ideas?

Installation error on Arch Linux

OpenCV 3.3.0-2

go version go1.9.1 linux/amd64

# github.com/hybridgroup/gocv
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/core.cpp.o: In function `cv::Mat::create(int, int, int)':
/usr/include/opencv2/core/mat.inl.hpp:784: undefined reference to `cv::Mat::create(int, int const*, int)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/core.cpp.o: In function `cv::Mat::Mat(int, int, int, cv::Scalar_<double> const&)':
/usr/include/opencv2/core/mat.inl.hpp:421: undefined reference to `cv::Mat::operator=(cv::Scalar_<double> const&)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/core.cpp.o: In function `cv::Mat::~Mat()':
/usr/include/opencv2/core/mat.inl.hpp:692: undefined reference to `cv::fastFree(void*)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/core.cpp.o: In function `cv::Mat::release()':
/usr/include/opencv2/core/mat.inl.hpp:804: undefined reference to `cv::Mat::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/core.cpp.o: In function `Mat_Clone':
/usr/include/opencv2/core/mat.inl.hpp:764: undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/core.cpp.o: In function `Mat_Region':
./core.cpp:31: undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/core.cpp.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/core.cpp.o: In function `cv::String::operator=(cv::String const&)':
/usr/include/opencv2/core/cvstd.hpp:655: undefined reference to `cv::String::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/core.cpp.o: In function `cv::Mat::release()':
/usr/include/opencv2/core/mat.inl.hpp:804: undefined reference to `cv::Mat::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/core.cpp.o: In function `cv::Mat::~Mat()':
/usr/include/opencv2/core/mat.inl.hpp:692: undefined reference to `cv::fastFree(void*)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/highgui.cpp.o: In function `Window_New':
./highgui.cpp:5: undefined reference to `cv::namedWindow(cv::String const&, int)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/highgui.cpp.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/highgui.cpp.o: In function `Window_Close':
./highgui.cpp:9: undefined reference to `cv::destroyWindow(cv::String const&)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/highgui.cpp.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/highgui.cpp.o: In function `Window_IMShow':
./highgui.cpp:13: undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/highgui.cpp.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/highgui.cpp.o: In function `Window_WaitKey':
./highgui.cpp:17: undefined reference to `cv::waitKey(int)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/highgui.cpp.o: In function `cv::String::String(char const*)':
/usr/include/opencv2/core/cvstd.hpp:601: undefined reference to `cv::String::allocate(unsigned long)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgcodecs.cpp.o: In function `Image_IMRead':
./imgcodecs.cpp:5: undefined reference to `cv::imread(cv::String const&, int)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgcodecs.cpp.o: In function `Image_IMRead':
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgcodecs.cpp.o: In function `cv::Mat::~Mat()':
/usr/include/opencv2/core/mat.inl.hpp:692: undefined reference to `cv::fastFree(void*)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgcodecs.cpp.o: In function `cv::Mat::Mat(cv::Mat const&)':
/usr/include/opencv2/core/mat.inl.hpp:490: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgcodecs.cpp.o: In function `cv::Mat::release()':
/usr/include/opencv2/core/mat.inl.hpp:804: undefined reference to `cv::Mat::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgcodecs.cpp.o: In function `Image_IMRead':
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgcodecs.cpp.o: In function `Image_IMWrite':
./imgcodecs.cpp:10: undefined reference to `cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgcodecs.cpp.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgcodecs.cpp.o: In function `Image_IMEncode':
./imgcodecs.cpp:15: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgcodecs.cpp.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgproc.cpp.o: In function `CvtColor':
./imgproc.cpp:4: undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgproc.cpp.o: In function `Blur':
./imgproc.cpp:9: undefined reference to `cv::blur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, cv::Point_<int>, int)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgproc.cpp.o: In function `GaussianBlur':
./imgproc.cpp:14: undefined reference to `cv::GaussianBlur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgproc.cpp.o: In function `Canny':
./imgproc.cpp:18: undefined reference to `cv::Canny(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, bool)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgproc.cpp.o: In function `HoughLines':
./imgproc.cpp:22: undefined reference to `cv::HoughLines(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, double, double, double, double)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgproc.cpp.o: In function `HoughLinesP':
./imgproc.cpp:26: undefined reference to `cv::HoughLinesP(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, double, double)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgproc.cpp.o: In function `Rectangle':
./imgproc.cpp:31: undefined reference to `cv::rectangle(cv::_InputOutputArray const&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgproc.cpp.o: In function `GetTextSize':
./imgproc.cpp:36: undefined reference to `cv::getTextSize(cv::String const&, int, double, int, int*)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgproc.cpp.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgproc.cpp.o: In function `PutText':
./imgproc.cpp:45: undefined reference to `cv::putText(cv::_InputOutputArray const&, cv::String const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/imgproc.cpp.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/objdetect.cpp.o: In function `CascadeClassifier_New':
./objdetect.cpp:5: undefined reference to `cv::CascadeClassifier::CascadeClassifier()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/objdetect.cpp.o: In function `CascadeClassifier_Close':
./objdetect.cpp:9: undefined reference to `cv::CascadeClassifier::~CascadeClassifier()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/objdetect.cpp.o: In function `CascadeClassifier_Load':
./objdetect.cpp:13: undefined reference to `cv::CascadeClassifier::load(cv::String const&)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/objdetect.cpp.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/objdetect.cpp.o: In function `CascadeClassifier_DetectMultiScale':
./objdetect.cpp:18: undefined reference to `cv::CascadeClassifier::detectMultiScale(cv::_InputArray const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/videoio.cpp.o: In function `VideoCapture_New':
./videoio.cpp:5: undefined reference to `cv::VideoCapture::VideoCapture()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/videoio.cpp.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/videoio.cpp.o: In function `VideoWriter_New':
./videoio.cpp:40: undefined reference to `cv::VideoWriter::VideoWriter()'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/videoio.cpp.o: In function `VideoWriter_Open':
./videoio.cpp:49: undefined reference to `cv::VideoWriter::fourcc(char, char, char, char)'
/tmp/go-build805318815/github.com/hybridgroup/gocv/_obj/videoio.cpp.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
/usr/include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
collect2: ошибка: выполнение ld завершилось с кодом возврата 1

nextEventMatchingMask should only be called from the Main Thread! (MacOS)

Hi, I got this error when run the 'motion-detect' demo on MacOS 10.13.1:

$ go run main.go 0
Start reading camera device: 0
2017-11-19 03:50:16.083 main[29761:4138352] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff4ba062fb __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00007fff72373c76 objc_exception_throw + 48
	2   AppKit                              0x00007fff497322cf -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 4167
	3   libopencv_highgui.3.3.dylib         0x0000000004e3bc0f cvWaitKey + 351
	4   libopencv_highgui.3.3.dylib         0x0000000004e372ca _ZN2cv9waitKeyExEi + 34
	5   libopencv_highgui.3.3.dylib         0x0000000004e37330 _ZN2cv7waitKeyEi + 34
	6   main                                0x00000000040a4e03 Window_WaitKey + 19
	7   main                                0x00000000040a026c _cgo_c1a8f8376f83_Cfunc_Window_WaitKey + 28
	8   main                                0x0000000004052970 runtime.asmcgocall + 112
)
libc++abi.dylib: terminating with uncaught exception of type NSException
SIGABRT: abort
PC=0x7fff730b1fce m=3 sigcode=0
signal arrived during cgo execution

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x40a0250, 0xc42003ae30, 0x0)
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/cgocall.go:132 +0xe4 fp=0xc42003adf0 sp=0xc42003adb0 pc=0x4004334
gocv.io/x/gocv._Cfunc_Window_WaitKey(0x1, 0x0)
	gocv.io/x/gocv/_obj/_cgo_gotypes.go:1653 +0x4d fp=0xc42003ae30 sp=0xc42003adf0 pc=0x409d07d
gocv.io/x/gocv.WaitKey(0x1, 0x9f0ca90)
	/Users/besser/go/src/gocv.io/x/gocv/highgui.go:128 +0x2a fp=0xc42003ae50 sp=0xc42003ae30 pc=0x409d65a
main.main()
	/Users/besser/go/src/gocv.io/x/gocv/cmd/motion-detect/main.go:100 +0x5d5 fp=0xc42003af80 sp=0xc42003ae50 pc=0x409f7b5
runtime.main()
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/proc.go:195 +0x226 fp=0xc42003afe0 sp=0xc42003af80 pc=0x402b986
runtime.goexit()
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc42003afe8 sp=0xc42003afe0 pc=0x40537d1

rax    0x0
rbx    0x70000c346000
rcx    0x70000c344428
rdx    0x0
rdi    0xc03
rsi    0x6
rbp    0x70000c344460
rsp    0x70000c344428
r8     0x70000c3442f0
r9     0x70000c3444c0
r10    0x0
r11    0x206
r12    0xc03
r13    0x30
r14    0x6
r15    0x2d
rip    0x7fff730b1fce
rflags 0x206
cs     0x7
fs     0x0
gs     0x0
exit status 2

imgproc.cpp issue on MacOS

Hi! I am getting

imgproc.cpp:61:28: error: expected '(' for function-style cast or type construction

error, tried running simple Hello World! sample.

"imgproc.cpp issue on MacOS #30" is happen to me again, and i find answer

I find this line on ./env.sh

CVPATH=$(brew info opencv | sed -n "4p" | sed -e "s/ (.*//g")

But i already install opencv 2 and 3.1
So i have 3 opencv version 2, 3.1, 3.4

It cause set CVPATH="/usr/local/Cellar/opencv/2.4.13"

So i changed

CVPATH=$(brew info opencv | grep -E "opencv/3\.([3-9]|[1-9]\d{1,})" | sed -e "s/ (.*//g")

This make CVPATH can select cv3.3 above
And it seem fine

If anyone have multiple opencv installed by brew can have same problem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.