Coder Social home page Coder Social logo

jan-bar / go-opencv Goto Github PK

View Code? Open in Web Editor NEW

This project forked from go-opencv/go-opencv

0.0 0.0 0.0 7.04 MB

Go bindings for OpenCV / 2.x API in gocv / 1.x API in opencv

License: BSD 3-Clause "New" or "Revised" License

C++ 89.58% C 6.23% Go 3.59% Dockerfile 0.05% SWIG 0.27% Objective-C 0.21% Batchfile 0.08%

go-opencv's Introduction

Go OpenCV binding

Join the chat at https://gitter.im/lazywei/go-opencv

A Golang binding for OpenCV.

OpenCV 1.x C API bindings through CGO, and OpenCV 2+ C++ API (GoCV) through SWIG.


Disclaimer

This is a fork of chai's go-opencv, which has only OpenCV1 support through CGO, and all credits for OpenCV1 wrapper (except files in gocv/ folder) should mainly go to Chai. At the time of the fork (Dec 9, 2013) the original project was inactive and was hosted on Google Code, which was a little inconvenient for community contribution. Hence, I decided to host a fork on Github so people can contribute to this project easily. Since then, some patches were added by community, and some experimental OpenCV 2 wrappers were added as well. That means this fork went on a little bit divergent way comparing to the origin project. However, now the origin project seems to be active again and be moved to GitHub starting from Aug 25, 2014. Efforts to merge the two projects are very welcome.


Install

Linux & Mac OS X

Install Go and OpenCV, you might want to install both of them via apt-get or homebrew.

You can reference the link to install required packages.

go get github.com/go-opencv/go-opencv
cd $GOPATH/src/github.com/go-opencv/go-opencv/samples
go run hellocv.go

Windows

  • Install Go and MinGw
  • install OpenCV-2.4.x to MinGW dir
# libopencv*.dll --> ${MinGWRoot}\bin
# libopencv*.lib --> ${MinGWRoot}\lib
# include\opencv --> ${MinGWRoot}\include\opencv
# include\opencv2 --> ${MinGWRoot}\include\opencv2

go get github.com/go-opencv/go-opencv
cd ${GoOpenCVRoot}/trunk/samples && go run hellocv.go

[WIP] OpenCV2 (GoCV)

After OpenCV 2.x+, the core team no longer develop and maintain C API. Therefore, CGO will not be used in CV2 binding. Instead, we are using SWIG for wrapping. The support for OpenCV2 is currently under development, and whole code will be placed under gocv package.

If you want to use CV2's API, please refer to the code under gocv/ directory. There is no too many documents for CV2 wrapper yet, but you can still find the example usages in *_test.go.

Please also note that the basic data structures in OpenCV (e.g., cv::Mat, cv::Point3f) are wrapped partially for now. For more detail on how to use these types, please refer to GoCV's README.

Requirement: we will build the wrappers based on mat64, given it is much easier to manipulate the underlaying data. In most case, it is not necessary to access the original CV data, e.g., cv::Mat can be converted from/to *mat64.Dense.

Example

OpenCV2's initCameraMatrix2D

package main

import . "github.com/go-opencv/go-opencv/gocv"
import "github.com/gonum/matrix/mat64"

func main() {

	objPts := mat64.NewDense(4, 3, []float64{
		0, 25, 0,
		0, -25, 0,
		-47, 25, 0,
		-47, -25, 0})

	imgPts := mat64.NewDense(4, 2, []float64{
		1136.4140625, 1041.89208984,
		1845.33190918, 671.39581299,
		302.73373413, 634.79998779,
		1051.46154785, 352.76107788})

	camMat := GcvInitCameraMatrix2D(objPts, imgPts)
	fmt.Println(camMat)
}

Resizing

package main

import opencv "github.com/jan-bar/go-opencv/opencv"

func main() {
	filename := "bert.jpg"
	srcImg := opencv.LoadImage(filename)
	if srcImg == nil {
		panic("Loading Image failed")
	}
	defer srcImg.Release()
	resized1 := opencv.Resize(srcImg, 400, 0, 0)
	resized2 := opencv.Resize(srcImg, 300, 500, 0)
	resized3 := opencv.Resize(srcImg, 300, 500, 2)
	opencv.SaveImage("resized1.jpg", resized1, nil)
	opencv.SaveImage("resized2.jpg", resized2, nil)
	opencv.SaveImage("resized3.jpg", resized3, nil)
}

Webcam

Yet another cool example is created by @saratovsource which demos how to use webcam:

cd samples
go run webcam.go

More

You can find more samples at: https://github.com/go-opencv/go-opencv/tree/master/samples

How to contribute

  • Fork this repo

  • Clone the main repo, and add your fork as a remote

    git clone https://github.com/go-opencv/go-opencv.git
    cd go-opencv
    git remote rename origin upstream
    git remote add origin https://github.com/your_github_account/go-opencv.git
    
  • Create new feature branch

    git checkout -b your-feature-branch
    
  • Commit your change and push it to your repo

    git commit -m 'new feature'
    git push origin your-feature-branch
    
  • Open a pull request!

link

goOpenCv

go-opencv's People

Contributors

lazywei avatar kevinabrandon avatar davidoram avatar zankich avatar fredcarle avatar vanillahsu avatar jan-bar avatar akirill0v avatar brian-armstrong-discord avatar nfillot avatar mohamed-helala avatar evan176 avatar bradleyg avatar egonschiele avatar satojkovic avatar hpgood avatar chai2010 avatar zakkor avatar gitter-badger avatar wizztjh avatar 9nut avatar shnellpavel avatar kweisamx avatar nickknissen avatar gen2brain avatar asm-jaime avatar niaow avatar fhs avatar didrocks avatar dmelani avatar

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.