diff --git a/go.mod b/go.mod index 98a497e4..f679ba11 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/justinas/alice v1.2.0 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/rs/zerolog v1.29.1 + gocv.io/x/gocv v0.33.0 ) require ( diff --git a/go.sum b/go.sum index a09e1573..5bc93773 100644 --- a/go.sum +++ b/go.sum @@ -31,6 +31,7 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGa github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/hybridgroup/mjpeg v0.0.0-20140228234708-4680f319790e/go.mod h1:eagM805MRKrioHYuU7iKLUyFPVKqVV6um5DAvCkUtXs= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= @@ -45,6 +46,7 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9 github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= +github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -65,6 +67,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +gocv.io/x/gocv v0.33.0 h1:WDtaBrq92AKrhepYzEktydDzNSm3t5k7ciawZK4rns8= +gocv.io/x/gocv v0.33.0/go.mod h1:oc6FvfYqfBp99p+yOEzs9tbYF9gOrAQSeL/dyIPefJU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= diff --git a/internal/generator/download.go b/internal/generator/download.go index 79740099..5aa35d01 100644 --- a/internal/generator/download.go +++ b/internal/generator/download.go @@ -6,6 +6,7 @@ import ( "image" "image/gif" "image/jpeg" + "io" "net/http" "net/url" "path/filepath" @@ -15,6 +16,7 @@ import ( "github.com/SongStitch/song-stitch/internal/cache" "github.com/rs/zerolog" + "gocv.io/x/gocv" ) const ( @@ -24,13 +26,11 @@ const ( const maxRetries = 3 -var ( - backoffSchedule = []time.Duration{ - 200 * time.Millisecond, - 500 * time.Millisecond, - 1 * time.Second, - } -) +var backoffSchedule = []time.Duration{ + 200 * time.Millisecond, + 500 * time.Millisecond, + 1 * time.Second, +} func DownloadImageWithRetry(ctx context.Context, entity Downloadable) error { var err error @@ -149,40 +149,32 @@ func getExtension(u string) (string, error) { return ext, nil } -func GetImage(ctx context.Context, img *image.Image, url string) error { +func GetImage(ctx context.Context, url string, mat *gocv.Mat) (image.Image, error) { if len(url) == 0 { - img = nil - // Skip album art if it doesn't exist - return nil + return nil, nil } req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { - return err + return nil, err } resp, err := http.DefaultClient.Do(req) if err != nil { - return err + return nil, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return fmt.Errorf("unexpected status code: %d", resp.StatusCode) + return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode) } - - extension, err := getExtension(url) + imgBytes, err := io.ReadAll(resp.Body) if err != nil { - return err + return nil, err } - if strings.ToLower(extension) == jpgFileType { - *img, err = jpeg.Decode(resp.Body) - } else if strings.ToLower(extension) == gifFileType { - *img, err = gif.Decode(resp.Body) - } else { - *img, _, err = image.Decode(resp.Body) - } + err = gocv.IMDecodeIntoMat(imgBytes, -1, mat) if err != nil { - return err + return nil, err } + img, _ := mat.ToImage() - return nil + return img, nil } diff --git a/internal/generator/image.go b/internal/generator/image.go index 4e1d0ac0..3233af78 100644 --- a/internal/generator/image.go +++ b/internal/generator/image.go @@ -3,7 +3,9 @@ package generator import ( "bytes" "context" + "fmt" "image" + "runtime" "sync" "time" @@ -11,27 +13,28 @@ import ( "github.com/SongStitch/go-webp/webp" "github.com/SongStitch/song-stitch/internal/constants" "github.com/fogleman/gg" + "gocv.io/x/gocv" "github.com/nfnt/resize" "github.com/rs/zerolog" ) type DisplayOptions struct { - ArtistName bool - AlbumName bool - TrackName bool - PlayCount bool - Compress bool - Resize bool - Width uint + TextLocation constants.TextLocation Height uint + ImageDimension int + Columns int + Rows int FontSize float64 + Width uint + PlayCount bool + Resize bool BoldFont bool - Rows int - Columns int - ImageDimension int + Compress bool + ArtistName bool + TrackName bool Webp bool - TextLocation constants.TextLocation + AlbumName bool } const ( @@ -114,7 +117,6 @@ func resizeImage(ctx context.Context, img *image.Image, width uint, height uint) } else if int(width) == (*img).Bounds().Dx() && int(height) == (*img).Bounds().Dy() { return img } else if height == 0 { - height = uint(float64(width) * float64((*img).Bounds().Dy()) / float64((*img).Bounds().Dx())) } else if width == 0 { width = uint(float64(height) * float64((*img).Bounds().Dx()) / float64((*img).Bounds().Dy())) @@ -191,7 +193,11 @@ func CreateCollageEfficient[T Drawable](ctx context.Context, albums []T, display var wg sync.WaitGroup maxconcurrent := 10 sem := make(chan struct{}, maxconcurrent) - images := make([]image.Image, maxconcurrent) + mats := make([]*gocv.Mat, maxconcurrent) + for i := range mats { + m := gocv.NewMatWithSize(displayOptions.ImageDimension, displayOptions.ImageDimension, gocv.MatTypeCV8UC3) + mats[i] = &m + } wg.Add(len(albums)) @@ -205,8 +211,7 @@ func CreateCollageEfficient[T Drawable](ctx context.Context, albums []T, display wg.Done() }() - img := images[i%maxconcurrent] - err := GetImage(ctx, &img, album.GetImageUrl()) + img, err := GetImage(ctx, album.GetImageUrl(), mats[i%maxconcurrent]) if err != nil { logger.Error().Err(err).Msg("Failed to fetch image") return @@ -218,8 +223,10 @@ func CreateCollageEfficient[T Drawable](ctx context.Context, albums []T, display album.ClearImage() placeText(dc, album, displayOptions, float64(x), float64(y)) + if i%10 == 0 { + PrintMemUsage() + } } - }(album, x, y, i) } @@ -230,7 +237,22 @@ func CreateCollageEfficient[T Drawable](ctx context.Context, albums []T, display if displayOptions.Resize { collage = *resizeImage(ctx, &collage, displayOptions.Width, displayOptions.Height) } + PrintMemUsage() logger.Info().Dur("duration", time.Since(start)).Int("rows", displayOptions.Rows).Int("columns", displayOptions.Columns).Msg("Collage created") return &collage, nil } + +func PrintMemUsage() { + var m runtime.MemStats + runtime.ReadMemStats(&m) + // For info on each, see: https://golang.org/pkg/runtime/#MemStats + fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc)) + fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc)) + fmt.Printf("\tSys = %v MiB", bToMb(m.Sys)) + fmt.Printf("\tNumGC = %v\n", m.NumGC) +} + +func bToMb(b uint64) uint64 { + return b / 1024 / 1024 +} diff --git a/internal/server/server.go b/internal/server/server.go index 86d246d4..32b31459 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -2,6 +2,7 @@ package server import ( "net/http" + "net/http/pprof" "os" "time" @@ -65,6 +66,12 @@ func RunServer() { router.HandleFunc("/support", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "public/support.html") }) + router.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index)) + router.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) + router.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) + router.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) + router.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace)) + router.Handle("/debug/pprof/{cmd}", http.HandlerFunc(pprof.Index)) server := &http.Server{ Addr: ":8080", diff --git a/vendor/gocv.io/x/gocv/.astylerc b/vendor/gocv.io/x/gocv/.astylerc new file mode 100644 index 00000000..e05f9df4 --- /dev/null +++ b/vendor/gocv.io/x/gocv/.astylerc @@ -0,0 +1,28 @@ +--lineend=linux + +--style=google + +--indent=spaces=4 +--indent-col1-comments +--convert-tabs + +--attach-return-type +--attach-namespaces +--attach-classes +--attach-inlines + +--add-brackets +--add-braces + +--align-pointer=type +--align-reference=type + +--max-code-length=100 +--break-after-logical + +--pad-comma +--pad-oper +--unpad-paren + +--break-blocks +--pad-header diff --git a/vendor/gocv.io/x/gocv/.gitignore b/vendor/gocv.io/x/gocv/.gitignore new file mode 100644 index 00000000..adf29f1c --- /dev/null +++ b/vendor/gocv.io/x/gocv/.gitignore @@ -0,0 +1,12 @@ +profile.cov +count.out +*.swp +*.snap +/parts +/prime +/stage +.vscode/ +/build +.idea/ +contrib/data.yaml +contrib/testOilPainting.png diff --git a/vendor/gocv.io/x/gocv/CHANGELOG.md b/vendor/gocv.io/x/gocv/CHANGELOG.md new file mode 100644 index 00000000..1284d0cc --- /dev/null +++ b/vendor/gocv.io/x/gocv/CHANGELOG.md @@ -0,0 +1,1090 @@ +0.33.0 +--- +* **bugfix** + * Remove opencv2/aruco.hpp include +* **all** + * build performance tests with all OpenCV builds +* **build** + * build and push Ubuntu 22.04 base image with OpenCV 4.7.0 + * docker images with opencv + * docker production images with opencv 4.7.0 + * Docker push to GHCR +* **core** + * Add ReduceArgMax and ReduceArgMin +* **dnn** + * improved NMSBoxes code +* **docker** + * add dockerfile for Ubuntu 22.04 OpenCV base image + * updates to migrate to GHCR +* **examples** + * Deallocate Mats in feature-matching example. + * Fix G108 (CWE-200) and G114 (CWE-676) + * Fix G304 (CWE-22) and G307 (CWE-703) + * Fix G304 (CWE-22) and G307 (CWE-703) + * Missed #nosec tag +* **make** + * Ubuntu Jammy (22) opencv build support. + + +0.32.0 +--- +* **all** + * update to OpenCV 4.7.0 +* **core** + * Add the number of thread setter and getter +* **calib3d** + * add EstimateAffinePartial2DWithParams() +* **imgcodecs** + * Add IMDecodeIntoMat to reduce heap allocations (#1035) +* **imgproc** + * add matchShapes function support +* **objdetect** + * move aruco from contrib and also refactor/update to match current OpenCV API +* **photo** + * add inpaint function +* **video** + * cv::KalmanFilter bindings. +* **cuda** + * add support for cuda::TemplateMatching +* **docker** + * update all dockerfiles for OpenCV 4.7.0/GoCV 0.32.0 + * multiplatform for both amd64 and arm64 + * install libjpeg-turbo into docker image + * add Ubunutu 18.04 and 20.04 prebuilt OpenCV images + * add dockerfile for older version of CUDA for those who cannot upgrade +* **ci** + * remove circleci + * correct actions that trigger build +* **make** + * change download path for OpenCV release tag +* **windows** + * Update win_build_opencv.cmd +* **docs** + * correct docs on building docker + * update ROADMAP + * typo in comment + * update comments style with gofmt +* **openvino** + * Add openvino Dockerfile + * Fix OpenvinoVersion dangling pointer + * Update env.sh and README.md for 2022.1 + +0.31.0 +--- +* **all** + * update to OpenCV 4.6.0 +* **build** + * Switch to Github Actions for Linux CI build + * Use go -tags static when verifying static build +* **core** + * Add Mat.ElemSize (#964) + * avoid index out of range panic in NewPointsVectorFromPoints +* **video** + * add findTransformECC function +* **contrib/ximgproc** + * add PeiLinNormalization() function + * add anisotropicDiffusion() function + * implement edgePreservingFilter() + * implement niBlackThreshold and thinning filters + +0.30.0 +--- +* **all** + * update to OpenCV 4.5.5 +* **build** + * add install_nonfree make task to build all opencv_contrib modules + * correct download location for onnx test file + * Update Makefile for missing version changes +* **core** + * correct how memory is being allocated for Eye(), Zeros(), and Ones() to address issue #930 +* **calib3d** + * Adding support for estimateAffine2DWithParams (#924) +* **imgproc** + * Add DrawContoursWithParams function +* **photo** + * Add bindings for fastNlMeansDenoising and fastNlMeansDenoisingColored + * add detailEnhance function + * add EdgePreservingFilter function + * add PencilSketch function + * add stylization function +* **docs** + * add godoc comments for FastNlMeansDenoising functions + * update README with info on latest mingw-w64 t use for Windows builds + * dnn pose detect examples correct the order of the argument variable name +* **examples** + * Fixed memory leaks in the motion detection example +* **openvino** + * Update env.sh and README.md +* **windows** + * use mingw-w64 8.1.0 for protobuf compile +* **contrib** + * add cv::wechat_qrcode::WeChatQRCode (#949) + * Update cgo_static.go + +0.29.0 +--- +* **all** + * update to OpenCV 4.5.4 +* **build** + * add static build ability on windows + * use tbb for all builds for CPU accelerated operations +* **cuda** + * implement a bunch of per-element operations + * add get/set/reset device functions + * add NewGpuMatWithSize() to preallocate device memory + * Reshape() returns a new GpuMat with the changed data + * correct use of Stream by adding WaitForCompletion() and passing pre-allocated GpuMats +* **docs** + * update ROADMAP from recent contributions +* **videoio** + * Fix open video capture with api test (#895) +* **calib3d** + * added EstimateAffine2D + * findChessboardCornersSB +* **aruco** + * added many functions as part of initial implementation + +0.28.0 +--- +* **all** + * update to OpenCV 4.5.3 + * make task and build tag for static build of OpenCV/GoCV on Linux + * add Makefile tasks for OpenCV install on Nvidia Jetson + * add gotest for more colorful test output running tests from containers +* **build** + * correcting output format for code coverage report + * enforce rule that all Go code is correctly formatted + * remove codecov +* **core** + * add NewPointVectorFromMat() and NewPoint2fVectorFromMat() functions + * Fix possible MatProfile race by ordering remove before free. +* **cuda** + * add core functions for GpuMat like Cols(), Rows(), and Type() + * initial implementation for the Flip function +* **docs** + * update ROADMAP from recent contributions +* **examples** + * correct list of examples and fix comment +* **features2d** + * Add NewORBWithParams +* **tracking** + * change MOSSE to KCF +* **highgui** + * Add function CreateTrackbarWithValue to Window type. +* **imgcodec** + * optimize IMEncode avoiding multiple data copies. +* **imgproc** + * Add CircleWithParams function + * Add DilateWithParams() function (#827) + * Add EllipseWithParams function + * Add FillPolyWithParams function + * Add PointPolygonTest function + * Add RectangleWithParams function +* **photo** + * add MergeMertens, AlignMTB and Denoising function (#848) +* **xphoto** + * Add Xphoto contrib (#844) + +0.27.0 +--- +* **all** + * update to OpenCV 4.5.2 +* **core** + * add Append() to PointsVector/PointVector + * add cv::RNG + * add implementation for Point2fVector + * add rand functions + * add test coverage for PointsVector + * create new PointsVector/PointVector wrappers to avoid repetitive memory copying for seeming innocent operations involving slices of image.Point + * test coverage for Point2f + * use PointVector for everything that we can to speed up pipeline when passing around Point vectors + * use enum instead of int for Invert Method +* **cuda** + * adding HoughLinesDetector and HoughSegmentDetector + * adding tests for the CannyEdgeDetector + * some refactoring of the API + * adding dockerfiles for OpenCV 4.5.2 with CUDA 11.2 + * add GaussianFilter + * correct signature and test for Threshold + * implement SobelFilter + * move arithm module functions into correct location + * rename files to get rid of so many cudas + * add abs function implementation +* **dnn** + * increase test coverage +* **docker** + * make all Dockerfiles names/tags more consistent +* **docs** + * add CUDA functions that need implementation to ROADMAP + * remove invalid sections and add some missing functions from ROADMAP +* **imgproc** + * Add FindContoursWithParams function + * Add ToImageYUV and ToImageYUVWithParams +* **make** + * add make task to show changelog for next release +* **wechat_qrcode** + * disable module in Windows due to linker error + +0.26.0 +--- +* **all** + * update to OpenCV 4.5.1 +* **core** + * add Matrix initializers: eye, ones, zeros (#758) + * add multidimensional mat creation + * add ndim mat constructor + * added accumulators + * added norm call with two mats (#600) + * keep a reference to a []byte that backs a Mat. (#755) + * remove guard for DataPtrUint8 since any Mat can be treated an Uint8 + * add Mat IsContinuous() function, and ensure that any Mat data pointers used to create Go slices only apply to continuous Mats + * fix buffer size for Go strings for 32-bit operating systems +* **build** + * bring back codecov.io +* **calib3d** + * correctly close mat after test +* **dnn** + * add ReadNetFromONNX and ReadNetFromONNXBytes (#760) + * increase test coverage +* **docker** + * dockerfiles for opencv gpu builds +* **docs** + * corrected links to CUDA and OpenVINO + * list all unimplemented functions in photo module + * replace GoDocs with pkg docs + * update ROADMAP from recent contributions +* **imgproc** + * add test coverage for GetTextSizeWithBaseline() + * close all Mats even those based on memory slices + * close Mat to avoid memory leak in ToImage() + * refactoring of ToImage and ImageToMatXX functions +* **openvino** + * fix dldt repo in makefile for openvino +* **os** + * adding gcc-c++ package to rpm deps +* **photo** + * add SeamlessClone function +* **profile** + * add created mats in Split and ForwardLayers to profile (#780) + +0.25.0 +--- +* **all** + * update to opencv release 4.5.0 +* **build** + * add file dependencies needed for DNN tests + * add verbose output for tests on CircleCI + * also run unit tests on non-free algorithms. YMMV. + * fix build with cuda + * remove Travis and switch to CircleCI using Docker based builds + * update CI builds to Go 1.15 +* **core** + * add mixChannels() method to Mat (#746) + * Add toGoStrings helper + * support ConvertToWithParams method +* **dnn** + * Add NMSBoxes function (#736) + * Added ability to load Torch file. Tested features for extracting 128d vectors + * fix using wrong type for unconnectedlayertype + * use default ddepth for conversions to blob from image as recommended by @berak +* **docker** + * use separate dockerfile for opencv to avoid massive rebuild +* **docs** + * add recent contributions to ROADMAP and also add cuda functions still in need of implementation + * display CircleCI badge in README + * minor improvements to CUDA docs in READMEs +* **features2d** + * add FlannBasedMatcher + * add drawmatches (#720) + * fix memory leak in SIFT +* **highgui** + * refactored ROI methods +* **imgproc** + * Add option to return baseline with GetTextSizeWithBaseline +* **objdetect** + * Add QRCode DetectAndDecodeMulti +* **videoio** + * Add video capture properties and set preferred api backend (#739) + * fix needed as discussed in golang/go issue #32479 + +0.24.0 +--- +* **all** + * update Makefile and READMEChange constants and corresponding function signatures to have the correct types (#689) + * replace master branch terminology with release + * update to OpenCV 4.4.0 +* **calib3d** + * add FindHomography() + * add function EstimateAffinePartial2D() + * add GetAffineTransform() and GetAffineTransform2f() + * add UndistortPoints(), FisheyeUndistortPoints() and EstimateNewCameraMatrixForUndistortRectify() +* **core** + * add MultiplyWithParams +* **docs** + * add recent contributions to ROADMAP + * create CODE_OF_CONDUCT.md + * update copyright year +* **features2d** + * close returned Mat from SIFT algorithm + * fix issue 707 with DrawKeyPoints + * SIFT patent now expired so is part of main OpenCV modules +* **imgproc** + * change struct to remove GNU old-style field designator extension warning + +0.23.0 +--- +* **build** + * update Makefile and README + * update to use go1.14 +* **calib3d** + * add draw chessboard +* **core** + * fix memory leak in Mat.Size() and Mat.Split() (#580) +* **cuda** + * add build support + * add cuda backend/target + * add support for: + * cv::cuda::CannyEdgeDetector + * cv::cuda::CascadeClassifier Class + * cv::cuda::HOG Class + * remove breaking case statement +* **dnn** + * avoid parallel test runs + * remove attempt at providing grayscale image blog conversion that uses mean adjustment +* **docker** + * docker file last command change (#505) +* **docs** + * add recent contributions to ROADMAP +* **imgproc** + * add ErodeWithParams function + * add getGaussianKernel function + * add Go Point2f type and update GetPerspectiveTransform() (#589) + * add PhaseCorrelate binding (#626) + * added Polylines feature + * do not free contours data until after we have drawn the needed contours + * Threshold() should return a value (#620) +* **make** + * added raspberry pi zero support to the makefile +* **opencv** + * update to OpenCV 4.3.0 +* **openvino** + * add build support +* **windows** + * add cmake flag for allocator stats counter type to avoid opencv issue #16398 + +0.22.0 +--- +* **bgsegm** + * Add BackgroundSubtractorCNT +* **calib3d** + * Added undistort function (#520) +* **core** + * add functions (singular value decomposition, multiply between matrices, transpose matrix) (#559) + * Add new funcs (#578) + * add setIdentity() method to Mat + * add String method (#552) + * MatType: add missing constants +* **dnn** + * Adding GetLayerNames() + * respect the bit depth of the input image to set the expected output when converting an image to a blob +* **doc** + * change opencv version 3.x to 4.x +* **docker** + * use Go1.13.5 for image +* **imgcodecs** + * Fix webp image decode error (#523) +imgcodecs: optimize copy of data used for IMDecode method +* **imgproc** + * Add GetRectSubPix + * Added ClipLine + * Added InvertAffineTransform + * Added LinearPolar function (#524) + * correct ksize param used for MedianBlur unit test + * Feature/put text with line type (#527) + * FitEllipse + * In FillPoly and DrawContours functions, remove func() wrap to avoid memory freed before calling opencv functions. (#543) +* **objdetect** + * Add support QR codes +* **opencv** + * update to OpenCV 4.2.0 release +* **openvino** + * Add openvino async +* **test** + * Tolerate imprecise result in SolvePoly + * Tolerate imprecision in TestHoughLines + +0.21.0 +--- +* **build** + * added go clean --cache to clean target, see issue 458 +* **core** + * Add KMeans function + * added MeanWithMask function for Mats (#487) + * Fix possible resource leak +* **cuda** + * added cudaoptflow + * added NewGpuMatFromMat which creates a GpuMat from a Mat + * Support for CUDA Image Warping (#494) +* **dnn** + * add BlobFromImages (#467) + * add ImagesFromBlob (#468) +* **docs** + * update ROADMAP with all recent contributions. Thank you! +* **examples** + * face detection from image url by using IMDecode (#499) + * better format +* **imgproc** + * Add calcBackProject + * Add CompareHist + * Add DistanceTransform and Watershed + * Add GrabCut + * Add Integral + * Add MorphologyExWithParams +* **opencv** + * update to version 4.1.2 +* **openvino** + * updates needed for 2019 R3 +* **videoio** + * Added ToCodec to convert FOURCC string to numeric representation (#485) + +0.20.0 +--- +* **build** + * Use Go 1.12.x for build + * Update to OpenCV 4.1.0 +* **cuda** + * Initial cuda implementation +* **docs** + * Fix the command to install xquartz via brew/cask +* **features2d** + * Add support for SimpleBlobDetectorParams (#434) + * Added FastFeatureDetectorWithParams +* **imgproc** + * Added function call to cv::morphologyDefaultBorderValue +* **test** + * Increase test coverage for FP16BlobFromImage() +* **video** + * Added calcOpticalFlowPyrLKWithParams + * Addition of MOG2/KNN constructor with options + +0.19.0 +--- +* **build** + * Adds Dockerfile. Updates Makefile and README. + * make maintainer tag same as dockerhub organization name + * make sure to run tests for non-free contrib algorithms + * update Appveyor build to use Go 1.12 +* **calib3d** + * add func InitUndistortRectifyMap (#405) +* **cmd** + * correct formatting of code in example +* **core** + * Added Bitwise Operations With Masks + * update to OpenCV4.0.1 +* **dnn** + * add new backend and target types for NVIDIA and FPGA + * Added blobFromImages in ROADMAP.md (#403) + * Implement dnn methods for loading in-memory models. +* **docker** + * update Dockerfile to use OpenCV 4.0.1 +* **docs** + * update ROADMAP from recent contributions +* **examples** + * Fixing filename in caffe-classifier example +* **imgproc** + * Add 'MinEnclosingCircle' function + * added BoxPoints function and BorderIsolated const + * Added Connected Components + * Added the HoughLinesPointSet function. + * Implement CLAHE to imgproc +* **openvino** + * remove lib no longer included during non-FPGA installations +* **test** + * Add len(kp) == 232 to TestMSER, seems this is necessary for MacOS for some reason. + +0.18.0 +--- +* **build** + * add OPENCV_GENERATE_PKGCONFIG flag to generate pkg-config file + * Add required curl package to the RPM and DEBS + * correct name for zip directory used for code download + * Removing linking against face contrib module + * update CI to use 4.0.0 release + * update Makefile and Windows build command file to OpenCV 4.0.0 + * use opencv4 file for pkg-config +* **core** + * add ScaleAdd() method to Mat +* **docs** + * replace OpenCV 3.4.3 references with OpenCV 4 + * update macOS installation info to refer to new OpenCV 4.0 brew + * Updated function documentation with information about errors. +* **examples** + * Improve accuracy in hand gesture sample +* **features2d** + * update drawKeypoints() to use new stricter enum +* **openvino** + * changes to accommodate release 2018R4 +* **profile** + * add build tag matprofile to allow for conditional inclusion of custom profile + * Add Mat profile wrapper in other areas of the library. + * Add MatProfile. + * Add MatProfileTest. + * move MatProfile tests into separate test file so they only run when custom profiler active +* **test** + * Close images in tests. + * More Closes in tests. + * test that we are using 4.0.x version now +* **videoio** + * Return the right type and error when opening VideoCapture fails + +0.17.0 +--- +* **build** + * Update Makefile + * update version of OpenCV used to 3.4.3 + * use link to OpenCV 3.4.3 for Windows builds +* **core** + * add mulSpectrums wrapper + * add PolarToCart() method to Mat + * add Reduce() method to Mat + * add Repeat() method to Mat + * add Solve() method to Mat + * add SolveCubic() method to Mat + * add SolvePoly() method to Mat + * add Sort() method to Mat + * add SortIdx() method to Mat + * add Trace() method to Mat + * Added new MatType + * Added Phase function +* **dnn** + * update test to match OpenCV 3.4.3 behavior +* **docs** + * Add example of how to run individual test + * adding instructions for installing pkgconfig for macOS + * fixed GOPATH bug. + * update ROADMAP from recent contributions +* **examples** + * add condition to handle no circle found in circle detection example +* **imgcodecs** + * Added IMEncodeWithParams function +* **imgproc** + * Added Filter2D function + * Added fitLine function + * Added logPolar function + * Added Remap function + * Added SepFilter2D function + * Added Sobel function + * Added SpatialGradient function +* **xfeatures2d** + * do not run SIFT test unless OpenCV was built using OPENCV_ENABLE_NONFREE + * do not run SURF test unless OpenCV was built using OPENCV_ENABLE_NONFREE + +0.16.0 +--- +* **build** + * add make task for Raspbian install with ARM hardware optimizations + * use all available cores to compile OpenCV on Windows as discussed in issue #275 + * download performance improvements for OpenCV installs on Windows + * correct various errors and issues with OpenCV installs on Fedora and CentOS +* **core** + * correct spelling error in constant to fix issue #269 + * implemented & added test for Mat.SetTo + * improve Multiply() GoDoc and test showing Scalar() multiplication + * mutator functions for Mat add, subtract, multiply, and divide for uint8 and float32 values. +* **dnn** + * add FP16BlobFromImage() function to convert an image Mat to a half-float aka FP16 slice of bytes +* **docs** + * fix a varible error in example code in README + +0.15.0 +--- +* **build** + * add max to make -j + * improve path for Windows to use currently configured GOPATH +* **core** + * Add Mat.DataPtr methods for direct access to OpenCV data + * Avoid extra copy in Mat.ToBytes + code review feedback +* **dnn** + * add test coverage for ParseNetBackend and ParseNetTarget + * complete test coverage +* **docs** + * minor cleanup of language for install + * use chdir instead of cd in Windows instructions +* **examples** + * add 'hello, video' example to repo + * add HoughLinesP example + * correct message on device close to match actual event + * small change in display message for when file is input source + * use DrawContours in motion detect example +* **imgproc** + * Add MinAreaRect() function +* **test** + * filling test coverage gaps +* **videoio** + * add test coverage for OpenVideoCapture + +0.14.0 +--- +* **build** + * Add -lopencv_calib3d341 to the linker + * auto-confirm on package installs from make deps command + * display PowerShell download status for OpenCV files + * obtain caffe test config file from new location in Travis build + * remove VS only dependencies from OpenCV build, copy caffe test config file from new location + * return back to GoCV directory after OpenCV install + * update for release of OpenCV v3.4.2 + * use PowerShell for scripted OpenCV install for Windows + * win32 version number has not changed yet +* **calib3d** + * Add Calibrate for Fisheye model(WIP) +* **core** + * add GetTickCount function + * add GetTickFrequency function + * add Size() and FromPtr() methods to Mat + * add Total method to Mat + * Added RotateFlag type + * correct CopyTo to use pointer to Mat as destination + * functions converting Image to Mat + * rename implementation to avoid conflicts with Windows + * stricter use of reflect.SliceHeader +* **dnn** + * add backend/device options to caffe and tensorflow DNN examples + * add Close to Layer + * add first version of dnn-pose-detection example + * add further comments to object detection/tracking DNN example + * add GetPerfProfile function to Net + * add initial Layer implementation alongside enhancements to Net + * add InputNameToIndex to Layer + * add new functions allowing DNN backends such as OpenVINO + * additional refactoring and comments in dnn-pose-detection example + * cleanup DNN face detection example + * correct const for device targets to be called Target + * correct test that expected init slice with blank entries + * do not init slice with blank entries, since added via append + * further cleanup of DNN face detection example + * make dnn-pose-detection example use Go channels for async operation + * refactoring and additional comments for object detection/tracking DNN example + * refine comment in header for style transfer example + * working style transfer example + * added ForwardLayers() to accomodate models with multiple output layers +* **docs** + * add scripted Windows install info to README + * Added a sample gocv workflow contributing guideline + * mention docker image in README. + * mention work in progress on Android + * simplify and add missing step in Linux installation in README + * update contributing instructions to match latest version + * update ROADMAP from recent calib3d module contribution + * update ROADMAP from recent imgproc histogram contribution +* **examples** + * cleanup header for caffe dnn classifier + * show how to use either Caffe or Tensorflow for DNN object detection + * further improve dnn samples + * rearrange and add comments to dnn style transfer example + * remove old copy of pose detector + * remove unused example +* **features2d** + * free memory allocation bug for C.KeyPoints as pointed out by @tzununbekov + * Adding opencv::drawKeypoints() support +* **imgproc** + * add equalizeHist function + * Added opencv::calcHist implementation +* **openvino** + * add needed environment config to execute examples + * further details in README explaining how to use + * remove opencv contrib references as they are not included in OpenVINO +* **videoio** + * Add OpenVideoCapture + * Use gocv.VideoCaptureFile if string is specified for device. + +0.13.0 +--- +* **build** + * Add cgo directives to contrib + * contrib subpackage also needs cpp 11 or greater for a warning free build on Linux + * Deprecate env scripts and update README + * Don't set --std=c++1z on non-macOS + * Remove CGO vars from CI and correct Windows cgo directives + * Support pkg-config via cgo directives + * we actually do need cpp 11 or greater for a warning free build on Linux +* **docs** + * add a Github issue template to project + * provide specific examples of using custom environment +* **imgproc** + * add HoughLinesPWithParams() function +* **openvino** + * add build tag specific to openvino + * add roadmap info + * add smoke test for ie + +0.12.0 +--- +* **build** + * convert to CRLF + * Enable verbosity for travisCI + * Further improvements to Makefile +* **core** + * Add Rotate, VConcat + * Adding InScalarRange and NewMatFromScalarWithSize functions + * Changed NewMatFromScalarWithSize to NewMatWithSizeFromScalar + * implement CheckRange(), Determinant(), EigenNonSymmetric(), Min(), and MinMaxIdx() functions + * implement PerspectiveTransform() and Sqrt() functions + * implement Transform() and Transpose() functions + * Make toByteArray safe for empty byte slices + * Renamed InScalarRange to InRangeWithScalar +* **docs** + * nicer error if we can't read haarcascade_frontalface_default + * correct some ROADMAP links + * Fix example command. + * Fix executable name in help text. + * update ROADMAP from recent contributions +* **imgproc** + * add BoxFilter and SqBoxFilter functions + * Fix the hack to convert C arrays to Go slices. +* **videoio** + * Add isColor to VideoWriterFile + * Check numerical parameters for gocv.VideoWriterFile + * CodecString() +* **features2d** + * add BFMatcher +* **img_hash** + * Add contrib/img_hash module + * add GoDocs for new img_hash module + * Add img-similarity as an example for img_hash +* **openvino** + * adds support for Intel OpenVINO toolkit PVL + * starting experimental work on OpenVINO IE + * update README files for Intel OpenVINO toolkit support + * WIP on IE can load an IR network + +0.11.0 +--- +* **build** + * Add astyle config + * Astyle cpp/h files + * remove duplication in Makefile for astyle +* **core** + * Add GetVecfAt() function to Mat + * Add GetVeciAt() function to Mat + * Add Mat.ToImage() + * add MeanStdDev() method to Mat + * add more functions + * Compare Mat Type directly + * further cleanup for GoDocs and enforce type for convariance operations + * Make borderType in CopyMakeBorder be type BorderType + * Mat Type() should return MatType + * remove unused convenience functions + * use Mat* to indicate when a Mat is mutable aka an output parameter +* **dnn** + * add a ssd sample and a GetBlobChannel helper + * added another helper func and a pose detection demo +* **docs** + * add some additional detail about adding OpenCV functions to GoCV + * updates to contribution guidelines + * fill out complete list of needed imgproc functions for sections that have work started + * indicate that missing imgproc functions need implementation + * mention the WithParams patterns to be used for functions with default params + * update README for the Mat* based API changes + * update ROADMAP for recent changes especially awesome recent core contributions from @berak +* **examples** + * Fix tf-classifier example + * move new DNN advanced examples into separate folders + * Update doc for the face contrib package + * Update links in caffe-classifier demo + * WIP on hand gestures tracking example +* **highgui** + * fix constant in NewWindow +* **imgproc** + * Add Ellipse() and FillPoly() functions + * Add HoughCirclesWithParams() func + * correct output Mat to for ConvexHull() + * rename param being used for Mat image to be modified +* **tracking** + * add support for TrackerMIL, TrackerBoosting, TrackerMedianFlow, TrackerTLD, TrackerKCF, TrackerMOSSE, TrackerCSRT trackers + * removed mutitracker, added Csrt, rebased + * update GoDocs and minor renaming based on gometalint output + +0.10.0 +--- +* **build** + * install unzip before build + * overwrite when unzipping file to install Tensorflow test model + * use -DCPU_DISPATCH= flag for build to avoid problem with disabled AVX on Windows + * update unzipped file when installing Tensorflow test model +* **core** + * add Compare() and CountNonZero() functions + * add getter/setter using optional params for multi-dimensional Mat using row/col/channel + * Add mat subtract function + * add new toRectangle function to DRY up conversion from CRects to []image.Rectangle + * add split subtract sum wrappers + * Add toCPoints() helper function + * Added Mat.CopyToWithMask() per #47 + * added Pow() method + * BatchDistance BorderInterpolate CalcCovarMatrix CartToPolar + * CompleteSymm ConvertScaleAbs CopyMakeBorder Dct + * divide, multiply + * Eigen Exp ExtractChannels + * operations on a 3d Mat are not same as a 2d multichannel Mat + * resolve merge conflict with duplicate Subtract() function + * run gofmt on core tests + * Updated type for Mat.GetUCharAt() and Mat.SetUCharAt() to reflect uint8 instead of int8 +* **docs** + * update ROADMAP of completed functions in core from recent contributions +* **env** + * check loading resources + * Add distribution detection to deps rule + * Add needed environment variables for Linux +* **highgui** + * add some missing test coverage on WaitKey() +* **imgproc** + * Add adaptive threshold function + * Add pyrDown and pyrUp functions + * Expose DrawContours() + * Expose WarpPerspective and GetPerspectiveTransform + * implement ConvexHull() and ConvexityDefects() functions +* **opencv** + * update to OpenCV version 3.4.1 + +0.9.0 +--- +* **bugfix** + * correct several errors in size parameter ordering +* **build** + * add missing opencv_face lib reference to env.sh + * Support for non-brew installs of opencv on Darwin +* **core** + * add Channels() method to Mat + * add ConvertTo() and NewMatFromBytes() functions + * add Type() method to Mat + * implement ConvertFp16() function +* **dnn** + * use correct size for blob used for Caffe/Tensorflow tests +* **docs** + * Update copyright date and Apache 2.0 license to include full text +* **examples** + * cleanup mjpeg streamer code + * cleanup motion detector comments + * correct use of defer in loop + * use correct size for blob used for Caffe/Tensorflow examples +* **imgproc** + * Add cv::approxPolyDP() bindings. + * Add cv::arcLength() bindings. + * Add cv::matchTemplate() bindings. + * correct comment and link for Blur function + * correct docs for BilateralFilter() + +0.8.0 +--- +* **core** + * add ColorMapFunctions and their test + * add Mat ToBytes + * add Reshape and MinMaxLoc functions + * also delete points + * fix mistake in the norm function by taking NormType instead of int as parameter + * SetDoubleAt func and his test + * SetFloatAt func and his test + * SetIntAt func and his test + * SetSCharAt func and his test + * SetShortAt func and his test + * SetUCharAt fun and his test + * use correct delete operator for array of new, eliminates a bunch of memory leaks +* **dnn** + * add support for loading Tensorflow models + * adjust test for Caffe now that we are auto-cropping blob + * first pass at adding Caffe support + * go back to older function signature to avoid version conflicts with Intel CV SDK + * properly close DNN Net class + * use approx. value from test result to account forr windows precision differences +* **features2d** + * implement GFTTDetector, KAZE, and MSER algorithms + * modify MSER test for Windows results +* **highgui** + * un-deprecate WaitKey function needed for CLI apps +* **imgcodec** + * add fileExt type +* **imgproc** + * add the norm wrapper and use it in test for WarpAffine and WarpAffineWithParams + * GetRotationMatrix2D, WarpAffine and WarpAffineWithParams + * use NormL2 in wrap affine +* **pvl** + * add support for FaceRecognizer + * complete wrappers for all missing FaceDetector functions + * update instructions to match R3 of Intel CV SDK +* **docs** + * add more detail about exactly which functions are not yet implememented in the modules that are marked as 'Work Started' + * add refernece to Tensorflow example, and also suggest brew upgrade for MacOS + * improve ROADMAP to help would-be contributors know where to get started + * in the readme, explain compiling to a static library + * remove many godoc warnings by improving function descriptions + * update all OpenCV 3.3.1 references to v3.4.0 + * update CGO_LDFLAGS references to match latest requirements + * update contribution guidelines to try to make it more inviting +* **examples** + * add Caffe classifier example + * add Tensorflow classifier example + * fixed closing window in examples in infinite loop + * fixed format of the examples with gofmt +* **test** + * add helper function for test : floatEquals + * add some attiribution from test function + * display OpenCV version in case that test fails + * add round function to allow for floating point accuracy differences due to GPU usage. +* **build** + * improve search for already installed OpenCV on MacOS + * update Appveyor build to Opencv 3.4.0 + * update to Opencv 3.4.0 + +0.7.0 +--- +* **core** + * correct Merge implementation +* **docs** + * change wording and formatting for roadmap + * update roadmap for a more complete list of OpenCV functionality + * sequence docs in README in same way as the web site, aka by OS + * show in README that some work was done on contrib face module +* **face** + * LBPH facerecognizer bindings +* **highgui** + * complete implementation for remaining API functions +* **imgcodecs** + * add IMDecode function +* **imgproc** + * elaborate on HoughLines & HoughLinesP tests to fetch a few individual results +* **objdetect** + * add GroupRectangles function +* **xfeatures2d** + * add SIFT and SURF algorithms from OpenCV contrib + * improve description for OpenCV contrib + * run tests from OpenCV contrib + +0.6.0 +--- +* **core** + * Add cv::LUT binding +* **examples** + * do not try to go fullscreen, since does not work on OSX +* **features2d** + * add AKAZE algorithm + * add BRISK algorithm + * add FastFeatureDetector algorithm + * implement AgastFeatureDetector algorithm + * implement ORB algorithm + * implement SimpleBlobDetector algorithm +* **osx** + * Fix to get the OpenCV path with "brew info". +* **highgui** + * use new Window with thread lock, and deprecate WaitKey() in favor of Window.WaitKey() + * use Window.WaitKey() in tests +* **imgproc** + * add tests for HoughCircles +* **pvl** + * use correct Ptr referencing +* **video** + * use smart Ptr for Algorithms thanks to @alalek + * use unsafe.Pointer for Algorithm + * move tests to single file now that they all pass + +0.5.0 +--- +* **core** + * add TermCriteria for iterative algorithms +* **imgproc** + * add CornerSubPix() and GoodFeaturesToTrack() for corner detection +* **objdetect** + * add DetectMultiScaleWithParams() for HOGDescriptor + * add DetectMultiScaleWithParams() to allow override of defaults for CascadeClassifier +* **video** + * add CalcOpticalFlowFarneback() for Farneback optical flow calculations + * add CalcOpticalFlowPyrLK() for Lucas-Kanade optical flow calculations +* **videoio** + * use temp directory for Windows test compat. +* **build** + * enable Appveyor build w/cache +* **osx** + * update env path to always match installed OpenCV from Homebrew + +0.4.0 +--- +* **core** + * Added cv::mean binding with single argument + * fix the write-strings warning + * return temp pointer fix +* **examples** + * add counter example + * add motion-detect command + * correct counter + * remove redundant cast and other small cleanup + * set motion detect example to fullscreen + * use MOG2 for continous motion detection, instead of simplistic first frame only +* **highgui** + * ability to better control the fullscreen window +* **imgproc** + * add BorderType param type for GaussianBlur + * add BoundingRect() function + * add ContourArea() function + * add FindContours() function along with associated data types + * add Laplacian and Scharr functions + * add Moments() function + * add Threshold function +* **pvl** + * add needed lib for linker missing in README +* **test** + * slightly more permissive version test +* **videoio** + * Add image compression flags for gocv.IMWrite + * Fixed possible looping out of compression parameters length + * Make dedicated function to run cv::imwrite with compression parameters + +0.3.1 +--- +* **overall** + * Update to use OpenCV 3.3.1 + +0.3.0 +--- +* **docs** + * Correct Windows build location from same @jpfarias fix to gocv-site +* **core** + * Add Resize + * Add Mat merge and Discrete Fourier Transform + * Add CopyTo() and Normalize() + * Implement various important Mat logical operations +* **video** + * BackgroundSubtractorMOG2 algorithm now working + * Add BackgroundSubtractorKNN algorithm from video module +* **videoio** + * Add VideoCapture::get +* **imgproc** + * Add BilateralFilter and MedianBlur + * Additional drawing functions implemented + * Add HoughCircles filter + * Implement various morphological operations +* **highgui** + * Add Trackbar support +* **objdetect** + * Add HOGDescriptor +* **build** + * Remove race from test on Travis, since it causes CGo segfault in MOG2 + +0.2.0 +--- +* Switchover to custom domain for package import +* Yes, we have Windows + +0.1.0 +--- +Initial release! + +- [X] Video capture +- [X] GUI Window to display video +- [X] Image load/save +- [X] CascadeClassifier for object detection/face tracking/etc. +- [X] Installation instructions for Ubuntu +- [X] Installation instructions for OS X +- [X] Code example to use VideoWriter +- [X] Intel CV SDK PVL FaceTracker support +- [X] imgproc Image processing +- [X] Travis CI build +- [X] At least minimal test coverage for each OpenCV class +- [X] Implement more of imgproc Image processing \ No newline at end of file diff --git a/vendor/gocv.io/x/gocv/CODE_OF_CONDUCT.md b/vendor/gocv.io/x/gocv/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..aea8fed2 --- /dev/null +++ b/vendor/gocv.io/x/gocv/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at info@hybridgroup.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/vendor/gocv.io/x/gocv/CONTRIBUTING.md b/vendor/gocv.io/x/gocv/CONTRIBUTING.md new file mode 100644 index 00000000..2357ed72 --- /dev/null +++ b/vendor/gocv.io/x/gocv/CONTRIBUTING.md @@ -0,0 +1,136 @@ +# How to contribute + +Thank you for your interest in improving GoCV. + +We would like your help to make this project better, so we appreciate any contributions. See if one of the following descriptions matches your situation: + +### Newcomer to GoCV, to OpenCV, or to computer vision in general + +We'd love to get your feedback on getting started with GoCV. Run into any difficulty, confusion, or anything else? You are not alone. We want to know about your experience, so we can help the next people. Please open a Github issue with your questions, or get in touch directly with us. + +### Something in GoCV is not working as you expect + +Please open a Github issue with your problem, and we will be happy to assist. + +### Something you want/need from OpenCV does not appear to be in GoCV + +We probably have not implemented it yet. Please take a look at our [ROADMAP.md](ROADMAP.md). Your pull request adding the functionality to GoCV would be greatly appreciated. + +### You found some Python code on the Internet that performs some computer vision task, and you want to do it using GoCV + +Please open a Github issue with your needs, and we can see what we can do. + +## How to use our Github repository + +The `release` branch of this repo will always have the latest released version of GoCV. All of the active development work for the next release will take place in the `dev` branch. GoCV will use semantic versioning and will create a tag/release for each release. + +Here is how to contribute back some code or documentation: + +- Fork repo +- Create a feature branch off of the `dev` branch +- Make some useful change +- Submit a pull request against the `dev` branch. +- Be kind + +## How to add a function from OpenCV to GoCV + +Here are a few basic guidelines on how to add a function from OpenCV to GoCV: + +- Please open a Github issue. We want to help, and also make sure that there is no duplications of efforts. Sometimes what you need is already being worked on by someone else. +- Use the proper Go style naming `MissingFunction()` for the Go wrapper. +- Make any output parameters `Mat*` to indicate to developers that the underlying OpenCV data will be changed by the function. +- Use Go types when possible as parameters for example `image.Point` and then convert to the appropriate OpenCV struct. Also define a new type based on `int` and `const` values instead of just passing "magic numbers" as params. For example, the `VideoCaptureProperties` type used in `videoio.go`. +- Always add the function to the GoCV file named the same as the OpenCV module to which the function belongs. +- If the new function is in a module that is not yet implemented by GoCV, a new set of files for that module will need to be added. +- Always add a "smoke" test for the new function being added. We are not testing OpenCV itself, but just the GoCV wrapper, so all that is needed generally is just exercising the new function. +- If OpenCV has any default params for a function, we have been implementing 2 versions of the function since Go does not support overloading. For example, with a OpenCV function: + +```c +opencv::xYZ(int p1, int p2, int p3=2, int p4=3); +``` + +We would define 2 functions in GoCV: + +```go +// uses default param values +XYZ(p1, p2) + +// sets each param +XYZWithParams(p2, p2, p3, p4) +``` + +## How to run tests + +To run the tests: + +``` +go test . +go test ./contrib/. +``` + +If you want to run an individual test, you can provide a RegExp to the `-run` argument: +``` +go test -run TestMat +``` + +If you are using Intel OpenVINO, you can run those tests using: + +``` +go test ./openvino/... +``` + +## Contributing workflow + +This section provides a short description of one of many possible workflows you can follow to contribute to `GoCV`. This workflow is based on multiple [git remotes](https://git-scm.com/docs/git-remote) and it's by no means the only workflow you can use to contribute to `GoCV`. However, it's an option that might help you get started quickly without too much hassle as this workflow lets you work off the `gocv` repo directory path! + +Assuming you have already forked the `gocv` repo, you need to add a new `git remote` which will point to your GitHub fork. Notice below that you **must** `cd` to `gocv` repo directory before you add the new `git remote`: + +```shell +cd $GOPATH/src/gocv.io/x/gocv +git remote add gocv-fork https://github.com/YOUR_GH_HANDLE/gocv.git +``` + +Note, that in the command above we called our new `git remote`, **gocv-fork** for convenience so we can easily recognize it. You are free to choose any remote name of your liking. + +You should now see your new `git remote` when running the command below: + +```shell +git remote -v + +gocv-fork https://github.com/YOUR_GH_HANDLE/gocv.git (fetch) +gocv-fork https://github.com/YOUR_GH_HANDLE/gocv.git (push) +origin https://github.com/hybridgroup/gocv (fetch) +origin https://github.com/hybridgroup/gocv (push) +``` + +Before you create a new branch from `dev` you should fetch the latests commits from the `dev` branch: + +```shell +git fetch origin dev +``` + +You want the `dev` branch in your `gocv` fork to be in sync with the `dev` branch of `gocv`, so push the earlier fetched commits to your GitHub fork as shown below. Note, the `-f` force switch might not be needed: + +```shell +git push gocv-fork dev -f +``` + +Create a new feature branch from `dev`: + +```shell +git checkout -b new-feature +``` + +After you've made your changes you can run the tests using the `make` command listed below. Note, you're still working off the `gocv` project root directory, hence running the command below does not require complicated `$GOPATH` rewrites or whatnot: + +```shell +make test +``` + +Once the tests have passed, commit your new code to the `new-feature` branch and push it to your fork running the command below: + +```shell +git push gocv-fork new-feature +``` + +You can now open a new PR from `new-feature` branch in your forked repo against the `dev` branch of `gocv`. diff --git a/vendor/gocv.io/x/gocv/Dockerfile b/vendor/gocv.io/x/gocv/Dockerfile new file mode 100644 index 00000000..3a87e51c --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile @@ -0,0 +1,12 @@ +# to build this docker image: +# docker build . +FROM ghcr.io/hybridgroup/opencv:4.7.0 + +ENV GOPATH /go + +COPY . /go/src/gocv.io/x/gocv/ + +WORKDIR /go/src/gocv.io/x/gocv +RUN go build -tags example -o /build/gocv_version -i ./cmd/version/ + +CMD ["/build/gocv_version"] diff --git a/vendor/gocv.io/x/gocv/Dockerfile-test b/vendor/gocv.io/x/gocv/Dockerfile-test new file mode 100644 index 00000000..652dc4c1 --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile-test @@ -0,0 +1,19 @@ +# To build: +# docker build -f Dockerfile-test -t gocv-test . +# +# To run tests: +# xhost + +# docker run -it --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix gocv-test-4.x +# xhost - +# +FROM ghcr.io/hybridgroup/opencv:4.7.0 AS gocv-test-4.7 + +ENV GOPATH /go + +COPY . /go/src/gocv.io/x/gocv/ + +WORKDIR /go/src/gocv.io/x/gocv + +RUN go install github.com/rakyll/gotest@latest + +ENTRYPOINT ["gotest", "-v", ".", "./contrib/..."] diff --git a/vendor/gocv.io/x/gocv/Dockerfile-test.gpu-cuda-10 b/vendor/gocv.io/x/gocv/Dockerfile-test.gpu-cuda-10 new file mode 100644 index 00000000..63af630a --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile-test.gpu-cuda-10 @@ -0,0 +1,18 @@ +# To build: +# docker build -f Dockerfile-test.gpu-cuda-10 -t gocv-test-gpu-cuda-10 . +# +# To run tests: +# docker run -it --rm --gpus all gocv-test-gpu-cuda-10 +# +FROM ghcr.io/hybridgroup/opencv:4.7.0-gpu-cuda-10 AS gocv-gpu-test-cuda-10 + +ENV GOPATH /go +ENV PATH="${PATH}:/go/bin" + +COPY . /go/src/gocv.io/x/gocv/ + +WORKDIR /go/src/gocv.io/x/gocv + +RUN go install github.com/rakyll/gotest@latest + +ENTRYPOINT ["gotest", "-v", "./cuda/..."] diff --git a/vendor/gocv.io/x/gocv/Dockerfile-test.gpu-cuda-11 b/vendor/gocv.io/x/gocv/Dockerfile-test.gpu-cuda-11 new file mode 100644 index 00000000..102a0dd8 --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile-test.gpu-cuda-11 @@ -0,0 +1,18 @@ +# To build: +# docker build -f Dockerfile-test.gpu-cuda-11 -t gocv-test-gpu-cuda-11 . +# +# To run tests: +# docker run -it --rm --gpus all gocv-test-gpu-cuda-11 +# +FROM ghcr.io/hybridgroup/opencv:4.7.0-gpu-cuda-11 AS gocv-gpu-test-cuda-11 + +ENV GOPATH /go +ENV PATH="${PATH}:/go/bin" + +COPY . /go/src/gocv.io/x/gocv/ + +WORKDIR /go/src/gocv.io/x/gocv + +RUN go install github.com/rakyll/gotest@latest + +ENTRYPOINT ["gotest", "-v", "./cuda/..."] diff --git a/vendor/gocv.io/x/gocv/Dockerfile-test.gpu-cuda-11.2.2 b/vendor/gocv.io/x/gocv/Dockerfile-test.gpu-cuda-11.2.2 new file mode 100644 index 00000000..b4701103 --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile-test.gpu-cuda-11.2.2 @@ -0,0 +1,18 @@ +# To build: +# docker build -f Dockerfile-test.gpu-cuda-11.2.2 -t gocv-test-gpu-cuda-11.2.2 . +# +# To run tests: +# docker run -it --rm --gpus all gocv-test-gpu-cuda-11.2.2 +# +FROM ghcr.io/hybridgroup/opencv:4.7.0-gpu-cuda-11.2.2 AS gocv-gpu-test-cuda-11 + +ENV GOPATH /go +ENV PATH="${PATH}:/go/bin" + +COPY . /go/src/gocv.io/x/gocv/ + +WORKDIR /go/src/gocv.io/x/gocv + +RUN go install github.com/rakyll/gotest@latest + +ENTRYPOINT ["gotest", "-v", "./cuda/..."] diff --git a/vendor/gocv.io/x/gocv/Dockerfile.gpu b/vendor/gocv.io/x/gocv/Dockerfile.gpu new file mode 100644 index 00000000..8d3348b6 --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile.gpu @@ -0,0 +1,12 @@ +# to build this docker image: +# docker build -f Dockerfile.gpu . +FROM ghcr.io/hybridgroup/opencv:4.7.0-gpu-cuda-11 AS gocv-gpu + +ENV GOPATH /go + +COPY . /go/src/gocv.io/x/gocv/ + +WORKDIR /go/src/gocv.io/x/gocv +RUN go build -tags cuda -o /build/gocv_cuda_version ./cmd/cuda/ + +CMD ["/build/gocv_cuda_version"] diff --git a/vendor/gocv.io/x/gocv/Dockerfile.opencv b/vendor/gocv.io/x/gocv/Dockerfile.opencv new file mode 100644 index 00000000..cf3425cb --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile.opencv @@ -0,0 +1,140 @@ +# OpenCV 4 prebuilt multiarchitecture image +# +# To build release: +# docker buildx build -f Dockerfile.opencv -t ghcr.io/hybridgroup/opencv:4.7.0 -t ghcr.io/hybridgroup/opencv:latest --platform=linux/arm64,linux/amd64 --push . +# +# To build prerelease: +# docker buildx build --build-arg OPENCV_VERSION="4.x" --build-arg OPENCV_FILE="https://github.com/opencv/opencv/archive/refs/heads/4.x.zip" --build-arg OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/refs/heads/4.x.zip" -f Dockerfile.opencv -t ghcr.io/hybridgroup/opencv:4.7.0-dev --platform=linux/arm64,linux/amd64 --push . + + +################### +# amd64 build stage +################### + +FROM --platform=linux/amd64 golang:1.20-buster AS opencv-base-amd64 +LABEL maintainer="hybridgroup" + +RUN apt-get update && apt-get install -y \ + git build-essential cmake pkg-config unzip libgtk2.0-dev \ + curl ca-certificates libcurl4-openssl-dev libssl-dev \ + libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev \ + libjpeg62-turbo-dev libpng-dev libtiff-dev libdc1394-22-dev nasm && \ + rm -rf /var/lib/apt/lists/* + +FROM --platform=linux/amd64 opencv-base-amd64 AS opencv-build-amd64 + +ARG OPENCV_VERSION="4.7.0" +ENV OPENCV_VERSION $OPENCV_VERSION + +ARG OPENCV_FILE="https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_FILE $OPENCV_FILE + +ARG OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_CONTRIB_FILE $OPENCV_CONTRIB_FILE + +RUN curl -Lo opencv.zip ${OPENCV_FILE} && \ + unzip -q opencv.zip && \ + curl -Lo opencv_contrib.zip ${OPENCV_CONTRIB_FILE} && \ + unzip -q opencv_contrib.zip && \ + rm opencv.zip opencv_contrib.zip + +RUN cd opencv-${OPENCV_VERSION} && \ + mkdir build && cd build && \ + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D WITH_IPP=OFF \ + -D WITH_OPENGL=OFF \ + -D WITH_QT=OFF \ + -D CMAKE_INSTALL_PREFIX=/usr/local \ + -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ + -D OPENCV_ENABLE_NONFREE=ON \ + -D WITH_JASPER=OFF \ + -D WITH_TBB=ON \ + -D BUILD_JPEG=ON \ + -D WITH_SIMD=ON \ + -D ENABLE_LIBJPEG_TURBO_SIMD=ON \ + -D BUILD_DOCS=OFF \ + -D BUILD_EXAMPLES=OFF \ + -D BUILD_TESTS=OFF \ + -D BUILD_PERF_TESTS=ON \ + -D BUILD_opencv_java=NO \ + -D BUILD_opencv_python=NO \ + -D BUILD_opencv_python2=NO \ + -D BUILD_opencv_python3=NO \ + -D OPENCV_GENERATE_PKGCONFIG=ON .. && \ + make -j $(nproc --all) && \ + make preinstall && make install && ldconfig && \ + cd / && rm -rf opencv* + + +################### +# amd64 build stage +################### + +FROM --platform=linux/arm64 golang:1.20-buster AS opencv-base-arm64 +LABEL maintainer="hybridgroup" + +RUN apt-get update && apt-get install -y --no-install-recommends \ + git build-essential cmake pkg-config unzip libgtk2.0-dev \ + curl ca-certificates libcurl4-openssl-dev libssl-dev \ + libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev \ + libjpeg62-turbo-dev libpng-dev libtiff-dev libdc1394-22-dev && \ + rm -rf /var/lib/apt/lists/* + +FROM --platform=linux/arm64 opencv-base-arm64 AS opencv-build-arm64 + +ARG OPENCV_VERSION="4.7.0" +ENV OPENCV_VERSION $OPENCV_VERSION + +ARG OPENCV_FILE="https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_FILE $OPENCV_FILE + +ARG OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_CONTRIB_FILE $OPENCV_CONTRIB_FILE + +RUN curl -Lo opencv.zip ${OPENCV_FILE} && \ + unzip -q opencv.zip && \ + curl -Lo opencv_contrib.zip ${OPENCV_CONTRIB_FILE} && \ + unzip -q opencv_contrib.zip && \ + rm opencv.zip opencv_contrib.zip + +RUN cd opencv-${OPENCV_VERSION} && \ + mkdir build && cd build && \ + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D CMAKE_INSTALL_PREFIX=/usr/local \ + -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ + -D ENABLE_NEON=ON \ + -D WITH_FFMPEG=ON \ + -D WITH_TBB=ON \ + -D BUILD_TBB=ON \ + -D BUILD_TESTS=OFF \ + -D WITH_EIGEN=OFF \ + -D WITH_GSTREAMER=OFF \ + -D WITH_V4L=ON \ + -D WITH_LIBV4L=ON \ + -D WITH_VTK=OFF \ + -D WITH_QT=OFF \ + -D BUILD_JPEG=ON \ + -D OPENCV_ENABLE_NONFREE=ON \ + -D BUILD_DOCS=OFF \ + -D BUILD_EXAMPLES=OFF \ + -D BUILD_TESTS=OFF \ + -D BUILD_PERF_TESTS=ON \ + -D BUILD_opencv_java=NO \ + -D BUILD_opencv_python=NO \ + -D BUILD_opencv_python2=NO \ + -D BUILD_opencv_python3=NO \ + -D OPENCV_GENERATE_PKGCONFIG=ON \ + -D CMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake .. && \ + make -j $(nproc --all) && \ + make preinstall && make install && ldconfig && \ + cd / && rm -rf opencv* + +ARG TARGETARCH + +################### +# multiarch build stage +################### + +FROM opencv-build-${TARGETARCH} as opencv-final + +CMD ["opencv_version", "-b"] diff --git a/vendor/gocv.io/x/gocv/Dockerfile.opencv-gpu-cuda-10 b/vendor/gocv.io/x/gocv/Dockerfile.opencv-gpu-cuda-10 new file mode 100644 index 00000000..d094d509 --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile.opencv-gpu-cuda-10 @@ -0,0 +1,68 @@ +# to build this docker image: +# docker build -f Dockerfile.opencv-gpu-cuda-10 -t ghcr.io/hybridgroup/opencv:4.7.0-gpu-cuda-10 . +FROM nvidia/cuda:10.2-cudnn8-devel AS opencv-gpu-base +LABEL maintainer="hybridgroup" + +# needed for cuda repo key rotation. see: +# https://forums.developer.nvidia.com/t/notice-cuda-linux-repository-key-rotation/212771 +# +RUN apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub + +RUN apt-get update && apt-get install -y --no-install-recommends \ + git build-essential cmake pkg-config unzip libgtk2.0-dev \ + wget curl ca-certificates libcurl4-openssl-dev libssl-dev \ + libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev \ + libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev && \ + rm -rf /var/lib/apt/lists/* + +ARG OPENCV_VERSION="4.7.0" +ENV OPENCV_VERSION $OPENCV_VERSION + +RUN curl -Lo opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \ + unzip -q opencv.zip && \ + curl -Lo opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \ + unzip -q opencv_contrib.zip && \ + rm opencv.zip opencv_contrib.zip && \ + cd opencv-${OPENCV_VERSION} && \ + mkdir build && cd build && \ + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D WITH_IPP=OFF \ + -D WITH_OPENGL=OFF \ + -D WITH_QT=OFF \ + -D CMAKE_INSTALL_PREFIX=/usr/local \ + -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ + -D OPENCV_ENABLE_NONFREE=ON \ + -D WITH_JASPER=OFF \ + -D BUILD_DOCS=OFF \ + -D BUILD_EXAMPLES=OFF \ + -D BUILD_TESTS=OFF \ + -D BUILD_PERF_TESTS=ON \ + -D BUILD_opencv_java=NO \ + -D BUILD_opencv_python=NO \ + -D BUILD_opencv_python2=NO \ + -D BUILD_opencv_python3=NO \ + -D WITH_TBB=ON \ + -D WITH_CUDA=ON \ + -D ENABLE_FAST_MATH=1 \ + -D CUDA_FAST_MATH=1 \ + -D WITH_CUBLAS=1 \ + -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda/ \ + -D BUILD_opencv_cudacodec=OFF \ + -D WITH_CUDNN=ON \ + -D OPENCV_DNN_CUDA=ON \ + -D CUDA_GENERATION=Auto \ + -D OPENCV_GENERATE_PKGCONFIG=ON .. && \ + make -j $(nproc --all) && \ + make preinstall && make install && ldconfig && \ + cd / && rm -rf opencv* + +# install golang here +FROM opencv-gpu-base AS opencv-gpu-golang + +ENV GO_RELEASE=1.20.2 +RUN wget https://dl.google.com/go/go${GO_RELEASE}.linux-amd64.tar.gz && \ + tar xfv go${GO_RELEASE}.linux-amd64.tar.gz -C /usr/local && \ + rm go${GO_RELEASE}.linux-amd64.tar.gz +ENV PATH="${PATH}:/usr/local/go/bin" + +CMD ["go version"] diff --git a/vendor/gocv.io/x/gocv/Dockerfile.opencv-gpu-cuda-11 b/vendor/gocv.io/x/gocv/Dockerfile.opencv-gpu-cuda-11 new file mode 100644 index 00000000..4db4decb --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile.opencv-gpu-cuda-11 @@ -0,0 +1,74 @@ +# to build this docker image: +# docker build -f Dockerfile.opencv-gpu-cuda-11 -t ghcr.io/hybridgroup/opencv:4.7.0-gpu-cuda-11 . +# docker build --build-arg OPENCV_VERSION="4.x" --build-arg OPENCV_FILE="https://github.com/opencv/opencv/archive/refs/heads/4.x.zip" --build-arg OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/refs/heads/4.x.zip" -f Dockerfile.opencv-gpu-cuda-11.2.2 -t ghcr.io/hybridgroup/opencv:4.8.0-dev-gpu-cuda-11 . +FROM nvidia/cuda:11.5.2-cudnn8-devel-ubuntu20.04 AS opencv-gpu-cuda-11-base +LABEL maintainer="hybridgroup" +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y --no-install-recommends \ + git build-essential cmake pkg-config unzip libgtk2.0-dev \ + wget curl ca-certificates libcurl4-openssl-dev libssl-dev \ + libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev \ + libjpeg-turbo8-dev libpng-dev libtiff-dev libdc1394-22-dev nasm && \ + rm -rf /var/lib/apt/lists/* + +ARG OPENCV_VERSION="4.7.0" +ENV OPENCV_VERSION $OPENCV_VERSION + +ARG OPENCV_FILE="https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_FILE $OPENCV_FILE + +ARG OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_CONTRIB_FILE $OPENCV_CONTRIB_FILE + +RUN curl -Lo opencv.zip ${OPENCV_FILE} && \ + unzip -q opencv.zip && \ + curl -Lo opencv_contrib.zip ${OPENCV_CONTRIB_FILE} && \ + unzip -q opencv_contrib.zip && \ + rm opencv.zip opencv_contrib.zip && \ + cd opencv-${OPENCV_VERSION} && \ + mkdir build && cd build && \ + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D WITH_IPP=OFF \ + -D WITH_OPENGL=OFF \ + -D WITH_QT=OFF \ + -D CMAKE_INSTALL_PREFIX=/usr/local \ + -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ + -D OPENCV_ENABLE_NONFREE=ON \ + -D WITH_JASPER=OFF \ + -D BUILD_DOCS=OFF \ + -D BUILD_EXAMPLES=OFF \ + -D BUILD_TESTS=OFF \ + -D BUILD_PERF_TESTS=ON \ + -D BUILD_opencv_java=NO \ + -D BUILD_opencv_python=NO \ + -D BUILD_opencv_python2=NO \ + -D BUILD_opencv_python3=NO \ + -D WITH_TBB=ON \ + -D BUILD_JPEG=ON \ + -D WITH_SIMD=ON \ + -D WITH_LIBJPEG_TURBO_SIMD=ON \ + -D WITH_CUDA=ON \ + -D ENABLE_FAST_MATH=1 \ + -D CUDA_FAST_MATH=1 \ + -D WITH_CUBLAS=1 \ + -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda/ \ + -D BUILD_opencv_cudacodec=OFF \ + -D WITH_CUDNN=ON \ + -D OPENCV_DNN_CUDA=ON \ + -D CUDA_GENERATION=Auto \ + -D OPENCV_GENERATE_PKGCONFIG=ON .. && \ + make -j $(nproc --all) && \ + make preinstall && make install && ldconfig && \ + cd / && rm -rf opencv* + +# install golang here +FROM opencv-gpu-cuda-11-base AS opencv-gpu-cuda-11-golang + +ENV GO_RELEASE=1.20.2 +RUN wget https://dl.google.com/go/go${GO_RELEASE}.linux-amd64.tar.gz && \ + tar xfv go${GO_RELEASE}.linux-amd64.tar.gz -C /usr/local && \ + rm go${GO_RELEASE}.linux-amd64.tar.gz +ENV PATH="${PATH}:/usr/local/go/bin" + +CMD ["go version"] diff --git a/vendor/gocv.io/x/gocv/Dockerfile.opencv-gpu-cuda-11.2.2 b/vendor/gocv.io/x/gocv/Dockerfile.opencv-gpu-cuda-11.2.2 new file mode 100644 index 00000000..b1cc9893 --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile.opencv-gpu-cuda-11.2.2 @@ -0,0 +1,74 @@ +# to build this docker image: +# docker build -f Dockerfile.opencv-gpu-cuda-11 -t ghcr.io/hybridgroup/opencv:4.7.0-gpu-cuda-11.2.2 . +# docker build --build-arg OPENCV_VERSION="4.x" --build-arg OPENCV_FILE="https://github.com/opencv/opencv/archive/refs/heads/4.x.zip" --build-arg OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/refs/heads/4.x.zip" -f Dockerfile.opencv-gpu-cuda-11.2.2 -t ghcr.io/hybridgroup/opencv:4.8.0-dev-gpu-cuda-11.2.2 . +FROM nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04 AS opencv-gpu-cuda-11-base +LABEL maintainer="hybridgroup" +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y --no-install-recommends \ + git build-essential cmake pkg-config unzip libgtk2.0-dev \ + wget curl ca-certificates libcurl4-openssl-dev libssl-dev \ + libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev \ + libjpeg-turbo8-dev libpng-dev libtiff-dev libdc1394-22-dev nasm && \ + rm -rf /var/lib/apt/lists/* + +ARG OPENCV_VERSION="4.7.0" +ENV OPENCV_VERSION $OPENCV_VERSION + +ARG OPENCV_FILE="https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_FILE $OPENCV_FILE + +ARG OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_CONTRIB_FILE $OPENCV_CONTRIB_FILE + +RUN curl -Lo opencv.zip ${OPENCV_FILE} && \ + unzip -q opencv.zip && \ + curl -Lo opencv_contrib.zip ${OPENCV_CONTRIB_FILE} && \ + unzip -q opencv_contrib.zip && \ + rm opencv.zip opencv_contrib.zip && \ + cd opencv-${OPENCV_VERSION} && \ + mkdir build && cd build && \ + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D WITH_IPP=OFF \ + -D WITH_OPENGL=OFF \ + -D WITH_QT=OFF \ + -D CMAKE_INSTALL_PREFIX=/usr/local \ + -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ + -D OPENCV_ENABLE_NONFREE=ON \ + -D WITH_JASPER=OFF \ + -D BUILD_DOCS=OFF \ + -D BUILD_EXAMPLES=OFF \ + -D BUILD_TESTS=OFF \ + -D BUILD_PERF_TESTS=ON \ + -D BUILD_opencv_java=NO \ + -D BUILD_opencv_python=NO \ + -D BUILD_opencv_python2=NO \ + -D BUILD_opencv_python3=NO \ + -D WITH_TBB=ON \ + -D BUILD_JPEG=ON \ + -D WITH_SIMD=ON \ + -D WITH_LIBJPEG_TURBO_SIMD=ON \ + -D WITH_CUDA=ON \ + -D ENABLE_FAST_MATH=1 \ + -D CUDA_FAST_MATH=1 \ + -D WITH_CUBLAS=1 \ + -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda/ \ + -D BUILD_opencv_cudacodec=OFF \ + -D WITH_CUDNN=ON \ + -D OPENCV_DNN_CUDA=ON \ + -D CUDA_GENERATION=Auto \ + -D OPENCV_GENERATE_PKGCONFIG=ON .. && \ + make -j $(nproc --all) && \ + make preinstall && make install && ldconfig && \ + cd / && rm -rf opencv* + +# install golang here +FROM opencv-gpu-cuda-11-base AS opencv-gpu-cuda-11-golang + +ENV GO_RELEASE=1.20.2 +RUN wget https://dl.google.com/go/go${GO_RELEASE}.linux-amd64.tar.gz && \ + tar xfv go${GO_RELEASE}.linux-amd64.tar.gz -C /usr/local && \ + rm go${GO_RELEASE}.linux-amd64.tar.gz +ENV PATH="${PATH}:/usr/local/go/bin" + +CMD ["go version"] diff --git a/vendor/gocv.io/x/gocv/Dockerfile.opencv-openvino b/vendor/gocv.io/x/gocv/Dockerfile.opencv-openvino new file mode 100644 index 00000000..2617540a --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile.opencv-openvino @@ -0,0 +1,57 @@ +# to build this docker image: +# docker build -f Dockerfile.opencv-openvino -t ghcr.io/hybridgroup/opencv:4.7.0-openvino +FROM openvino/ubuntu20_dev:2022.1.0 AS opencv-openvino-base +LABEL maintainer="hybridgroup" +ENV DEBIAN_FRONTEND=noninteractive +USER root +RUN apt-get update && apt-get install -y --no-install-recommends \ + git build-essential cmake pkg-config unzip libgtk2.0-dev \ + wget curl ca-certificates libcurl4-openssl-dev libssl-dev \ + libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev \ + libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev && \ + rm -rf /var/lib/apt/lists/* + +ARG OPENCV_VERSION="4.7.0" +ENV OPENCV_VERSION $OPENCV_VERSION + +RUN curl -Lo opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \ + unzip -q opencv.zip && \ + curl -Lo opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \ + unzip -q opencv_contrib.zip && \ + rm opencv.zip opencv_contrib.zip && \ + cd opencv-${OPENCV_VERSION} && \ + mkdir build && cd build && \ + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D WITH_IPP=OFF \ + -D WITH_OPENGL=OFF \ + -D WITH_QT=OFF \ + -D CMAKE_INSTALL_PREFIX=/usr/local \ + -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ + -D OPENCV_ENABLE_NONFREE=ON \ + -D WITH_JASPER=OFF \ + -D BUILD_DOCS=OFF \ + -D BUILD_EXAMPLES=OFF \ + -D BUILD_TESTS=OFF \ + -D BUILD_PERF_TESTS=ON \ + -D BUILD_opencv_java=NO \ + -D BUILD_opencv_python=NO \ + -D BUILD_opencv_python2=NO \ + -D BUILD_opencv_python3=NO \ + -D WITH_TBB=ON \ + -D WITH_OPENVINO=1 \ + -D ENABLE_FAST_MATH=1 \ + -D OPENCV_GENERATE_PKGCONFIG=ON .. && \ + make -j $(nproc --all) && \ + make preinstall && make install && ldconfig && \ + cd / && rm -rf opencv* + +# install golang here +FROM opencv-openvino-base AS opencv-openvino-golang + +ENV GO_RELEASE=1.20.2 +RUN wget https://dl.google.com/go/go${GO_RELEASE}.linux-amd64.tar.gz && \ + tar xfv go${GO_RELEASE}.linux-amd64.tar.gz -C /usr/local && \ + rm go${GO_RELEASE}.linux-amd64.tar.gz +ENV PATH="${PATH}:/usr/local/go/bin" +USER openvino +CMD ["go version"] diff --git a/vendor/gocv.io/x/gocv/Dockerfile.opencv-ubuntu-18.04 b/vendor/gocv.io/x/gocv/Dockerfile.opencv-ubuntu-18.04 new file mode 100644 index 00000000..11c6c0a2 --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile.opencv-ubuntu-18.04 @@ -0,0 +1,55 @@ +# to build this docker image: +# docker build -f Dockerfile.opencv-ubuntu-18.04 -t ghcr.io/hybridgroup/opencv:4.7.0-ubuntu-18.04 . +# docker build --build-arg OPENCV_VERSION="4.x" --build-arg OPENCV_FILE="https://github.com/opencv/opencv/archive/refs/heads/4.x.zip" --build-arg OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/refs/heads/4.x.zip" -f Dockerfile.opencv-ubuntu-18.04 -t ghcr.io/hybridgroup/opencv:4.8.0-dev-ubuntu-18.04 . +FROM ubuntu:18.04 AS opencv-base +LABEL maintainer="hybridgroup" + +RUN apt-get update && apt-get install -y --no-install-recommends \ + git build-essential cmake pkg-config wget unzip libgtk2.0-dev \ + curl ca-certificates libcurl4-openssl-dev libssl-dev \ + libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev \ + libjpeg-turbo8-dev libpng-dev libtiff-dev libdc1394-22-dev nasm && \ + rm -rf /var/lib/apt/lists/* + +ARG OPENCV_VERSION="4.7.0" +ENV OPENCV_VERSION $OPENCV_VERSION + +ARG OPENCV_FILE="https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_FILE $OPENCV_FILE + +ARG OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_CONTRIB_FILE $OPENCV_CONTRIB_FILE + +RUN curl -Lo opencv.zip ${OPENCV_FILE} && \ + unzip -q opencv.zip && \ + curl -Lo opencv_contrib.zip ${OPENCV_CONTRIB_FILE} && \ + unzip -q opencv_contrib.zip && \ + rm opencv.zip opencv_contrib.zip && \ + cd opencv-${OPENCV_VERSION} && \ + mkdir build && cd build && \ + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D WITH_IPP=OFF \ + -D WITH_OPENGL=OFF \ + -D WITH_QT=OFF \ + -D CMAKE_INSTALL_PREFIX=/usr/local \ + -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ + -D OPENCV_ENABLE_NONFREE=ON \ + -D WITH_JASPER=OFF \ + -D WITH_TBB=ON \ + -D BUILD_JPEG=ON \ + -D WITH_SIMD=ON \ + -D ENABLE_LIBJPEG_TURBO_SIMD=ON \ + -D BUILD_DOCS=OFF \ + -D BUILD_EXAMPLES=OFF \ + -D BUILD_TESTS=OFF \ + -D BUILD_PERF_TESTS=ON \ + -D BUILD_opencv_java=NO \ + -D BUILD_opencv_python=NO \ + -D BUILD_opencv_python2=NO \ + -D BUILD_opencv_python3=NO \ + -D OPENCV_GENERATE_PKGCONFIG=ON .. && \ + make -j $(nproc --all) && \ + make preinstall && make install && ldconfig && \ + cd / && rm -rf opencv* + +CMD ["opencv_version", "-b"] diff --git a/vendor/gocv.io/x/gocv/Dockerfile.opencv-ubuntu-20.04 b/vendor/gocv.io/x/gocv/Dockerfile.opencv-ubuntu-20.04 new file mode 100644 index 00000000..8e2b9d76 --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile.opencv-ubuntu-20.04 @@ -0,0 +1,58 @@ +# to build this docker image: +# docker build -f Dockerfile.opencv-ubuntu-20.04 -t ghcr.io/hybridgroup/opencv:4.7.0-ubuntu-20.04 . +# docker build --build-arg OPENCV_VERSION="4.x" --build-arg OPENCV_FILE="https://github.com/opencv/opencv/archive/refs/heads/4.x.zip" --build-arg OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/refs/heads/4.x.zip" -f Dockerfile.opencv-ubuntu-20.04 -t ghcr.io/hybridgroup/opencv:4.8.0-dev-ubuntu-20.04 . +FROM ubuntu:20.04 AS opencv-base +LABEL maintainer="hybridgroup" + +ENV TZ=Europe/Madrid +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +RUN apt-get update && apt-get install -y --no-install-recommends \ + tzdata git build-essential cmake pkg-config wget unzip libgtk2.0-dev \ + curl ca-certificates libcurl4-openssl-dev libssl-dev \ + libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev \ + libjpeg-turbo8-dev libpng-dev libtiff-dev libdc1394-22-dev nasm && \ + rm -rf /var/lib/apt/lists/* + +ARG OPENCV_VERSION="4.7.0" +ENV OPENCV_VERSION $OPENCV_VERSION + +ARG OPENCV_FILE="https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_FILE $OPENCV_FILE + +ARG OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_CONTRIB_FILE $OPENCV_CONTRIB_FILE + +RUN curl -Lo opencv.zip ${OPENCV_FILE} && \ + unzip -q opencv.zip && \ + curl -Lo opencv_contrib.zip ${OPENCV_CONTRIB_FILE} && \ + unzip -q opencv_contrib.zip && \ + rm opencv.zip opencv_contrib.zip && \ + cd opencv-${OPENCV_VERSION} && \ + mkdir build && cd build && \ + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D WITH_IPP=OFF \ + -D WITH_OPENGL=OFF \ + -D WITH_QT=OFF \ + -D CMAKE_INSTALL_PREFIX=/usr/local \ + -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ + -D OPENCV_ENABLE_NONFREE=ON \ + -D WITH_JASPER=OFF \ + -D WITH_TBB=ON \ + -D BUILD_JPEG=ON \ + -D WITH_SIMD=ON \ + -D ENABLE_LIBJPEG_TURBO_SIMD=ON \ + -D BUILD_DOCS=OFF \ + -D BUILD_EXAMPLES=OFF \ + -D BUILD_TESTS=OFF \ + -D BUILD_PERF_TESTS=ON \ + -D BUILD_opencv_java=NO \ + -D BUILD_opencv_python=NO \ + -D BUILD_opencv_python2=NO \ + -D BUILD_opencv_python3=NO \ + -D OPENCV_GENERATE_PKGCONFIG=ON .. && \ + make -j $(nproc --all) && \ + make preinstall && make install && ldconfig && \ + cd / && rm -rf opencv* + +CMD ["opencv_version", "-b"] diff --git a/vendor/gocv.io/x/gocv/Dockerfile.opencv-ubuntu-22.04 b/vendor/gocv.io/x/gocv/Dockerfile.opencv-ubuntu-22.04 new file mode 100644 index 00000000..f8b3b08c --- /dev/null +++ b/vendor/gocv.io/x/gocv/Dockerfile.opencv-ubuntu-22.04 @@ -0,0 +1,58 @@ +# to build this docker image: +# docker build -f Dockerfile.opencv-ubuntu-22.04 -t ghcr.io/hybridgroup/opencv:4.7.0-ubuntu-22.04 . +# docker build --build-arg OPENCV_VERSION="4.x" --build-arg OPENCV_FILE="https://github.com/opencv/opencv/archive/refs/heads/4.x.zip" --build-arg OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/refs/heads/4.x.zip" -f Dockerfile.opencv-ubuntu-20.04 -t ghcr.io/hybridgroup/opencv:4.8.0-dev-ubuntu-20.04 . +FROM ubuntu:22.04 AS opencv-base +LABEL maintainer="hybridgroup" + +ENV TZ=Europe/Madrid +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +RUN apt-get update && apt-get install -y --no-install-recommends \ + tzdata git build-essential cmake pkg-config wget unzip libgtk2.0-dev \ + curl ca-certificates libcurl4-openssl-dev libssl-dev \ + libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev \ + libjpeg-turbo8-dev libpng-dev libtiff-dev libdc1394-dev nasm && \ + rm -rf /var/lib/apt/lists/* + +ARG OPENCV_VERSION="4.7.0" +ENV OPENCV_VERSION $OPENCV_VERSION + +ARG OPENCV_FILE="https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_FILE $OPENCV_FILE + +ARG OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip" +ENV OPENCV_CONTRIB_FILE $OPENCV_CONTRIB_FILE + +RUN curl -Lo opencv.zip ${OPENCV_FILE} && \ + unzip -q opencv.zip && \ + curl -Lo opencv_contrib.zip ${OPENCV_CONTRIB_FILE} && \ + unzip -q opencv_contrib.zip && \ + rm opencv.zip opencv_contrib.zip && \ + cd opencv-${OPENCV_VERSION} && \ + mkdir build && cd build && \ + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D WITH_IPP=OFF \ + -D WITH_OPENGL=OFF \ + -D WITH_QT=OFF \ + -D CMAKE_INSTALL_PREFIX=/usr/local \ + -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ + -D OPENCV_ENABLE_NONFREE=ON \ + -D WITH_JASPER=OFF \ + -D WITH_TBB=ON \ + -D BUILD_JPEG=ON \ + -D WITH_SIMD=ON \ + -D ENABLE_LIBJPEG_TURBO_SIMD=ON \ + -D BUILD_DOCS=OFF \ + -D BUILD_EXAMPLES=OFF \ + -D BUILD_TESTS=OFF \ + -D BUILD_PERF_TESTS=ON \ + -D BUILD_opencv_java=NO \ + -D BUILD_opencv_python=NO \ + -D BUILD_opencv_python2=NO \ + -D BUILD_opencv_python3=NO \ + -D OPENCV_GENERATE_PKGCONFIG=ON .. && \ + make -j $(nproc --all) && \ + make preinstall && make install && ldconfig && \ + cd / && rm -rf opencv* + +CMD ["opencv_version", "-b"] diff --git a/vendor/gocv.io/x/gocv/LICENSE.txt b/vendor/gocv.io/x/gocv/LICENSE.txt new file mode 100644 index 00000000..3263f9e9 --- /dev/null +++ b/vendor/gocv.io/x/gocv/LICENSE.txt @@ -0,0 +1,13 @@ +Copyright (c) 2017-2022 The Hybrid Group and friends + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/vendor/gocv.io/x/gocv/Makefile b/vendor/gocv.io/x/gocv/Makefile new file mode 100644 index 00000000..be3d3f7f --- /dev/null +++ b/vendor/gocv.io/x/gocv/Makefile @@ -0,0 +1,320 @@ +.ONESHELL: +.PHONY: test deps download build clean astyle cmds docker + +# GoCV version to use. +GOCV_VERSION?="v0.31.0" + +# OpenCV version to use. +OPENCV_VERSION?=4.7.0 + +# Go version to use when building Docker image +GOVERSION?=1.16.2 + +# Temporary directory to put files into. +TMP_DIR?=/tmp/ + +# Build shared or static library +BUILD_SHARED_LIBS?=ON + +# Package list for each well-known Linux distribution +RPMS=cmake curl wget git gtk2-devel libpng-devel libjpeg-devel libtiff-devel tbb tbb-devel libdc1394-devel unzip gcc-c++ +DEBS=unzip wget build-essential cmake curl git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev +DEBS_UBUNTU_JAMMY=unzip wget build-essential cmake curl git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-dev +JETSON=build-essential cmake git unzip pkg-config libjpeg-dev libpng-dev libtiff-dev libavcodec-dev libavformat-dev libswscale-dev libgtk2.0-dev libcanberra-gtk* libxvidcore-dev libx264-dev libgtk-3-dev libtbb2 libtbb-dev libdc1394-22-dev libv4l-dev v4l-utils libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libavresample-dev libvorbis-dev libxine2-dev libfaac-dev libmp3lame-dev libtheora-dev libopencore-amrnb-dev libopencore-amrwb-dev libopenblas-dev libatlas-base-dev libblas-dev liblapack-dev libeigen3-dev gfortran libhdf5-dev protobuf-compiler libprotobuf-dev libgoogle-glog-dev libgflags-dev + +explain: + @echo "For quick install with typical defaults of both OpenCV and GoCV, run 'make install'" + +# Detect Linux distribution +distro_deps= +ifneq ($(shell which dnf 2>/dev/null),) + distro_deps=deps_fedora +else +ifneq ($(shell which apt-get 2>/dev/null),) +ifneq ($(shell cat /etc/os-release 2>/dev/null | grep "Jammy Jellyfish"),) + distro_deps=deps_ubuntu_jammy +else + distro_deps=deps_debian +endif +else +ifneq ($(shell which yum 2>/dev/null),) + distro_deps=deps_rh_centos +endif +endif +endif + +# Install all necessary dependencies. +deps: $(distro_deps) + +deps_rh_centos: + sudo yum -y install pkgconfig $(RPMS) + +deps_fedora: + sudo dnf -y install pkgconf-pkg-config $(RPMS) + +deps_debian: + sudo apt-get -y update + sudo apt-get -y install $(DEBS) + +deps_ubuntu_jammy: + sudo apt-get -y update + sudo apt-get -y install $(DEBS_UBUNTU_JAMMY) + +deps_jetson: + sudo sh -c "echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/nvidia-tegra.conf" + sudo ldconfig + sudo apt-get -y update + sudo apt-get -y install $(JETSON) + +# Download OpenCV source tarballs. +download: + rm -rf $(TMP_DIR)opencv + mkdir $(TMP_DIR)opencv + cd $(TMP_DIR)opencv + curl -Lo opencv.zip https://github.com/opencv/opencv/archive/refs/tags/$(OPENCV_VERSION).zip + unzip -q opencv.zip + curl -Lo opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/refs/tags/$(OPENCV_VERSION).zip + unzip -q opencv_contrib.zip + rm opencv.zip opencv_contrib.zip + cd - + +# Download openvino source tarballs. +download_openvino: + sudo rm -rf /usr/local/dldt/ + sudo rm -rf /usr/local/openvino/ + sudo git clone https://github.com/openvinotoolkit/openvino -b 2019_R3.1 /usr/local/openvino/ + +# Build openvino. +build_openvino_package: + cd /usr/local/openvino/inference-engine + sudo git submodule init + sudo git submodule update --recursive + sudo ./install_dependencies.sh + sudo mv -f thirdparty/clDNN/common/intel_ocl_icd/6.3/linux/Release thirdparty/clDNN/common/intel_ocl_icd/6.3/linux/RELEASE + sudo mkdir build + cd build + sudo rm -rf * + sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} -D ENABLE_VPU=ON -D ENABLE_MKL_DNN=ON -D ENABLE_CLDNN=ON .. + sudo $(MAKE) -j $(shell nproc --all) + sudo touch VERSION + sudo mkdir -p src/ngraph + sudo cp thirdparty/ngraph/src/ngraph/version.hpp src/ngraph + cd - + +# Build OpenCV. +build: + cd $(TMP_DIR)opencv/opencv-$(OPENCV_VERSION) + mkdir build + cd build + rm -rf * + cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} -D OPENCV_EXTRA_MODULES_PATH=$(TMP_DIR)opencv/opencv_contrib-$(OPENCV_VERSION)/modules -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=ON -D BUILD_opencv_java=NO -D BUILD_opencv_python=NO -D BUILD_opencv_python2=NO -D BUILD_opencv_python3=NO -D WITH_JASPER=OFF -D WITH_TBB=ON -DOPENCV_GENERATE_PKGCONFIG=ON .. + $(MAKE) -j $(shell nproc --all) + $(MAKE) preinstall + cd - + +# Build OpenCV on Raspbian with ARM hardware optimizations. +build_raspi: + cd $(TMP_DIR)opencv/opencv-$(OPENCV_VERSION) + mkdir build + cd build + rm -rf * + cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} -D OPENCV_EXTRA_MODULES_PATH=$(TMP_DIR)opencv/opencv_contrib-$(OPENCV_VERSION)/modules -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=ON -D BUILD_opencv_java=OFF -D BUILD_opencv_python=NO -D BUILD_opencv_python2=NO -D BUILD_opencv_python3=NO -D ENABLE_NEON=ON -D ENABLE_VFPV3=ON -D WITH_JASPER=OFF -D OPENCV_GENERATE_PKGCONFIG=ON .. + $(MAKE) -j $(shell nproc --all) + $(MAKE) preinstall + cd - + +# Build OpenCV on Raspberry pi zero which has ARMv6. +build_raspi_zero: + cd $(TMP_DIR)opencv/opencv-$(OPENCV_VERSION) + mkdir build + cd build + rm -rf * + cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} -D OPENCV_EXTRA_MODULES_PATH=$(TMP_DIR)opencv/opencv_contrib-$(OPENCV_VERSION)/modules -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=ON -D BUILD_opencv_java=OFF -D BUILD_opencv_python=NO -D BUILD_opencv_python2=NO -D BUILD_opencv_python3=NO -D ENABLE_VFPV2=ON -D WITH_JASPER=OFF -D OPENCV_GENERATE_PKGCONFIG=ON .. + $(MAKE) -j $(shell nproc --all) + $(MAKE) preinstall + cd - + +# Build OpenCV for NVidia Jetson with CUDA. +build_jetson: + cd $(TMP_DIR)opencv/opencv-$(OPENCV_VERSION) + mkdir build + cd build + rm -rf * + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D CMAKE_INSTALL_PREFIX=/usr/local \ + -D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \ + -D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} \ + -D OPENCV_EXTRA_MODULES_PATH=$(TMP_DIR)opencv/opencv_contrib-$(OPENCV_VERSION)/modules \ + -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=ON -D BUILD_opencv_java=OFF -D BUILD_opencv_python=NO -D BUILD_opencv_python2=NO -D BUILD_opencv_python3=NO \ + -D WITH_OPENCL=OFF \ + -D WITH_CUDA=ON \ + -D CUDA_ARCH_BIN=5.3 \ + -D CUDA_ARCH_PTX="" \ + -D WITH_CUDNN=ON \ + -D WITH_CUBLAS=ON \ + -D ENABLE_FAST_MATH=ON \ + -D CUDA_FAST_MATH=ON \ + -D OPENCV_DNN_CUDA=ON \ + -D ENABLE_NEON=ON \ + -D WITH_QT=OFF \ + -D WITH_OPENMP=ON \ + -D WITH_OPENGL=ON \ + -D BUILD_TIFF=ON \ + -D WITH_FFMPEG=ON \ + -D WITH_GSTREAMER=ON \ + -D WITH_TBB=ON \ + -D BUILD_TBB=ON \ + -D BUILD_TESTS=OFF \ + -D WITH_EIGEN=ON \ + -D WITH_V4L=ON \ + -D WITH_LIBV4L=ON \ + -D OPENCV_GENERATE_PKGCONFIG=ON .. + $(MAKE) -j $(shell nproc --all) + $(MAKE) preinstall + cd - + +# Build OpenCV with non-free contrib modules. +build_nonfree: + cd $(TMP_DIR)opencv/opencv-$(OPENCV_VERSION) + mkdir build + cd build + rm -rf * + cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} -D OPENCV_EXTRA_MODULES_PATH=$(TMP_DIR)opencv/opencv_contrib-$(OPENCV_VERSION)/modules -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=ON -D BUILD_opencv_java=NO -D BUILD_opencv_python=NO -D BUILD_opencv_python2=NO -D BUILD_opencv_python3=NO -D WITH_JASPER=OFF -D WITH_TBB=ON -DOPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_ENABLE_NONFREE=ON .. + $(MAKE) -j $(shell nproc --all) + $(MAKE) preinstall + cd - + +# Build OpenCV with openvino. +build_openvino: + cd $(TMP_DIR)opencv/opencv-$(OPENCV_VERSION) + mkdir build + cd build + rm -rf * + cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} -D ENABLE_CXX11=ON -D OPENCV_EXTRA_MODULES_PATH=$(TMP_DIR)opencv/opencv_contrib-$(OPENCV_VERSION)/modules -D WITH_INF_ENGINE=ON -D InferenceEngine_DIR=/usr/local/dldt/inference-engine/build -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=ON -D BUILD_opencv_java=NO -D BUILD_opencv_python=NO -D BUILD_opencv_python2=NO -D BUILD_opencv_python3=NO -D WITH_JASPER=OFF -D WITH_TBB=ON -DOPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_ENABLE_NONFREE=ON .. + $(MAKE) -j $(shell nproc --all) + $(MAKE) preinstall + cd - + +# Build OpenCV with cuda. +build_cuda: + cd $(TMP_DIR)opencv/opencv-$(OPENCV_VERSION) + mkdir build + cd build + rm -rf * + cmake -j $(shell nproc --all) -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} -D OPENCV_EXTRA_MODULES_PATH=$(TMP_DIR)opencv/opencv_contrib-$(OPENCV_VERSION)/modules -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=ON -D BUILD_opencv_java=NO -D BUILD_opencv_python=NO -D BUILD_opencv_python2=NO -D BUILD_opencv_python3=NO -D WITH_JASPER=OFF -D WITH_TBB=ON -DOPENCV_GENERATE_PKGCONFIG=ON -DWITH_CUDA=ON -DENABLE_FAST_MATH=1 -DCUDA_FAST_MATH=1 -DWITH_CUBLAS=1 -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda/ -DBUILD_opencv_cudacodec=OFF -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON -D CUDA_GENERATION=Auto .. + $(MAKE) -j $(shell nproc --all) + $(MAKE) preinstall + cd - + +# Build OpenCV staticly linked +build_static: + cd $(TMP_DIR)opencv/opencv-$(OPENCV_VERSION) + mkdir build + cd build + rm -rf * + cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=OFF -D OPENCV_EXTRA_MODULES_PATH=$(TMP_DIR)opencv/opencv_contrib-$(OPENCV_VERSION)/modules -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=ON -D BUILD_opencv_java=NO -D BUILD_opencv_python=NO -D BUILD_opencv_python2=NO -D BUILD_opencv_python3=NO -DWITH_JASPER=OFF -DWITH_QT=OFF -DWITH_GTK=OFF -DWITH_FFMPEG=OFF -DWITH_TIFF=OFF -DWITH_WEBP=OFF -DWITH_PNG=OFF -DWITH_1394=OFF -DWITH_OPENJPEG=OFF -DOPENCV_GENERATE_PKGCONFIG=ON .. + $(MAKE) -j $(shell nproc --all) + $(MAKE) preinstall + cd - + +# Build OpenCV with cuda. +build_all: + cd $(TMP_DIR)opencv/opencv-$(OPENCV_VERSION) + mkdir build + cd build + rm -rf * + cmake -j $(shell nproc --all) -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} -D ENABLE_CXX11=ON -D OPENCV_EXTRA_MODULES_PATH=$(TMP_DIR)opencv/opencv_contrib-$(OPENCV_VERSION)/modules -D WITH_INF_ENGINE=ON -D InferenceEngine_DIR=/usr/local/dldt/inference-engine/build -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=ON -D BUILD_opencv_java=NO -D BUILD_opencv_python=NO -D BUILD_opencv_python2=NO -D BUILD_opencv_python3=NO -D WITH_JASPER=OFF -D WITH_TBB=ON -DOPENCV_GENERATE_PKGCONFIG=ON -DWITH_CUDA=ON -DENABLE_FAST_MATH=1 -DCUDA_FAST_MATH=1 -DWITH_CUBLAS=1 -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda/ -DBUILD_opencv_cudacodec=OFF -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON -D CUDA_GENERATION=Auto .. + $(MAKE) -j $(shell nproc --all) + $(MAKE) preinstall + cd - + +# Cleanup temporary build files. +clean: + go clean --cache + rm -rf $(TMP_DIR)opencv + +# Cleanup old library files. +sudo_pre_install_clean: + sudo rm -rf /usr/local/lib/cmake/opencv4/ + sudo rm -rf /usr/local/lib/libopencv* + sudo rm -rf /usr/local/lib/pkgconfig/opencv* + sudo rm -rf /usr/local/include/opencv* + +# Do everything. +install: deps download sudo_pre_install_clean build sudo_install clean verify + +# Do everything on Raspbian. +install_raspi: deps download build_raspi sudo_install clean verify + +# Do everything on the raspberry pi zero. +install_raspi_zero: deps download build_raspi_zero sudo_install clean verify + +# Do everything on Jetson. +install_jetson: deps download build_jetson sudo_install clean verify + +# Do everything with cuda. +install_cuda: deps download sudo_pre_install_clean build_cuda sudo_install clean verify verify_cuda + +# Do everything with openvino. +install_openvino: deps download download_openvino sudo_pre_install_clean build_openvino_package sudo_install_openvino build_openvino sudo_install clean verify_openvino + +# Do everything statically. +install_static: deps download sudo_pre_install_clean build_static sudo_install clean verify_static + +# Do everything with non-free modules from cpencv_contrib. +install_nonfree: deps download sudo_pre_install_clean build_nonfree sudo_install clean verify + +# Do everything with openvino and cuda. +install_all: deps download download_openvino sudo_pre_install_clean build_openvino_package sudo_install_openvino build_all sudo_install clean verify_openvino verify_cuda + +# Install system wide. +sudo_install: + cd $(TMP_DIR)opencv/opencv-$(OPENCV_VERSION)/build + sudo $(MAKE) install + sudo ldconfig + cd - + +# Install system wide. +sudo_install_openvino: + cd /usr/local/openvino/inference-engine/build + sudo $(MAKE) install + sudo ldconfig + cd - + +# Build a minimal Go app to confirm gocv works. +verify: + go run ./cmd/version/main.go + +# Build a minimal Go app to confirm gocv works with statically built OpenCV. +verify_static: + go run -tags static ./cmd/version/main.go + +# Build a minimal Go app to confirm gocv cuda works. +verify_cuda: + go run ./cmd/cuda/main.go + +# Build a minimal Go app to confirm gocv openvino works. +verify_openvino: + go run -tags openvino ./cmd/version/main.go + +# Runs tests. +# This assumes env.sh was already sourced. +# pvt is not tested here since it requires additional depenedences. +test: + go test -tags matprofile . ./contrib + +docker: + docker build --build-arg OPENCV_VERSION=$(OPENCV_VERSION) --build-arg GOVERSION=$(GOVERSION) . + +astyle: + astyle --project=.astylerc --recursive *.cpp,*.h + + +releaselog: + git log --pretty=format:"%s" $(GOCV_VERSION)..HEAD + +CMDS=basic-drawing caffe-classifier captest capwindow counter dnn-detection dnn-pose-detection dnn-style-transfer faceblur facedetect facedetect-from-url feature-matching find-chessboard find-circles find-lines hand-gestures hello img-similarity mjpeg-streamer motion-detect saveimage savevideo showimage ssd-facedetect tf-classifier tracking version xphoto +cmds: + for cmd in $(CMDS) ; do \ + go build -o build/$$cmd cmd/$$cmd/main.go ; + done ; \ diff --git a/vendor/gocv.io/x/gocv/README.md b/vendor/gocv.io/x/gocv/README.md new file mode 100644 index 00000000..1cf5e83f --- /dev/null +++ b/vendor/gocv.io/x/gocv/README.md @@ -0,0 +1,593 @@ +# GoCV + +[![GoCV](https://raw.githubusercontent.com/hybridgroup/gocv/release/images/gocvlogo.jpg)](http://gocv.io/) + +[![Go Reference](https://pkg.go.dev/badge/gocv.io/x/gocv.svg)](https://pkg.go.dev/gocv.io/x/gocv) +[![Linux](https://github.com/hybridgroup/gocv/actions/workflows/linux.yml/badge.svg?branch=dev)](https://github.com/hybridgroup/gocv/actions/workflows/linux.yml) +[![Windows](https://ci.appveyor.com/api/projects/status/9asd5foet54ru69q/branch/dev?svg=true)](https://ci.appveyor.com/project/deadprogram/gocv/branch/dev) +[![Go Report Card](https://goreportcard.com/badge/github.com/hybridgroup/gocv)](https://goreportcard.com/report/github.com/hybridgroup/gocv) +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/hybridgroup/gocv/blob/release/LICENSE.txt) + +The GoCV package provides Go language bindings for the [OpenCV 4](http://opencv.org/) computer vision library. + +The GoCV package supports the latest releases of Go and OpenCV (v4.7.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](https://en.wikipedia.org/wiki/CUDA) for hardware acceleration using Nvidia GPUs. Check out the [CUDA README](./cuda/README.md) for more info on how to use GoCV with OpenCV/CUDA. + +GoCV also supports [Intel OpenVINO](https://software.intel.com/en-us/openvino-toolkit). Check out the [OpenVINO README](./openvino/README.md) 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: + +```go +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](https://raw.githubusercontent.com/hybridgroup/gocv/release/images/face-detect.jpg) + +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: + +```go +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](./cmd) of this repo in the form of various useful command line utilities, such as [capturing an image file](./cmd/saveimage), [streaming mjpeg video](./cmd/mjpeg-streamer), [counting objects that cross a line](./cmd/counter), and [using OpenCV with Tensorflow for object classification](./cmd/tf-classifier). + +## 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.7.0. + +Here are instructions for Ubuntu, Raspian, macOS, and Windows. + +## Ubuntu/Linux + +### Installation + +You can use `make` to install OpenCV 4.7.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.7.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.33.0 + opencv lib version: 4.7.0 + +That's it, now you are ready to use GoCV. + +#### Using CUDA with GoCV + +See the [cuda directory](./cuda) for information. + +#### Using OpenVINO with GoCV + +See the [openvino directory](./openvino) for information. + +#### Make Install for OpenVINO and Cuda + +The following commands should do everything to download and install OpenCV 4.7.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.33.0 + opencv lib version: 4.7.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.7.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.33.0 + opencv lib version: 4.7.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](https://gocv.io/) 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](https://golang.org/) 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.19.4' +``` + +#### 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](https://www.xquartz.org/). You can also install xquartz using [homebrew](https://brew.sh/) by running `brew cask install xquartz` +* install [socat](https://linux.die.net/man/1/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: + +```shell +open -a xquartz +``` +Click on *Security* tab in preferences and check the "Allow connections" box: + +![app image](./images/xquartz.png) + +Next, you need to create a TCP proxy using `socat` which will stream [X Window](https://en.wikipedia.org/wiki/X_Window_System) 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: + +```shell +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: + +```shell +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: + +```shell +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](https://github.com/denismakogon). You can find it located at [https://github.com/denismakogon/gocv-alpine](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.7.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.7.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.33.0 + opencv lib version: 4.7.0 + +That's it, now you are ready to use GoCV. + +## macOS + +### Installation + +You can install OpenCV 4.7.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.7.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.33.0 + opencv lib version: 4.7.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.7.0/include" + export CGO_LDFLAGS="-L/usr/local/Cellar/opencv/4.7.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.7.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/](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/](https://cmake.org/download/) to the default location. CMake installer will add CMake to your system path. + +#### OpenCV 4.7.0 and OpenCV Contrib Modules + +The following commands should do everything to download and install OpenCV 4.7.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.33.0 + opencv lib version: 4.7.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_core470 -lopencv_face470 -lopencv_videoio470 -lopencv_imgproc470 -lopencv_highgui470 -lopencv_imgcodecs470 -lopencv_objdetect470 -lopencv_features2d470 -lopencv_video470 -lopencv_dnn470 -lopencv_xfeatures2d470 -lopencv_plot470 -lopencv_tracking470 -lopencv_img_hash470 + +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/c19458cf64bd3e91faae85c3ac887481 + +See original discussion here: +https://github.com/hybridgroup/gocv/issues/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](https://golang.org/pkg/runtime/pprof/#Profile). + +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: + +```go +gocv.MatProfile.Count() +``` + +You can display the current entries (the stack traces) with: + +```go +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: + +```go +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: + +```go +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](http://localhost:6060/debug/pprof/gocv.io/x/gocv.Mat?debug=1). + + +## How to contribute + +Please take a look at our [CONTRIBUTING.md](./CONTRIBUTING.md) document to understand our contribution guidelines. + +Then check out our [ROADMAP.md](./ROADMAP.md) document to know what to work on next. + +## Why this project exists + +The [https://github.com/go-opencv/go-opencv](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](http://swig.org/). 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](https://github.com/opencv/opencv/tree/master/modules/videoio) 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-2021 The Hybrid Group. + +Logo generated by GopherizeMe - https://gopherize.me diff --git a/vendor/gocv.io/x/gocv/ROADMAP.md b/vendor/gocv.io/x/gocv/ROADMAP.md new file mode 100644 index 00000000..1557b5db --- /dev/null +++ b/vendor/gocv.io/x/gocv/ROADMAP.md @@ -0,0 +1,411 @@ +# Roadmap + +This is a list of all of the functionality areas within OpenCV, and OpenCV Contrib. + +Any section listed with an "X" means that all of the relevant OpenCV functionality has been wrapped for use within GoCV. + +Any section listed with **WORK STARTED** indicates that some work has been done, but not all functionality in that module has been completed. If there are any functions listed under a section marked **WORK STARTED**, it indicates that that function still requires a wrapper implemented. + +And any section that is simply listed, indicates that so far, no work has been done on that module. + +Your pull requests will be greatly appreciated! + +## Modules list + +- [ ] **core. Core functionality - WORK STARTED** + - [X] **Basic structures** + - [ ] **Operations on arrays - WORK STARTED**. The following functions still need implementation: + - [ ] [Mahalanobis](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga4493aee129179459cbfc6064f051aa7d) + - [ ] [mulTransposed](https://docs.opencv.org/master/d2/de8/group__core__array.html#gadc4e49f8f7a155044e3be1b9e3b270ab) + - [ ] [PCABackProject](https://docs.opencv.org/master/d2/de8/group__core__array.html#gab26049f30ee8e94f7d69d82c124faafc) + - [ ] [PCACompute](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga4e2073c7311f292a0648f04c37b73781) + - [ ] [PCAProject](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6b9fbc7b3a99ebfd441bbec0a6bc4f88) + - [ ] [PSNR](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga07aaf34ae31d226b1b847d8bcff3698f) + - [ ] [randn](https://docs.opencv.org/master/d2/de8/group__core__array.html#gaeff1f61e972d133a04ce3a5f81cf6808) + - [ ] [randShuffle](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6a789c8a5cb56c6dd62506179808f763) + - [ ] [randu](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga1ba1026dca0807b27057ba6a49d258c0) + - [ ] [setRNGSeed](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga757e657c037410d9e19e819569e7de0f) + - [ ] [SVBackSubst](https://docs.opencv.org/master/d2/de8/group__core__array.html#gab4e620e6fc6c8a27bb2be3d50a840c0b) + - [ ] [SVDecomp](https://docs.opencv.org/master/d2/de8/group__core__array.html#gab477b5b7b39b370bb03e75b19d2d5109) + - [ ] [theRNG](https://docs.opencv.org/master/d2/de8/group__core__array.html#ga75843061d150ad6564b5447e38e57722) + + - [ ] XML/YAML Persistence + - [ ] [FileStorage](https://docs.opencv.org/master/da/d56/classcv_1_1FileStorage.html) + + - [ ] **Clustering - WORK STARTED**. The following functions still need implementation: + - [ ] [partition](https://docs.opencv.org/master/d5/d38/group__core__cluster.html#ga2037c989e69b499c1aa271419f3a9b34) + + - [ ] Optimization Algorithms + - [ ] [ConjGradSolver](https://docs.opencv.org/master/d0/d21/classcv_1_1ConjGradSolver.html) + - [ ] [DownhillSolver](https://docs.opencv.org/master/d4/d43/classcv_1_1DownhillSolver.html) + - [ ] [solveLP](https://docs.opencv.org/master/da/d01/group__core__optim.html#ga9a06d237a9d38ace891efa1ca1b5d00a) + +- [ ] **imgproc. Image processing - WORK STARTED** + - [ ] **Image Filtering - WORK STARTED** The following functions still need implementation: + - [ ] [buildPyramid](https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gacfdda2bc1ac55e96de7e9f0bce7238c0) + - [ ] [getDerivKernels](https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga6d6c23f7bd3f5836c31cfae994fc4aea) + - [ ] [getGaborKernel](https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gae84c92d248183bd92fa713ce51cc3599) + - [ ] [morphologyExWithParams](https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga67493776e3ad1a3df63883829375201f) + - [ ] [pyrMeanShiftFiltering](https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga9fabdce9543bd602445f5db3827e4cc0) + + - [ ] **Geometric Image Transformations - WORK STARTED** The following functions still need implementation: + - [ ] [convertMaps](https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga9156732fa8f01be9ebd1a194f2728b7f) + - [ ] [getDefaultNewCameraMatrix](https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga744529385e88ef7bc841cbe04b35bfbf) + - [ ] [initUndistortRectifyMap](https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga7dfb72c9cf9780a347fbe3d1c47e5d5a) + - [ ] [initWideAngleProjMap](https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#gaceb049ec48898d1dadd5b50c604429c8) + - [ ] [undistort](https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga69f2545a8b62a6b0fc2ee060dc30559d) + + - [ ] **Miscellaneous Image Transformations - WORK STARTED** The following functions still need implementation: + - [ ] [cvtColorTwoPlane](https://docs.opencv.org/master/d7/d1b/group__imgproc__misc.html#ga8e873314e72a1a6c0252375538fbf753) + - [ ] [floodFill](https://docs.opencv.org/master/d7/d1b/group__imgproc__misc.html#gaf1f55a048f8a45bc3383586e80b1f0d0) + + - [ ] **Drawing Functions - WORK STARTED** The following functions still need implementation: + - [ ] [drawMarker](https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga482fa7b0f578fcdd8a174904592a6250) + - [ ] [ellipse2Poly](https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga727a72a3f6a625a2ae035f957c61051f) + - [ ] [fillConvexPoly](https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga906aae1606ea4ed2f27bec1537f6c5c2) + - [ ] [getFontScaleFromHeight](https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga442ff925c1a957794a1309e0ed3ba2c3) + + - [ ] ColorMaps in OpenCV + - [ ] Planar Subdivision + - [ ] **Histograms - WORK STARTED** The following functions still need implementation: + - [ ] [EMD](https://docs.opencv.org/master/d6/dc7/group__imgproc__hist.html#ga902b8e60cc7075c8947345489221e0e0) + - [ ] [wrapperEMD](https://docs.opencv.org/master/d6/dc7/group__imgproc__hist.html#ga31fdda0864e64ca6b9de252a2611758b) + + - [ ] **Structural Analysis and Shape Descriptors - WORK STARTED** The following functions still need implementation: + - [ ] [fitEllipse](https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#gaf259efaad93098103d6c27b9e4900ffa) + - [ ] [fitEllipseAMS](https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga69e90cda55c4e192a8caa0b99c3e4550) + - [ ] [fitEllipseDirect](https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga6421884fd411923a74891998bbe9e813) + - [ ] [HuMoments](https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#gab001db45c1f1af6cbdbe64df04c4e944) + - [ ] [intersectConvexConvex](https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga8e840f3f3695613d32c052bec89e782c) + - [ ] [isContourConvex](https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga8abf8010377b58cbc16db6734d92941b) + - [X] [matchShapes](https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#gaadc90cb16e2362c9bd6e7363e6e4c317) + - [ ] [minEnclosingTriangle](https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga1513e72f6bbdfc370563664f71e0542f) + - [ ] [rotatedRectangleIntersection](https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga8740e7645628c59d238b0b22c2abe2d4) + + - [ ] **Motion Analysis and Object Tracking - WORK STARTED** The following functions still need implementation: + - [ ] [createHanningWindow](https://docs.opencv.org/master/d7/df3/group__imgproc__motion.html#ga80e5c3de52f6bab3a7c1e60e89308e1b) + - [ ] [phaseCorrelate](https://docs.opencv.org/master/d7/df3/group__imgproc__motion.html#ga552420a2ace9ef3fb053cd630fdb4952) + + - [ ] **Feature Detection - WORK STARTED** The following functions still need implementation: + - [ ] [cornerEigenValsAndVecs](https://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#ga4055896d9ef77dd3cacf2c5f60e13f1c) + - [ ] [cornerHarris](https://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#gac1fc3598018010880e370e2f709b4345) + - [ ] [cornerMinEigenVal](https://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#ga3dbce297c1feb859ee36707e1003e0a8) + - [ ] [createLineSegmentDetector](https://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#ga6b2ad2353c337c42551b521a73eeae7d) + - [ ] [preCornerDetect](https://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#gaa819f39b5c994871774081803ae22586) + + - [ ] **Object Detection - WORK STARTED** + - [ ] **aruco. ArUco Marker Detection - WORK STARTED** + - [X] [detectMarkers](https://docs.opencv.org/4.x/d2/d1a/classcv_1_1aruco_1_1ArucoDetector.html#a0c1d14251bf1cbb06277f49cfe1c9b61) + - [ ] [refineDetectedMarkers](https://docs.opencv.org/4.x/d2/d1a/classcv_1_1aruco_1_1ArucoDetector.html#ad806c9310cfc826a178b0aefdf09bab6) + - [X] [drawDetectedMarkers](https://docs.opencv.org/4.x/de/d67/group__objdetect__aruco.html#ga2ad34b0f277edebb6a132d3069ed2909) + - [X] [generateImageMarker](https://docs.opencv.org/4.x/de/d67/group__objdetect__aruco.html#ga631cb40c63945cc5b9ef6b064a5f4fc2) + - [ ] [refineDetectedMarkers](https://docs.opencv.org/4.x/d2/d1a/classcv_1_1aruco_1_1ArucoDetector.html#ad806c9310cfc826a178b0aefdf09bab6) + - [ ] [drawDetectedCornersCharuco](https://docs.opencv.org/4.x/de/d67/group__objdetect__aruco.html#ga7225eee644190f791e1583c499b7ab10) + - [ ] [drawDetectedDiamonds](https://docs.opencv.org/4.x/de/d67/group__objdetect__aruco.html#ga0dbf27203267fb8e9f282554cf0d3433) + - [ ] [extendDictionary](https://docs.opencv.org/4.x/de/d67/group__objdetect__aruco.html#ga928c031e9a782b18405af56c851d9549) + - [ ] [CharucoDetector](https://docs.opencv.org/4.x/d9/df5/classcv_1_1aruco_1_1CharucoDetector.html#ad7647d1c3d0e2db97bedc31f743e796b) + - [ ] [detectBoard](https://docs.opencv.org/4.x/d9/df5/classcv_1_1aruco_1_1CharucoDetector.html#aacbea601612a3a0feaa45ebb7fb255fd) + - [ ] [detectDiamonds](https://docs.opencv.org/4.x/d9/df5/classcv_1_1aruco_1_1CharucoDetector.html#a50342803f68deb1e6b0b79f61d4b1a73) + +- [X] **imgcodecs. Image file reading and writing.** +- [X] **videoio. Video I/O** +- [X] **highgui. High-level GUI** +- [ ] **video. Video Analysis - WORK STARTED** + - [X] **Motion Analysis** + - [ ] **Object Tracking - WORK STARTED** The following functions still need implementation: + - [ ] [buildOpticalFlowPyramid](https://docs.opencv.org/master/dc/d6b/group__video__track.html#ga86640c1c470f87b2660c096d2b22b2ce) + - [ ] [estimateRigidTransform](https://docs.opencv.org/master/dc/d6b/group__video__track.html#ga762cbe5efd52cf078950196f3c616d48) + - [ ] [findTransformECC](https://docs.opencv.org/master/dc/d6b/group__video__track.html#ga7ded46f9a55c0364c92ccd2019d43e3a) + - [ ] [meanShift](https://docs.opencv.org/master/dc/d6b/group__video__track.html#ga7ded46f9a55c0364c92ccd2019d43e3a) + - [ ] [CamShift](https://docs.opencv.org/master/dc/d6b/group__video__track.html#gaef2bd39c8356f423124f1fe7c44d54a1) + - [ ] [DualTVL1OpticalFlow](https://docs.opencv.org/master/dc/d47/classcv_1_1DualTVL1OpticalFlow.html) + - [ ] [FarnebackOpticalFlow](https://docs.opencv.org/master/de/d9e/classcv_1_1FarnebackOpticalFlow.html) + - [X] [KalmanFilter](https://docs.opencv.org/master/dd/d6a/classcv_1_1KalmanFilter.html) + - [ ] [SparsePyrLKOpticalFlow](https://docs.opencv.org/master/d7/d08/classcv_1_1SparsePyrLKOpticalFlow.html) + - [ ] [GOTURN](https://docs.opencv.org/master/d7/d4c/classcv_1_1TrackerGOTURN.html) + +- [ ] **calib3d. Camera Calibration and 3D Reconstruction - WORK STARTED**. The following functions still need implementation: + - [ ] **Camera Calibration - WORK STARTED** The following functions still need implementation: + - [X] [calibrateCamera](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [calibrateCameraRO](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [calibrateHandEye](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [calibrationMatrixValues](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [checkChessboard](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [composeRT](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [computeCorrespondEpilines](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [convertPointsFromHomogeneous](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [convertPointsHomogeneous](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [convertPointsToHomogeneous](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [correctMatches](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [decomposeEssentialMat](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [decomposeHomographyMat](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [decomposeProjectionMatrix](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [drawChessboardCorners](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [drawFrameAxes](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [X] [estimateAffine2D](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [estimateAffine3D](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [filterHomographyDecompByVisibleRefpoints](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [filterSpeckles](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [find4QuadCornerSubpix](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [X] [findChessboardCorners](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [X] [findChessboardCornersSB](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [findCirclesGrid](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [findEssentialMat](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [findFundamentalMat](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [getDefaultNewCameraMatrix](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [getOptimalNewCameraMatrix](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [getValidDisparityROI](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [initCameraMatrix2D](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [initUndistortRectifyMap](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [initWideAngleProjMap](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [matMulDeriv](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [projectPoints](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [recoverPose](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [rectify3Collinear](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [reprojectImageTo3D](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [Rodrigues](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [RQDecomp3x3](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [sampsonDistance](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [solveP3P](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [solvePnP](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [solvePnPGeneric](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [solvePnPRansac](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [solvePnPRefineLM](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [solvePnPRefineVVS](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [stereoCalibrate](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [stereoRectify](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [stereoRectifyUncalibrated](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [triangulatePoints](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + - [ ] [validateDisparity](https://docs.opencv.org/master/d9/d0c/group__calib3d.html) + + - [ ] **Fisheye - WORK STARTED** The following functions still need implementation: + - [ ] [calibrate](https://docs.opencv.org/master/db/d58/group__calib3d__fisheye.html#gad626a78de2b1dae7489e152a5a5a89e1) + - [ ] [distortPoints](https://docs.opencv.org/master/db/d58/group__calib3d__fisheye.html#ga75d8877a98e38d0b29b6892c5f8d7765) + - [ ] [projectPoints](https://docs.opencv.org/master/db/d58/group__calib3d__fisheye.html#gab1ad1dc30c42ee1a50ce570019baf2c4) + - [ ] [stereoCalibrate](https://docs.opencv.org/master/db/d58/group__calib3d__fisheye.html#gadbb3a6ca6429528ef302c784df47949b) + - [ ] [stereoRectify](https://docs.opencv.org/master/db/d58/group__calib3d__fisheye.html#gac1af58774006689056b0f2ef1db55ecc) + +- [ ] **features2d. 2D Features Framework - WORK STARTED** + - [X] **Feature Detection and Description** + - [X] **Descriptor Matchers** + - [X] **Drawing Function of Keypoints and Matches** + - [ ] Object Categorization + - [ ] [BOWImgDescriptorExtractor](https://docs.opencv.org/master/d2/d6b/classcv_1_1BOWImgDescriptorExtractor.html) + - [ ] [BOWKMeansTrainer](https://docs.opencv.org/master/d4/d72/classcv_1_1BOWKMeansTrainer.html) + +- [X] **objdetect. Object Detection** +- [X] **dnn. Deep Neural Network module** +- [ ] ml. Machine Learning +- [ ] flann. Clustering and Search in Multi-Dimensional Spaces +- [ ] **photo. Computational Photography - WORK STARTED** The following functions still need implementation: + - [ ] [inpaint](https://docs.opencv.org/master/d7/d8b/group__photo__inpaint.html#gaedd30dfa0214fec4c88138b51d678085) + - [ ] [denoise_TVL1](https://docs.opencv.org/master/d1/d79/group__photo__denoise.html#ga7602ed5ae17b7de40152b922227c4e4f) + - [X] [fastNlMeansDenoising](https://docs.opencv.org/master/d1/d79/group__photo__denoise.html#ga4c6b0031f56ea3f98f768881279ffe93) + - [X] [fastNlMeansDenoisingColored](https://docs.opencv.org/master/d1/d79/group__photo__denoise.html#ga03aa4189fc3e31dafd638d90de335617) + - [X] [fastNlMeansDenoisingMulti](https://docs.opencv.org/master/d1/d79/group__photo__denoise.html#gaf4421bf068c4d632ea7f0aa38e0bf172) + - [ ] [createCalibrateDebevec](https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga7fed9707ad5f2cc0e633888867109f90) + - [ ] [createCalibrateRobertson](https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#gae77813a21cd351a596619e5ff013be5d) + - [ ] [createMergeDebevec](https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#gaa8eab36bc764abb2a225db7c945f87f9) + - [ ] [createMergeRobertson](https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga460d4a1df1a7e8cdcf7445bb87a8fb78) + - [ ] [createTonemap](https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#gabcbd653140b93a1fa87ccce94548cd0d) + - [ ] [createTonemapDrago](https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga72bf92bb6b8653ee4be650ac01cf50b6) + - [ ] [createTonemapMantiuk](https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga3b3f3bf083b7515802f039a6a70f2d21) + - [ ] [createTonemapReinhard](https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#gadabe7f6bf1fa96ad0fd644df9182c2fb) + - [ ] [decolor](https://docs.opencv.org/master/d4/d32/group__photo__decolor.html#ga4864d4c007bda5dacdc5e9d4ed7e222c) + - [X] [detailEnhance](https://docs.opencv.org/master/df/dac/group__photo__render.html#ga0de660cb6f371a464a74c7b651415975) + - [X] [edgePreservingFilter](https://docs.opencv.org/master/df/dac/group__photo__render.html#gafaee2977597029bc8e35da6e67bd31f7) + - [X] [pencilSketch](https://docs.opencv.org/master/df/dac/group__photo__render.html#gae5930dd822c713b36f8529b21ddebd0c) + - [X] [stylization](https://docs.opencv.org/master/df/dac/group__photo__render.html#gacb0f7324017df153d7b5d095aed53206) + +- [ ] stitching. Images stitching + +## CUDA + +- [ ] **core. - WORK STARTED** The following functions still need implementation: + - [ ] [cv::cuda::convertFp16](https://docs.opencv.org/master/d8/d40/group__cudacore__init.html#gaa1c52258763197958eb9e6681917f723) + - [ ] [cv::cuda::deviceSupports](https://docs.opencv.org/master/d8/d40/group__cudacore__init.html#ga170b10cc9af4aa8cce8c0afdb4b1d08c) + - [X] [cv::cuda::getDevice](https://docs.opencv.org/master/d8/d40/group__cudacore__init.html#ga6ded4ed8e4fc483a9863d31f34ec9c0e) + - [X] [cv::cuda::resetDevice](https://docs.opencv.org/master/d8/d40/group__cudacore__init.html#ga6153b6f461101374e655a54fc77e725e) + - [X] [cv::cuda::setDevice](https://docs.opencv.org/master/d8/d40/group__cudacore__init.html#gaefa34186b185de47851836dba537828b) + +- [ ] **cudaarithm. Operations on Matrices - WORK STARTED** The following functions still need implementation: + - [ ] **core** The following functions still need implementation: + - [ ] [cv::cuda::copyMakeBorder](https://docs.opencv.org/master/de/d09/group__cudaarithm__core.html#ga5368db7656eacf846b40089c98053a49) + - [ ] [cv::cuda::createLookUpTable](https://docs.opencv.org/master/de/d09/group__cudaarithm__core.html#ga2d9d9780dea8c5cd85d3c19b7e01979c) + - [ ] [cv::cuda::merge](https://docs.opencv.org/master/de/d09/group__cudaarithm__core.html#gaac939dc3b178ee92fb6e7078f342622c) + - [ ] [cv::cuda::split](https://docs.opencv.org/master/de/d09/group__cudaarithm__core.html#gabe5013d55d4ff586b20393913726179e) + - [ ] [cv::cuda::transpose](https://docs.opencv.org/master/de/d09/group__cudaarithm__core.html#ga327b71c3cb811a904ccf5fba37fc29f2) + + - [ ] **per-element operations - WORK STARTED** The following functions still need implementation: + - [X] [cv::cuda::absdiff](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#gac062b283cf46ee90f74a773d3382ab54) + - [X] [cv::cuda::add](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga5d9794bde97ed23d1c1485249074a8b1) + - [ ] [cv::cuda::addWeighted](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga2cd14a684ea70c6ab2a63ee90ffe6201) + - [X] [cv::cuda::bitwise_and](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga78d7c1a013877abd4237fbfc4e13bd76) + - [X] [cv::cuda::bitwise_not](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#gae58159a2259ae1acc76b531c171cf06a) + - [X] [cv::cuda::bitwise_or](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#gafd098ee3e51c68daa793999c1da3dfb7) + - [X] [cv::cuda::bitwise_xor](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga3d95d4faafb099aacf18e8b915a4ad8d) + - [ ] [cv::cuda::cartToPolar](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga82210c7d1c1d42e616e554bf75a53480) + - [ ] [cv::cuda::compare](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga4d41cd679f4a83862a3de71a6057db54) + - [X] [cv::cuda::divide](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga124315aa226260841e25cc0b9ea99dc3) + - [X] [cv::cuda::exp](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#gac6e51541d3bb0a7a396128e4d5919b61) + - [ ] [cv::cuda::inRange](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#gaf611ab6b1d85e951feb6f485b1ed9672) + - [X] [cv::cuda::log](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#gaae9c60739e2d1a977b4d3250a0be42ca) + - [ ] [cv::cuda::lshift](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#gafd072accecb14c9adccdad45e3bf2300) + - [ ] [cv::cuda::magnitude](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga3d17f4fcd79d7c01fadd217969009463) + - [ ] [cv::cuda::magnitudeSqr](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga7613e382d257e150033d0ce4d6098f6a) + - [X] [cv::cuda::max](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#gadb5dd3d870f10c0866035755b929b1e7) + - [X] [cv::cuda::min](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga74f0b05a65b3d949c237abb5e6c60867) + - [X] [cv::cuda::multiply](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga497cc0615bf717e1e615143b56f00591) + - [ ] [cv::cuda::phase](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga5b75ec01be06dcd6e27ada09a0d4656a) + - [ ] [cv::cuda::polarToCart](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga01516a286a329c303c2db746513dd9df) + - [ ] [cv::cuda::pow](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga82d04ef4bcc4dfa9bfbe76488007c6c4) + - [ ] [cv::cuda::rshift](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga87af0b66358cc302676f35c1fd56c2ed) + - [X] [cv::cuda::sqr](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga8aae233da90ce0ffe309ab8004342acb) + - [X] [cv::cuda::sqrt](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga09303680cb1a5521a922b6d392028d8c) + - [X] [cv::cuda::subtract](https://docs.opencv.org/master/d8/d34/group__cudaarithm__elem.html#ga6eab60fc250059e2fda79c5636bd067f) + + - [ ] **matrix reductions** The following functions still need implementation: + - [ ] [cv::cuda::absSum](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga690fa79ba4426c53f7d2bebf3d37a32a) + - [ ] [cv::cuda::calcAbsSum](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga15c403b76ab2c4d7ed0f5edc09891b7e) + - [ ] [cv::cuda::calcNorm](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga39d2826990d29b7e4b69dbe02bdae2e1) + - [ ] [cv::cuda::calcNormDiff](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga9be3d9a7b6c5760955f37d1039d01265) + - [ ] [cv::cuda::calcSqrSum](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#gac998c83597f6c206c78cee16aa87946f) + - [ ] [cv::cuda::calcSum](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga98a09144047f09f5cb1d6b6ea8e0856f) + - [ ] [cv::cuda::countNonZero](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga98a09144047f09f5cb1d6b6ea8e0856f) + - [ ] [cv::cuda::findMinMax](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#gae7f5f2aa9f65314470a76fccdff887f2) + - [ ] [cv::cuda::findMinMaxLoc](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga93916bc473a62d215d1130fab84d090a) + - [ ] [cv::cuda::integral](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga07e5104eba4bf45212ac9dbc5bf72ba6) + - [ ] [cv::cuda::meanStdDev](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga990a4db4c6d7e8f0f3a6685ba48fbddc) + - [ ] [cv::cuda::minMax](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga8d7de68c10717cf25e787e3c20d2dfee) + - [ ] [cv::cuda::minMaxLoc](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga5cacbc2a2323c4eaa81e7390c5d9f530) + - [ ] [cv::cuda::norm](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga6c01988a58d92126a7c60a4ab76d8324) + - [ ] [cv::cuda::normalize](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga4da4738b9956a5baaa2f5f8c2fba438a) + - [ ] [cv::cuda::rectStdDev](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#gac311484a4e57cab2ce2cfdc195fda7ee) + - [ ] [cv::cuda::reduce](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga21d57f661db7be093caf2c4378be2007) + - [ ] [cv::cuda::sqrIntegral](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga40c75196202706399a60bf6ba7a052ac) + - [ ] [cv::cuda::sqlSum](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga056c804ebf5d2eb9f6f35e3dcb01524c) + - [ ] [cv::cuda::sum](https://docs.opencv.org/master/d5/de6/group__cudaarithm__reduce.html#ga1f582844670199281e8012733b50c582) + + - [ ] **Operations on matrices** The following functions still need implementation: + - [ ] [cv::cuda::createConvolution](https://docs.opencv.org/4.5.0/d9/d88/group__cudaarithm__arithm.html#ga2695e05ef624bf3ce03cfbda383a821d) + - [ ] [cv::cuda::createDFT](https://docs.opencv.org/4.5.0/d9/d88/group__cudaarithm__arithm.html#ga0f72d063b73c8bb995678525eb076f10) + - [ ] [cv::cuda::dft](https://docs.opencv.org/4.5.0/d9/d88/group__cudaarithm__arithm.html#gadea99cb15a715c983bcc2870d65a2e78) + - [ ] [cv::cuda::gemm](https://docs.opencv.org/4.5.0/d9/d88/group__cudaarithm__arithm.html#ga42efe211d7a43bbc922da044c4f17130) + - [ ] [cv::cuda::mulAndScaleSpectrums](https://docs.opencv.org/4.5.0/d9/d88/group__cudaarithm__arithm.html#ga5704c25b8be4f19da812e6d98c8ee464) + - [ ] [cv::cuda::mulSpectrums](https://docs.opencv.org/4.5.0/d9/d88/group__cudaarithm__arithm.html#gab3e8900d67c4f59bdc137a0495206cd8) + +- [X] **cudabgsegm. Background Segmentation** + +- [ ] **cudacodec** Video Encoding/Decoding. The following functions still need implementation: + - [ ] [cv::cuda::VideoReader](https://docs.opencv.org/master/db/ded/classcv_1_1cudacodec_1_1VideoReader.html) + - [ ] [cv::cuda::VideoWriter](https://docs.opencv.org/master/df/dde/classcv_1_1cudacodec_1_1VideoWriter.html) + +- [ ] **cudafeatures2d** Feature Detection and Description. The following functions still need implementation: + - [ ] [cv::cuda::FastFeatureDetector](https://docs.opencv.org/master/d4/d6a/classcv_1_1cuda_1_1FastFeatureDetector.html) + - [ ] [cv::cuda::ORB](https://docs.opencv.org/master/da/d44/classcv_1_1cuda_1_1ORB.html) + +- [ ] **cudafilters. Image Filtering - WORK STARTED** The following functions still need implementation: + - [ ] [cv::cuda::createBoxFilter](https://docs.opencv.org/master/dc/d66/group__cudafilters.html#ga3113b66e289bad7caef412e6e13ec2be) + - [ ] [cv::cuda::createBoxMaxFilter](https://docs.opencv.org/master/dc/d66/group__cudafilters.html#gaaf4740c51128d23a37f6f1b22cee49e8) + - [ ] [cv::cuda::createBoxMinFilter](https://docs.opencv.org/master/dc/d66/group__cudafilters.html#ga77fd36949bc8d92aabc120b4b1cfaafa) + - [ ] [cv::cuda::createColumnSumFilter](https://docs.opencv.org/master/dc/d66/group__cudafilters.html#gac13bf7c41a34bfde2a7f33ad8caacfdf) + - [ ] [cv::cuda::createDerivFilter](https://docs.opencv.org/master/dc/d66/group__cudafilters.html#ga14d76dc6982ce739c67198f52bc16ee1) + - [ ] [cv::cuda::createLaplacianFilter](https://docs.opencv.org/master/dc/d66/group__cudafilters.html#ga53126e88bb7e6185dcd5628e28e42cd2) + - [ ] [cv::cuda::createLinearFilter](https://docs.opencv.org/master/dc/d66/group__cudafilters.html#ga57cb1804ad9d1280bf86433858daabf9) + - [ ] [cv::cuda::createMorphologyFilter](https://docs.opencv.org/master/dc/d66/group__cudafilters.html#gae58694e07be6bdbae126f36c75c08ee6) + - [ ] [cv::cuda::createRowSumFilter](https://docs.opencv.org/master/dc/d66/group__cudafilters.html#gaf735de273ccb5072f3c27816fb97a53a) + - [ ] [cv::cuda::createScharrFilter](https://docs.opencv.org/master/dc/d66/group__cudafilters.html#ga4ac8df158e5771ddb0bd5c9091188ce6) + - [ ] [cv::cuda::createSeparableLinearFilter](https://docs.opencv.org/master/dc/d66/group__cudafilters.html#gaf7b79a9a92992044f328dad07a52c4bf) + +- [ ] **cudaimgproc. Image Processing - WORK STARTED** The following functions still need implementation: + - [X] [cv::cuda::TemplateMatching](https://docs.opencv.org/master/d2/d58/classcv_1_1cuda_1_1TemplateMatching.html) + - [ ] [cv::cuda::alphaComp](https://docs.opencv.org/master/db/d8c/group__cudaimgproc__color.html#ga08a698700458d9311390997b57fbf8dc) + - [ ] [cv::cuda::demosaicing](https://docs.opencv.org/master/db/d8c/group__cudaimgproc__color.html#ga7fb153572b573ebd2d7610fcbe64166e) + - [ ] [cv::cuda::gammaCorrection](https://docs.opencv.org/master/db/d8c/group__cudaimgproc__color.html#gaf4195a8409c3b8fbfa37295c2b2c4729) + - [ ] [cv::cuda::swapChannels](https://docs.opencv.org/master/db/d8c/group__cudaimgproc__color.html#ga75a29cc4a97cde0d43ea066b01de927e) + - [ ] [cv::cuda::calcHist](https://docs.opencv.org/master/d8/d0e/group__cudaimgproc__hist.html#gaaf3944106890947020bb4522a7619c26) + - [ ] [cv::cuda::CLAHE](https://docs.opencv.org/master/db/d79/classcv_1_1cuda_1_1CLAHE.html) + - [ ] [cv::cuda::equalizeHist](https://docs.opencv.org/master/d8/d0e/group__cudaimgproc__hist.html#ga2384be74bd2feba7e6c46815513f0060) + - [ ] [cv::cuda::evenLevels](https://docs.opencv.org/master/d8/d0e/group__cudaimgproc__hist.html#ga2f2cbd21dc6d7367a7c4ee1a826f389d) + - [ ] [cv::cuda::histEven](https://docs.opencv.org/master/d8/d0e/group__cudaimgproc__hist.html#gacd3b14279fb77a57a510cb8c89a1856f) + - [ ] [cv::cuda::histRange](https://docs.opencv.org/master/d8/d0e/group__cudaimgproc__hist.html#ga87819085c1059186d9cdeacd92cea783) + - [ ] [cv::cuda::HoughCirclesDetector](https://docs.opencv.org/master/da/d80/classcv_1_1cuda_1_1HoughCirclesDetector.html) + - [ ] [cv::cuda::createGoodFeaturesToTrackDetector](https://docs.opencv.org/master/dc/d6d/group__cudaimgproc__feature.html#ga478b474a598ece101f7e706fee2c8e91) + - [ ] [cv::cuda::createHarrisCorner](https://docs.opencv.org/master/dc/d6d/group__cudaimgproc__feature.html#ga3e5878a803e9bba51added0c10101979) + - [ ] [cv::cuda::createMinEigenValCorner](https://docs.opencv.org/master/dc/d6d/group__cudaimgproc__feature.html#ga7457fd4b53b025f990b1c1dd1b749915) + - [ ] [cv::cuda::bilateralFilter](https://docs.opencv.org/master/d0/d05/group__cudaimgproc.html#ga6abeaecdd4e7edc0bd1393a04f4f20bd) + - [ ] [cv::cuda::blendLinear](https://docs.opencv.org/master/d0/d05/group__cudaimgproc.html#ga4793607e5729bcc15b27ea33d9fe335e) + - [ ] [cv::cuda::meanShiftFiltering](https://docs.opencv.org/master/d0/d05/group__cudaimgproc.html#gae13b3035bc6df0e512d876dbb8c00555) + - [ ] [cv::cuda::meanShiftProc](https://docs.opencv.org/master/d0/d05/group__cudaimgproc.html#ga6039dc8ecbe2f912bc83fcc9b3bcca39) + - [ ] [cv::cuda::meanShiftSegmentation](https://docs.opencv.org/master/d0/d05/group__cudaimgproc.html#ga70ed80533a448829dc48cf22b1845c16) + +- [X] **cudaobjdetect. Object Detection** + +- [ ] **cudaoptflow. Optical Flow - WORK STARTED** The following functions still need implementation: + - [ ] [BroxOpticalFlow](https://docs.opencv.org/master/d7/d18/classcv_1_1cuda_1_1BroxOpticalFlow.html) + - [ ] [DenseOpticalFlow](https://docs.opencv.org/master/d6/d4a/classcv_1_1cuda_1_1DenseOpticalFlow.html) + - [ ] [DensePyrLKOpticalFlow](https://docs.opencv.org/master/d0/da4/classcv_1_1cuda_1_1DensePyrLKOpticalFlow.html) + - [ ] [FarnebackOpticalFlow](https://docs.opencv.org/master/d9/d30/classcv_1_1cuda_1_1FarnebackOpticalFlow.html) + - [ ] [NvidiaHWOpticalFlow](https://docs.opencv.org/master/d5/d26/classcv_1_1cuda_1_1NvidiaHWOpticalFlow.html) + - [ ] [NvidiaOpticalFlow_1_0](https://docs.opencv.org/master/dc/d9d/classcv_1_1cuda_1_1NvidiaOpticalFlow__1__0.html) + - [ ] [SparseOpticalFlow](https://docs.opencv.org/master/d5/dcf/classcv_1_1cuda_1_1SparseOpticalFlow.html) + - [ ] **[SparsePyrLKOpticalFlow](https://docs.opencv.org/master/d7/d05/classcv_1_1cuda_1_1SparsePyrLKOpticalFlow.html) - WORK STARTED** + +- [ ] **cudastereo** Stereo Correspondence + - [ ] [cv::cuda::createDisparityBilateralFilter](https://docs.opencv.org/master/dd/d47/group__cudastereo.html#gaafb5f9902f7a9e74cb2cd4e680569590) + - [ ] [cv::cuda::createStereoBeliefPropagation](https://docs.opencv.org/master/dd/d47/group__cudastereo.html#ga8d22dd80bdfb4e3d7d2ac09e8a07c22b) + - [ ] [cv::cuda::createStereoBM](https://docs.opencv.org/master/dd/d47/group__cudastereo.html#ga77edc901350dd0a7f46ec5aca4138039) + - [ ] [cv::cuda::createStereoConstantSpaceBP](https://docs.opencv.org/master/dd/d47/group__cudastereo.html#gaec3b49c7cf9f7701a6f549a227be4df2) + - [ ] [cv::cuda::createStereoSGM](https://docs.opencv.org/master/dd/d47/group__cudastereo.html#gafb7e5284de5f488d664c3155acb12c93) + - [ ] [cv::cuda::drawColorDisp](https://docs.opencv.org/master/dd/d47/group__cudastereo.html#ga469b23a77938dd7c06861e59cecc08c5) + - [ ] [cv::cuda::reprojectImageTo3D](https://docs.opencv.org/master/dd/d47/group__cudastereo.html#gaff851e3932da0f3e74d1be1d8855f094) + +- [X] **cudawarping. Image Warping** + +## Contrib modules list + +- [ ] alphamat. Alpha Matting +- [ ] barcode. Barcode detecting and decoding methods +- [X] **bgsegm. Improved Background-Foreground Segmentation Methods - WORK STARTED** +- [ ] bioinspired. Biologically inspired vision models and derivated tools +- [ ] ccalib. Custom Calibration Pattern for 3D reconstruction +- [ ] cnn_3dobj. 3D object recognition and pose estimation API +- [ ] cvv. GUI for Interactive Visual Debugging of Computer Vision Programs +- [ ] datasets. Framework for working with different datasets +- [ ] dnn_modern. Deep Learning Modern Module +- [ ] dnn_objdetect. DNN used for object detection +- [ ] dnn_superres. DNN used for super resolution +- [ ] dpm. Deformable Part-based Models +- [ ] **face. Face Recognition - WORK STARTED** +- [ ] freetype. Drawing UTF-8 strings with freetype/harfbuzz +- [ ] fuzzy. Image processing based on fuzzy mathematics +- [ ] hdf. Hierarchical Data Format I/O routines +- [ ] hfs. Hierarchical Feature Selection for Efficient Image Segmentation +- [X] **img_hash. The module brings implementations of different image hashing algorithms.** +- [ ] intensity_transform. The module brings implementations of intensity transformation algorithms to adjust image contrast. +- [ ] line_descriptor. Binary descriptors for lines extracted from an image +- [ ] mcc. Macbeth Chart module +- [ ] optflow. Optical Flow Algorithms +- [ ] ovis. OGRE 3D Visualiser +- [ ] phase_unwrapping. Phase Unwrapping API +- [ ] plot. Plot function for Mat data +- [ ] quality. Image Quality Analysis (IQA) API +- [ ] rapid. silhouette based 3D object tracking +- [ ] reg. Image Registration +- [ ] rgbd. RGB-Depth Processing +- [ ] saliency. Saliency API +- [ ] sfm. Structure From Motion +- [ ] shape. Shape Distance and Matching +- [ ] stereo. Stereo Correspondance Algorithms +- [ ] structured_light. Structured Light API +- [ ] superres. Super Resolution +- [ ] surface_matching. Surface Matching +- [ ] text. Scene Text Detection and Recognition +- [ ] **tracking. Tracking API - WORK STARTED** +- [ ] videostab. Video Stabilization +- [ ] viz. 3D Visualizer +- [X] **wechat_qrcode. WeChat QR code detector for detecting and parsing QR code** +- [ ] **xfeatures2d. Extra 2D Features Framework - WORK STARTED** +- [ ] **ximgproc. Extended Image Processing - WORK STARTED** +- [ ] xobjdetect. Extended object detection +- [X] **xphoto. Additional photo processing algorithms** diff --git a/vendor/gocv.io/x/gocv/appveyor.yml b/vendor/gocv.io/x/gocv/appveyor.yml new file mode 100644 index 00000000..8af38ef2 --- /dev/null +++ b/vendor/gocv.io/x/gocv/appveyor.yml @@ -0,0 +1,36 @@ +version: "{build}" + +clone_folder: c:\gopath\src\gocv.io\x\gocv + +platform: + - MinGW_x64 + +environment: + GOPATH: c:\gopath + GOROOT: c:\go + GOVERSION: 1.19 + TEST_EXTERNAL: 1 + APPVEYOR_SAVE_CACHE_ON_ERROR: true + +cache: + - C:\opencv -> appveyor_build_opencv.cmd + +install: + - if not exist "C:\opencv" appveyor_build_opencv.cmd + - set PATH=C:\Perl\site\bin;C:\Perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\7-Zip;C:\Program Files\Microsoft\Web Platform Installer\;C:\Tools\PsTools;C:\Program Files (x86)\CMake\bin;C:\go\bin;C:\Tools\NuGet;C:\Program Files\LLVM\bin;C:\Tools\curl\bin;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\Yarn\bin;C:\Users\appveyor\AppData\Local\Yarn\bin;C:\Program Files\AppVeyor\BuildAgent\ + - set PATH=%PATH%;C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin + - set PATH=%PATH%;C:\Tools\GitVersion;C:\Program Files\Git LFS;C:\Program Files\Git\cmd;C:\Program Files\Git\usr\bin;C:\opencv\build\install\x64\mingw\bin; + - echo %PATH% + - echo %GOPATH% + - go version + - cd c:\gopath\src\gocv.io\x\gocv + - go get -d . + - set GOCV_CAFFE_TEST_FILES=C:\opencv\testdata + - set GOCV_TENSORFLOW_TEST_FILES=C:\opencv\testdata + - set GOCV_ONNX_TEST_FILES=C:\opencv\testdata + - set OPENCV_ENABLE_NONFREE=ON + - go env + +build_script: + - go test -tags matprofile -v . + - go test -tags matprofile -v ./contrib diff --git a/vendor/gocv.io/x/gocv/appveyor_build_opencv.cmd b/vendor/gocv.io/x/gocv/appveyor_build_opencv.cmd new file mode 100644 index 00000000..76c9171c --- /dev/null +++ b/vendor/gocv.io/x/gocv/appveyor_build_opencv.cmd @@ -0,0 +1,29 @@ + +if not exist "C:\opencv" mkdir "C:\opencv" +if not exist "C:\opencv\build" mkdir "C:\opencv\build" +if not exist "C:\opencv\testdata" mkdir "C:\opencv\testdata" + +appveyor DownloadFile https://github.com/opencv/opencv/archive/4.7.0.zip -FileName c:\opencv\opencv-4.7.0.zip +7z x c:\opencv\opencv-4.7.0.zip -oc:\opencv -y +del c:\opencv\opencv-4.7.0.zip /q +appveyor DownloadFile https://github.com/opencv/opencv_contrib/archive/4.7.0.zip -FileName c:\opencv\opencv_contrib-4.7.0.zip +7z x c:\opencv\opencv_contrib-4.7.0.zip -oc:\opencv -y +del c:\opencv\opencv_contrib-4.7.0.zip /q +cd C:\opencv\build +set PATH=C:\Perl\site\bin;C:\Perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\7-Zip;C:\Program Files\Microsoft\Web Platform Installer\;C:\Tools\PsTools;C:\Program Files (x86)\CMake\bin;C:\go\bin;C:\Tools\NuGet;C:\Program Files\LLVM\bin;C:\Tools\curl\bin;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\Yarn\bin;C:\Users\appveyor\AppData\Local\Yarn\bin;C:\Program Files\AppVeyor\BuildAgent\ +set PATH=%PATH%;C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin +dir C:\opencv +cmake C:\opencv\opencv-4.7.0 -G "MinGW Makefiles" -BC:\opencv\build -DENABLE_CXX11=ON -DOPENCV_EXTRA_MODULES_PATH=C:\opencv\opencv_contrib-4.7.0\modules -DBUILD_SHARED_LIBS=ON -DWITH_IPP=OFF -DWITH_MSMF=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=ON -DBUILD_opencv_java=OFF -DBUILD_opencv_python=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DBUILD_DOCS=OFF -DENABLE_PRECOMPILED_HEADERS=OFF -DBUILD_opencv_saliency=OFF -DBUILD_opencv_wechat_qrcode=ON -DCPU_DISPATCH= -DBUILD_opencv_gapi=OFF -DOPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_ENABLE_NONFREE=ON -DWITH_OPENCL_D3D11_NV=OFF -DOPENCV_ALLOCATOR_STATS_COUNTER_TYPE=int64_t -DWITH_TBB=ON -Wno-dev +mingw32-make -j%NUMBER_OF_PROCESSORS% +mingw32-make install +appveyor DownloadFile https://raw.githubusercontent.com/opencv/opencv_extra/master/testdata/dnn/bvlc_googlenet.prototxt -FileName C:\opencv\testdata\bvlc_googlenet.prototxt +appveyor DownloadFile https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/wechat_qrcode/detect.caffemodel -FileName C:\opencv\testdata\detect.caffemodel +appveyor DownloadFile https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/wechat_qrcode/detect.prototxt -FileName C:\opencv\testdata\detect.prototxt +appveyor DownloadFile https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/wechat_qrcode/sr.caffemodel -FileName C:\opencv\testdata\sr.caffemodel +appveyor DownloadFile https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/wechat_qrcode/sr.prototxt -FileName C:\opencv\testdata\sr.prototxt +appveyor DownloadFile http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel -FileName C:\opencv\testdata\bvlc_googlenet.caffemodel +appveyor DownloadFile https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip -FileName C:\opencv\testdata\inception5h.zip +appveyor DownloadFile https://github.com/onnx/models/raw/main/vision/classification/inception_and_googlenet/googlenet/model/googlenet-9.onnx -FileName C:\opencv\testdata\googlenet-9.onnx +7z x C:\opencv\testdata\inception5h.zip -oC:\opencv\testdata tensorflow_inception_graph.pb -y +rmdir c:\opencv\opencv-4.7.0 /s /q +rmdir c:\opencv\opencv_contrib-4.7.0 /s /q diff --git a/vendor/gocv.io/x/gocv/aruco.cpp b/vendor/gocv.io/x/gocv/aruco.cpp new file mode 100644 index 00000000..a65f897f --- /dev/null +++ b/vendor/gocv.io/x/gocv/aruco.cpp @@ -0,0 +1,287 @@ +#include "aruco.h" + +ArucoDetector ArucoDetector_New() { + return new cv::aruco::ArucoDetector(); +} + +ArucoDetector ArucoDetector_NewWithParams(ArucoDictionary dictionary, ArucoDetectorParameters params) { + return new cv::aruco::ArucoDetector(*dictionary, *params); +} + +void ArucoDetector_Close(ArucoDetector ad) { + delete ad; +} + +void ArucoDetector_DetectMarkers(ArucoDetector ad, Mat inputArr, Points2fVector markerCorners, IntVector *markerIds, Points2fVector rejectedCandidates) { + std::vector _markerIds; + ad->detectMarkers(*inputArr, *markerCorners, _markerIds, *rejectedCandidates); + + int *ids = new int[_markerIds.size()]; + + for (size_t i = 0; i < _markerIds.size(); ++i) + { + ids[i] = _markerIds[i]; + } + + markerIds->length = _markerIds.size(); + markerIds->val = ids; +} + +ArucoDetectorParameters ArucoDetectorParameters_Create() +{ + return new cv::aruco::DetectorParameters(); +} + +void ArucoDetectorParameters_SetAdaptiveThreshWinSizeMin(ArucoDetectorParameters ap, int adaptiveThreshWinSizeMin) { + ap->adaptiveThreshWinSizeMin = adaptiveThreshWinSizeMin; +} + +int ArucoDetectorParameters_GetAdaptiveThreshWinSizeMin(ArucoDetectorParameters ap) { + return ap->adaptiveThreshWinSizeMin; +} + +void ArucoDetectorParameters_SetAdaptiveThreshWinSizeMax(ArucoDetectorParameters ap, int adaptiveThreshWinSizeMax) { + ap->adaptiveThreshWinSizeMax = adaptiveThreshWinSizeMax; +} + +int ArucoDetectorParameters_GetAdaptiveThreshWinSizeMax(ArucoDetectorParameters ap) { + return ap->adaptiveThreshWinSizeMax; +} + +void ArucoDetectorParameters_SetAdaptiveThreshWinSizeStep(ArucoDetectorParameters ap, int adaptiveThreshWinSizeStep) { + ap->adaptiveThreshWinSizeStep = adaptiveThreshWinSizeStep; +} + +int ArucoDetectorParameters_GetAdaptiveThreshWinSizeStep(ArucoDetectorParameters ap) { + return ap->adaptiveThreshWinSizeStep; +} + +void ArucoDetectorParameters_SetAdaptiveThreshConstant(ArucoDetectorParameters ap, double adaptiveThreshConstant) { + ap->adaptiveThreshConstant = adaptiveThreshConstant; +} + +double ArucoDetectorParameters_GetAdaptiveThreshConstant(ArucoDetectorParameters ap) { + return ap->adaptiveThreshConstant; +} + +void ArucoDetectorParameters_SetMinMarkerPerimeterRate(ArucoDetectorParameters ap, double minMarkerPerimeterRate) { + ap->minMarkerPerimeterRate = minMarkerPerimeterRate; +} + +double ArucoDetectorParameters_GetMinMarkerPerimeterRate(ArucoDetectorParameters ap){ + return ap->minMarkerPerimeterRate; +} + +void ArucoDetectorParameters_SetMaxMarkerPerimeterRate(ArucoDetectorParameters ap, double maxMarkerPerimeterRate) { + ap->maxMarkerPerimeterRate = maxMarkerPerimeterRate; +} + +double ArucoDetectorParameters_GetMaxMarkerPerimeterRate(ArucoDetectorParameters ap){ + return ap->maxMarkerPerimeterRate; +} + +void ArucoDetectorParameters_SetPolygonalApproxAccuracyRate(ArucoDetectorParameters ap, double polygonalApproxAccuracyRate) { + ap->polygonalApproxAccuracyRate = polygonalApproxAccuracyRate; +} + +double ArucoDetectorParameters_GetPolygonalApproxAccuracyRate(ArucoDetectorParameters ap){ + return ap->polygonalApproxAccuracyRate; +} + +void ArucoDetectorParameters_SetMinCornerDistanceRate(ArucoDetectorParameters ap, double minCornerDistanceRate) { + ap->minCornerDistanceRate = minCornerDistanceRate; +} + +double ArucoDetectorParameters_GetMinCornerDistanceRate(ArucoDetectorParameters ap) { + return ap->minCornerDistanceRate; +} + +void ArucoDetectorParameters_SetMinDistanceToBorder(ArucoDetectorParameters ap, int minDistanceToBorder) { + ap->minDistanceToBorder = minDistanceToBorder; +} + +int ArucoDetectorParameters_GetMinDistanceToBorder(ArucoDetectorParameters ap) { + return ap->minDistanceToBorder; +} + +void ArucoDetectorParameters_SetMinMarkerDistanceRate(ArucoDetectorParameters ap, double minMarkerDistanceRate) { + ap->minMarkerDistanceRate = minMarkerDistanceRate; +} + +double ArucoDetectorParameters_GetMinMarkerDistanceRate(ArucoDetectorParameters ap) { + return ap->minMarkerDistanceRate; +} + +void ArucoDetectorParameters_SetCornerRefinementMethod(ArucoDetectorParameters ap, int cornerRefinementMethod) { + ap->cornerRefinementMethod = cv::aruco::CornerRefineMethod(cornerRefinementMethod); +} + +int ArucoDetectorParameters_GetCornerRefinementMethod(ArucoDetectorParameters ap) { + return ap->cornerRefinementMethod; +} + +void ArucoDetectorParameters_SetCornerRefinementWinSize(ArucoDetectorParameters ap, int cornerRefinementWinSize) { + ap->cornerRefinementWinSize = cornerRefinementWinSize; +} + +int ArucoDetectorParameters_GetCornerRefinementWinSize(ArucoDetectorParameters ap) { + return ap->cornerRefinementWinSize; +} + +void ArucoDetectorParameters_SetCornerRefinementMaxIterations(ArucoDetectorParameters ap, int cornerRefinementMaxIterations) { + ap->cornerRefinementMaxIterations = cornerRefinementMaxIterations; +} + +int ArucoDetectorParameters_GetCornerRefinementMaxIterations(ArucoDetectorParameters ap) { + return ap->cornerRefinementMaxIterations; +} + +void ArucoDetectorParameters_SetCornerRefinementMinAccuracy(ArucoDetectorParameters ap, double cornerRefinementMinAccuracy) { + ap->cornerRefinementMinAccuracy = cornerRefinementMinAccuracy; +} + +double ArucoDetectorParameters_GetCornerRefinementMinAccuracy(ArucoDetectorParameters ap) { + return ap->cornerRefinementMinAccuracy; +} + +void ArucoDetectorParameters_SetMarkerBorderBits(ArucoDetectorParameters ap, int markerBorderBits) { + ap->markerBorderBits = markerBorderBits; +} + +int ArucoDetectorParameters_GetMarkerBorderBits(ArucoDetectorParameters ap) { + return ap->markerBorderBits; +} + +void ArucoDetectorParameters_SetPerspectiveRemovePixelPerCell(ArucoDetectorParameters ap, int perspectiveRemovePixelPerCell) { + ap->perspectiveRemovePixelPerCell = perspectiveRemovePixelPerCell; +} + +int ArucoDetectorParameters_GetPerspectiveRemovePixelPerCell(ArucoDetectorParameters ap) { + return ap->perspectiveRemovePixelPerCell; +} + +void ArucoDetectorParameters_SetPerspectiveRemoveIgnoredMarginPerCell(ArucoDetectorParameters ap, double perspectiveRemoveIgnoredMarginPerCell) { + ap->perspectiveRemoveIgnoredMarginPerCell = perspectiveRemoveIgnoredMarginPerCell; +} + +double ArucoDetectorParameters_GetPerspectiveRemoveIgnoredMarginPerCell(ArucoDetectorParameters ap) { + return ap->perspectiveRemoveIgnoredMarginPerCell; +} + +void ArucoDetectorParameters_SetMaxErroneousBitsInBorderRate(ArucoDetectorParameters ap, double maxErroneousBitsInBorderRate) { + ap->maxErroneousBitsInBorderRate = maxErroneousBitsInBorderRate; +} + +double ArucoDetectorParameters_GetMaxErroneousBitsInBorderRate(ArucoDetectorParameters ap) { + return ap->maxErroneousBitsInBorderRate; +} + +void ArucoDetectorParameters_SetMinOtsuStdDev(ArucoDetectorParameters ap, double minOtsuStdDev) { + ap->minOtsuStdDev = minOtsuStdDev; +} + +double ArucoDetectorParameters_GetMinOtsuStdDev(ArucoDetectorParameters ap) { + return ap->minOtsuStdDev; +} + +void ArucoDetectorParameters_SetErrorCorrectionRate(ArucoDetectorParameters ap, double errorCorrectionRate) { + ap->errorCorrectionRate = errorCorrectionRate; +} + +double ArucoDetectorParameters_GetErrorCorrectionRate(ArucoDetectorParameters ap) { + return ap->errorCorrectionRate; +} + +void ArucoDetectorParameters_SetAprilTagQuadDecimate(ArucoDetectorParameters ap, float aprilTagQuadDecimate) { + ap->aprilTagQuadDecimate = aprilTagQuadDecimate; +} + +float ArucoDetectorParameters_GetAprilTagQuadDecimate(ArucoDetectorParameters ap) { + return ap->aprilTagQuadDecimate; +} + +void ArucoDetectorParameters_SetAprilTagQuadSigma(ArucoDetectorParameters ap, float aprilTagQuadSigma) { + ap->aprilTagQuadSigma = aprilTagQuadSigma; +} + +float ArucoDetectorParameters_GetAprilTagQuadSigma(ArucoDetectorParameters ap) { + return ap->aprilTagQuadSigma; +} + +void ArucoDetectorParameters_SetAprilTagMinClusterPixels(ArucoDetectorParameters ap, int aprilTagMinClusterPixels) { + ap->aprilTagMinClusterPixels = aprilTagMinClusterPixels; +} + +int ArucoDetectorParameters_GetAprilTagMinClusterPixels(ArucoDetectorParameters ap) { + return ap->aprilTagMinClusterPixels; +} + +void ArucoDetectorParameters_SetAprilTagMaxNmaxima(ArucoDetectorParameters ap, int aprilTagMaxNmaxima) { + ap->aprilTagMaxNmaxima = aprilTagMaxNmaxima; +} + +int ArucoDetectorParameters_GetAprilTagMaxNmaxima(ArucoDetectorParameters ap) { + return ap->aprilTagMaxNmaxima; +} + +void ArucoDetectorParameters_SetAprilTagCriticalRad(ArucoDetectorParameters ap, float aprilTagCriticalRad) { + ap->aprilTagCriticalRad = aprilTagCriticalRad; +} + +float ArucoDetectorParameters_GetAprilTagCriticalRad(ArucoDetectorParameters ap) { + return ap->aprilTagCriticalRad; +} + +void ArucoDetectorParameters_SetAprilTagMaxLineFitMse(ArucoDetectorParameters ap, float aprilTagMaxLineFitMse) { + ap->aprilTagMaxLineFitMse = aprilTagMaxLineFitMse; +} + +float ArucoDetectorParameters_GetAprilTagMaxLineFitMse(ArucoDetectorParameters ap) { + return ap->aprilTagMaxLineFitMse; +} + +void ArucoDetectorParameters_SetAprilTagMinWhiteBlackDiff(ArucoDetectorParameters ap, int aprilTagMinWhiteBlackDiff) { + ap->aprilTagMinWhiteBlackDiff = aprilTagMinWhiteBlackDiff; +} + +int ArucoDetectorParameters_GetAprilTagMinWhiteBlackDiff(ArucoDetectorParameters ap) { + return ap->aprilTagMinWhiteBlackDiff; +} + +void ArucoDetectorParameters_SetAprilTagDeglitch(ArucoDetectorParameters ap, int aprilTagDeglitch) { + ap->aprilTagDeglitch = aprilTagDeglitch; +} + +int ArucoDetectorParameters_GetAprilTagDeglitch(ArucoDetectorParameters ap) { + return ap->aprilTagDeglitch; +} + +void ArucoDetectorParameters_SetDetectInvertedMarker(ArucoDetectorParameters ap, bool detectInvertedMarker) { + ap->detectInvertedMarker = detectInvertedMarker; +} + +bool ArucoDetectorParameters_GetDetectInvertedMarker(ArucoDetectorParameters ap) { + return ap->detectInvertedMarker; +} + +void ArucoDrawDetectedMarkers(Mat image, Points2fVector markerCorners, IntVector markerIds, Scalar borderColor) +{ + std::vector _markerIds; + for (int i = 0, *v = markerIds.val; i < markerIds.length; ++v, ++i) + { + _markerIds.push_back(*v); + } + cv::Scalar _borderColor = cv::Scalar(borderColor.val1, borderColor.val2, borderColor.val3); + cv::aruco::drawDetectedMarkers(*image, *markerCorners, _markerIds, _borderColor); +} + +void ArucoGenerateImageMarker(int dictionaryId, int id, int sidePixels, Mat img, int borderBits) +{ + cv::aruco::Dictionary dict = cv::aruco::getPredefinedDictionary(dictionaryId); + cv::aruco::generateImageMarker(dict, id, sidePixels, *img, borderBits); +} + +ArucoDictionary getPredefinedDictionary(int dictionaryId) +{ + return new cv::aruco::Dictionary(cv::aruco::getPredefinedDictionary(dictionaryId)); +} \ No newline at end of file diff --git a/vendor/gocv.io/x/gocv/aruco.go b/vendor/gocv.io/x/gocv/aruco.go new file mode 100644 index 00000000..171921c8 --- /dev/null +++ b/vendor/gocv.io/x/gocv/aruco.go @@ -0,0 +1,337 @@ +package gocv + +/* +#include +#include "aruco.h" +#include "core.h" +*/ +import "C" + +import ( + "reflect" + "unsafe" +) + +type ArucoDetector struct { + p C.ArucoDetector +} + +// NewArucoDetector returns a new ArucoDetector. +func NewArucoDetector() ArucoDetector { + return ArucoDetector{p: C.ArucoDetector_New()} +} + +// NewArucoDetectorWithParams returns a new ArucoDetector. +func NewArucoDetectorWithParams(dictionary ArucoDictionary, params ArucoDetectorParameters) ArucoDetector { + return ArucoDetector{p: C.ArucoDetector_NewWithParams(dictionary.p, params.p)} +} + +// Close deletes the ArucoDetector's pointer. +func (a *ArucoDetector) Close() error { + C.ArucoDetector_Close(a.p) + a.p = nil + return nil +} + +// DetectMarkers does basic marker detection. +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d6a/group__aruco.html#gab9159aa69250d8d3642593e508cb6baa +func (a *ArucoDetector) DetectMarkers(input Mat) ( + markerCorners [][]Point2f, markerIds []int, rejectedCandidates [][]Point2f, +) { + + pvsCorners := NewPoints2fVector() + defer pvsCorners.Close() + pvsRejected := NewPoints2fVector() + defer pvsRejected.Close() + cmarkerIds := C.IntVector{} + defer C.free(unsafe.Pointer(cmarkerIds.val)) + + C.ArucoDetector_DetectMarkers(a.p, C.Mat(input.Ptr()), C.Points2fVector(pvsCorners.P()), + &cmarkerIds, C.Points2fVector(pvsRejected.P())) + + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(cmarkerIds.val)), + Len: int(cmarkerIds.length), + Cap: int(cmarkerIds.length), + } + pcids := *(*[]C.int)(unsafe.Pointer(h)) + markerIds = []int{} + for i := 0; i < int(cmarkerIds.length); i++ { + markerIds = append(markerIds, int(pcids[i])) + } + + return pvsCorners.ToPoints(), markerIds, pvsRejected.ToPoints() +} + +func ArucoDrawDetectedMarkers(img Mat, markerCorners [][]Point2f, markerIds []int, borderColor Scalar) { + cMarkerIds := make([]C.int, len(markerIds)) + for i, s := range markerIds { + cMarkerIds[i] = C.int(s) + } + markerIdsIntVec := C.IntVector{ + val: (*C.int)(&cMarkerIds[0]), + length: C.int(len(cMarkerIds)), + } + _markerCorners := NewPoints2fVectorFromPoints(markerCorners) + + cBorderColor := C.struct_Scalar{ + val1: C.double(borderColor.Val1), + val2: C.double(borderColor.Val2), + val3: C.double(borderColor.Val3), + val4: C.double(borderColor.Val4), + } + + C.ArucoDrawDetectedMarkers( + C.Mat(img.Ptr()), + C.Points2fVector(_markerCorners.P()), + markerIdsIntVec, + cBorderColor, + ) +} + +func ArucoGenerateImageMarker(dictionaryId ArucoDictionaryCode, id int, sidePixels int, img Mat, borderBits int) { + C.ArucoGenerateImageMarker(C.int(dictionaryId), C.int(id), C.int(sidePixels), C.Mat(img.Ptr()), C.int(borderBits)) +} + +type ArucoDetectorParameters struct { + p C.ArucoDetectorParameters +} + +// NewArucoDetectorParameters returns the default parameters for the SimpleBobDetector +func NewArucoDetectorParameters() ArucoDetectorParameters { + return ArucoDetectorParameters{p: C.ArucoDetectorParameters_Create()} +} + +func (ap *ArucoDetectorParameters) SetAdaptiveThreshWinSizeMin(adaptiveThreshWinSizeMin int) { + C.ArucoDetectorParameters_SetAdaptiveThreshWinSizeMin(ap.p, C.int(adaptiveThreshWinSizeMin)) +} + +func (ap *ArucoDetectorParameters) GetAdaptiveThreshWinSizeMin() int { + return int(C.ArucoDetectorParameters_GetAdaptiveThreshWinSizeMin(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetAdaptiveThreshWinSizeMax(adaptiveThreshWinSizeMax int) { + C.ArucoDetectorParameters_SetAdaptiveThreshWinSizeMax(ap.p, C.int(adaptiveThreshWinSizeMax)) +} + +func (ap *ArucoDetectorParameters) GetAdaptiveThreshWinSizeMax() int { + return int(C.ArucoDetectorParameters_GetAdaptiveThreshWinSizeMax(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetAdaptiveThreshWinSizeStep(adaptiveThreshWinSizeStep int) { + C.ArucoDetectorParameters_SetAdaptiveThreshWinSizeStep(ap.p, C.int(adaptiveThreshWinSizeStep)) +} + +func (ap *ArucoDetectorParameters) GetAdaptiveThreshWinSizeStep() int { + return int(C.ArucoDetectorParameters_GetAdaptiveThreshWinSizeStep(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetAdaptiveThreshConstant(adaptiveThreshConstant float64) { + C.ArucoDetectorParameters_SetAdaptiveThreshConstant(ap.p, C.double(adaptiveThreshConstant)) +} + +func (ap *ArucoDetectorParameters) GetAdaptiveThreshConstant() float64 { + return float64(C.ArucoDetectorParameters_GetAdaptiveThreshConstant(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetMinMarkerPerimeterRate(minMarkerPerimeterRate float64) { + C.ArucoDetectorParameters_SetMinMarkerPerimeterRate(ap.p, C.double(minMarkerPerimeterRate)) +} + +func (ap *ArucoDetectorParameters) GetMinMarkerPerimeterRate() float64 { + return float64(C.ArucoDetectorParameters_GetMinMarkerPerimeterRate(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetMaxMarkerPerimeterRate(maxMarkerPerimeterRate float64) { + C.ArucoDetectorParameters_SetMaxMarkerPerimeterRate(ap.p, C.double(maxMarkerPerimeterRate)) +} + +func (ap *ArucoDetectorParameters) GetMaxMarkerPerimeterRate() float64 { + return float64(C.ArucoDetectorParameters_GetMaxMarkerPerimeterRate(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetPolygonalApproxAccuracyRate(polygonalApproxAccuracyRate float64) { + C.ArucoDetectorParameters_SetPolygonalApproxAccuracyRate(ap.p, C.double(polygonalApproxAccuracyRate)) +} + +func (ap *ArucoDetectorParameters) GetPolygonalApproxAccuracyRate() float64 { + return float64(C.ArucoDetectorParameters_GetPolygonalApproxAccuracyRate(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetMinCornerDistanceRate(minCornerDistanceRate float64) { + C.ArucoDetectorParameters_SetMinCornerDistanceRate(ap.p, C.double(minCornerDistanceRate)) +} + +func (ap *ArucoDetectorParameters) GetMinCornerDistanceRate() float64 { + return float64(C.ArucoDetectorParameters_GetMinCornerDistanceRate(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetMinDistanceToBorder(minDistanceToBorder int) { + C.ArucoDetectorParameters_SetMinDistanceToBorder(ap.p, C.int(minDistanceToBorder)) +} + +func (ap *ArucoDetectorParameters) GetMinDistanceToBorder() int { + return int(C.ArucoDetectorParameters_GetMinDistanceToBorder(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetMinMarkerDistanceRate(minMarkerDistanceRate float64) { + C.ArucoDetectorParameters_SetMinMarkerDistanceRate(ap.p, C.double(minMarkerDistanceRate)) +} + +func (ap *ArucoDetectorParameters) GetMinMarkerDistanceRate() float64 { + return float64(C.ArucoDetectorParameters_GetMinMarkerDistanceRate(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetCornerRefinementMethod(cornerRefinementMethod int) { + C.ArucoDetectorParameters_SetCornerRefinementMethod(ap.p, C.int(cornerRefinementMethod)) +} + +func (ap *ArucoDetectorParameters) GetCornerRefinementMethod() int { + return int(C.ArucoDetectorParameters_GetCornerRefinementMethod(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetCornerRefinementWinSize(cornerRefinementWinSize int) { + C.ArucoDetectorParameters_SetCornerRefinementWinSize(ap.p, C.int(cornerRefinementWinSize)) +} + +func (ap *ArucoDetectorParameters) GetCornerRefinementWinSize() int { + return int(C.ArucoDetectorParameters_GetCornerRefinementWinSize(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetCornerRefinementMaxIterations(cornerRefinementMaxIterations int) { + C.ArucoDetectorParameters_SetCornerRefinementMaxIterations(ap.p, C.int(cornerRefinementMaxIterations)) +} + +func (ap *ArucoDetectorParameters) GetCornerRefinementMaxIterations() int { + return int(C.ArucoDetectorParameters_GetCornerRefinementMaxIterations(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetCornerRefinementMinAccuracy(cornerRefinementMinAccuracy float64) { + C.ArucoDetectorParameters_SetCornerRefinementMinAccuracy(ap.p, C.double(cornerRefinementMinAccuracy)) +} + +func (ap *ArucoDetectorParameters) GetCornerRefinementMinAccuracy() float64 { + return float64(C.ArucoDetectorParameters_GetCornerRefinementMinAccuracy(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetMarkerBorderBits(markerBorderBits int) { + C.ArucoDetectorParameters_SetMarkerBorderBits(ap.p, C.int(markerBorderBits)) +} + +func (ap *ArucoDetectorParameters) GetMarkerBorderBits() int { + return int(C.ArucoDetectorParameters_GetMarkerBorderBits(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetPerspectiveRemovePixelPerCell(perspectiveRemovePixelPerCell int) { + C.ArucoDetectorParameters_SetPerspectiveRemovePixelPerCell(ap.p, C.int(perspectiveRemovePixelPerCell)) +} + +func (ap *ArucoDetectorParameters) GetPerspectiveRemovePixelPerCell() int { + return int(C.ArucoDetectorParameters_GetPerspectiveRemovePixelPerCell(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetPerspectiveRemoveIgnoredMarginPerCell(perspectiveRemoveIgnoredMarginPerCell float64) { + C.ArucoDetectorParameters_SetPerspectiveRemoveIgnoredMarginPerCell(ap.p, C.double(perspectiveRemoveIgnoredMarginPerCell)) +} + +func (ap *ArucoDetectorParameters) GetPerspectiveRemoveIgnoredMarginPerCell() float64 { + return float64(C.ArucoDetectorParameters_GetPerspectiveRemoveIgnoredMarginPerCell(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetMaxErroneousBitsInBorderRate(maxErroneousBitsInBorderRate float64) { + C.ArucoDetectorParameters_SetMaxErroneousBitsInBorderRate(ap.p, C.double(maxErroneousBitsInBorderRate)) +} + +func (ap *ArucoDetectorParameters) GetMaxErroneousBitsInBorderRate() float64 { + return float64(C.ArucoDetectorParameters_GetMaxErroneousBitsInBorderRate(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetMinOtsuStdDev(minOtsuStdDev float64) { + C.ArucoDetectorParameters_SetMinOtsuStdDev(ap.p, C.double(minOtsuStdDev)) +} + +func (ap *ArucoDetectorParameters) GetMinOtsuStdDev() float64 { + return float64(C.ArucoDetectorParameters_GetMinOtsuStdDev(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetErrorCorrectionRate(errorCorrectionRate float64) { + C.ArucoDetectorParameters_SetErrorCorrectionRate(ap.p, C.double(errorCorrectionRate)) +} + +func (ap *ArucoDetectorParameters) GetErrorCorrectionRate() float64 { + return float64(C.ArucoDetectorParameters_GetErrorCorrectionRate(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetAprilTagQuadDecimate(aprilTagQuadDecimate float32) { + C.ArucoDetectorParameters_SetAprilTagQuadDecimate(ap.p, C.float(aprilTagQuadDecimate)) +} + +func (ap *ArucoDetectorParameters) GetAprilTagQuadDecimate() float32 { + return float32(C.ArucoDetectorParameters_GetAprilTagQuadDecimate(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetAprilTagQuadSigma(aprilTagQuadSigma float32) { + C.ArucoDetectorParameters_SetAprilTagQuadSigma(ap.p, C.float(aprilTagQuadSigma)) +} + +func (ap *ArucoDetectorParameters) GetAprilTagQuadSigma() float32 { + return float32(C.ArucoDetectorParameters_GetAprilTagQuadSigma(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetAprilTagMinClusterPixels(aprilTagMinClusterPixels int) { + C.ArucoDetectorParameters_SetAprilTagMinClusterPixels(ap.p, C.int(aprilTagMinClusterPixels)) +} + +func (ap *ArucoDetectorParameters) GetAprilTagMinClusterPixels() int { + return int(C.ArucoDetectorParameters_GetAprilTagMinClusterPixels(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetAprilTagMaxNmaxima(aprilTagMaxNmaxima int) { + C.ArucoDetectorParameters_SetAprilTagMaxNmaxima(ap.p, C.int(aprilTagMaxNmaxima)) +} + +func (ap *ArucoDetectorParameters) GetAprilTagMaxNmaxima() int { + return int(C.ArucoDetectorParameters_GetAprilTagMaxNmaxima(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetAprilTagCriticalRad(aprilTagCriticalRad float32) { + C.ArucoDetectorParameters_SetAprilTagCriticalRad(ap.p, C.float(aprilTagCriticalRad)) +} + +func (ap *ArucoDetectorParameters) GetAprilTagCriticalRad() float32 { + return float32(C.ArucoDetectorParameters_GetAprilTagCriticalRad(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetAprilTagMaxLineFitMse(aprilTagMaxLineFitMse float32) { + C.ArucoDetectorParameters_SetAprilTagMaxLineFitMse(ap.p, C.float(aprilTagMaxLineFitMse)) +} + +func (ap *ArucoDetectorParameters) GetAprilTagMaxLineFitMse() float32 { + return float32(C.ArucoDetectorParameters_GetAprilTagMaxLineFitMse(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetAprilTagMinWhiteBlackDiff(aprilTagMinWhiteBlackDiff int) { + C.ArucoDetectorParameters_SetAprilTagMinWhiteBlackDiff(ap.p, C.int(aprilTagMinWhiteBlackDiff)) +} + +func (ap *ArucoDetectorParameters) GetAprilTagMinWhiteBlackDiff() int { + return int(C.ArucoDetectorParameters_GetAprilTagMinWhiteBlackDiff(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetAprilTagDeglitch(aprilTagDeglitch int) { + C.ArucoDetectorParameters_SetAprilTagDeglitch(ap.p, C.int(aprilTagDeglitch)) +} + +func (ap *ArucoDetectorParameters) GetAprilTagDeglitch() int { + return int(C.ArucoDetectorParameters_GetAprilTagDeglitch(ap.p)) +} + +func (ap *ArucoDetectorParameters) SetDetectInvertedMarker(detectInvertedMarker bool) { + C.ArucoDetectorParameters_SetDetectInvertedMarker(ap.p, C.bool(detectInvertedMarker)) +} + +func (ap *ArucoDetectorParameters) GetDetectInvertedMarker() bool { + return bool(C.ArucoDetectorParameters_GetDetectInvertedMarker(ap.p)) +} diff --git a/vendor/gocv.io/x/gocv/aruco.h b/vendor/gocv.io/x/gocv/aruco.h new file mode 100644 index 00000000..4fe5482c --- /dev/null +++ b/vendor/gocv.io/x/gocv/aruco.h @@ -0,0 +1,96 @@ +#ifndef _OPENCV3_ARUCO_H_ +#define _OPENCV3_ARUCO_H_ + +#ifdef __cplusplus +#include +extern "C" { +#endif + +#include "core.h" + +#ifdef __cplusplus +typedef cv::aruco::Dictionary* ArucoDictionary; +typedef cv::aruco::DetectorParameters* ArucoDetectorParameters; +typedef cv::aruco::ArucoDetector* ArucoDetector; +#else +typedef void *ArucoDictionary; +typedef void *ArucoDetectorParameters; +typedef void *ArucoDetector; +#endif + +ArucoDetectorParameters ArucoDetectorParameters_Create(); +void ArucoDetectorParameters_SetAdaptiveThreshWinSizeMin(ArucoDetectorParameters ap, int adaptiveThreshWinSizeMin); +int ArucoDetectorParameters_GetAdaptiveThreshWinSizeMin(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetAdaptiveThreshWinSizeMax(ArucoDetectorParameters ap, int adaptiveThreshWinSizeMax); +int ArucoDetectorParameters_GetAdaptiveThreshWinSizeMax(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetAdaptiveThreshWinSizeStep(ArucoDetectorParameters ap, int adaptiveThreshWinSizeStep); +int ArucoDetectorParameters_GetAdaptiveThreshWinSizeStep(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetAdaptiveThreshConstant(ArucoDetectorParameters ap, double adaptiveThreshConstant); +double ArucoDetectorParameters_GetAdaptiveThreshConstant(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetMinMarkerPerimeterRate(ArucoDetectorParameters ap, double minMarkerPerimeterRate); +double ArucoDetectorParameters_GetMinMarkerPerimeterRate(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetMaxMarkerPerimeterRate(ArucoDetectorParameters ap, double maxMarkerPerimeterRate); +double ArucoDetectorParameters_GetMaxMarkerPerimeterRate(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetPolygonalApproxAccuracyRate(ArucoDetectorParameters ap, double polygonalApproxAccuracyRate); +double ArucoDetectorParameters_GetPolygonalApproxAccuracyRate(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetMinCornerDistanceRate(ArucoDetectorParameters ap, double minCornerDistanceRate); +double ArucoDetectorParameters_GetMinCornerDistanceRate(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetMinDistanceToBorder(ArucoDetectorParameters ap, int minDistanceToBorder); +int ArucoDetectorParameters_GetMinDistanceToBorder(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetMinMarkerDistanceRate(ArucoDetectorParameters ap, double minMarkerDistanceRate); +double ArucoDetectorParameters_GetMinMarkerDistanceRate(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetCornerRefinementMethod(ArucoDetectorParameters ap, int cornerRefinementMethod); +int ArucoDetectorParameters_GetCornerRefinementMethod(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetCornerRefinementWinSize(ArucoDetectorParameters ap, int cornerRefinementWinSize); +int ArucoDetectorParameters_GetCornerRefinementWinSize(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetCornerRefinementMaxIterations(ArucoDetectorParameters ap, int cornerRefinementMaxIterations); +int ArucoDetectorParameters_GetCornerRefinementMaxIterations(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetCornerRefinementMinAccuracy(ArucoDetectorParameters ap, double cornerRefinementMinAccuracy); +double ArucoDetectorParameters_GetCornerRefinementMinAccuracy(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetMarkerBorderBits(ArucoDetectorParameters ap, int markerBorderBits); +int ArucoDetectorParameters_GetMarkerBorderBits(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetPerspectiveRemovePixelPerCell(ArucoDetectorParameters ap, int perspectiveRemovePixelPerCell); +int ArucoDetectorParameters_GetPerspectiveRemovePixelPerCell(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetPerspectiveRemoveIgnoredMarginPerCell(ArucoDetectorParameters ap, double perspectiveRemoveIgnoredMarginPerCell); +double ArucoDetectorParameters_GetPerspectiveRemoveIgnoredMarginPerCell(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetMaxErroneousBitsInBorderRate(ArucoDetectorParameters ap, double maxErroneousBitsInBorderRate); +double ArucoDetectorParameters_GetMaxErroneousBitsInBorderRate(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetMinOtsuStdDev(ArucoDetectorParameters ap, double minOtsuStdDev); +double ArucoDetectorParameters_GetMinOtsuStdDev(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetErrorCorrectionRate(ArucoDetectorParameters ap, double errorCorrectionRate); +double ArucoDetectorParameters_GetErrorCorrectionRate(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetAprilTagQuadDecimate(ArucoDetectorParameters ap, float aprilTagQuadDecimate); +float ArucoDetectorParameters_GetAprilTagQuadDecimate(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetAprilTagQuadSigma(ArucoDetectorParameters ap, float aprilTagQuadSigma); +float ArucoDetectorParameters_GetAprilTagQuadSigma(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetAprilTagMinClusterPixels(ArucoDetectorParameters ap, int aprilTagMinClusterPixels); +int ArucoDetectorParameters_GetAprilTagMinClusterPixels(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetAprilTagMaxNmaxima(ArucoDetectorParameters ap, int aprilTagMaxNmaxima); +int ArucoDetectorParameters_GetAprilTagMaxNmaxima(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetAprilTagCriticalRad(ArucoDetectorParameters ap, float aprilTagCriticalRad); +float ArucoDetectorParameters_GetAprilTagCriticalRad(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetAprilTagMaxLineFitMse(ArucoDetectorParameters ap, float aprilTagMaxLineFitMse); +float ArucoDetectorParameters_GetAprilTagMaxLineFitMse(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetAprilTagMinWhiteBlackDiff(ArucoDetectorParameters ap, int aprilTagMinWhiteBlackDiff); +int ArucoDetectorParameters_GetAprilTagMinWhiteBlackDiff(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetAprilTagDeglitch(ArucoDetectorParameters ap, int aprilTagDeglitch); +int ArucoDetectorParameters_GetAprilTagDeglitch(ArucoDetectorParameters ap); +void ArucoDetectorParameters_SetDetectInvertedMarker(ArucoDetectorParameters ap, bool detectInvertedMarker); +bool ArucoDetectorParameters_GetDetectInvertedMarker(ArucoDetectorParameters ap); + + +ArucoDictionary getPredefinedDictionary(int dictionaryId); + +ArucoDetector ArucoDetector_New(); +ArucoDetector ArucoDetector_NewWithParams(ArucoDictionary dictionary, ArucoDetectorParameters params); +void ArucoDetector_Close(ArucoDetector ad); +void ArucoDetector_DetectMarkers(ArucoDetector ad, Mat inputArr, Points2fVector markerCorners, IntVector *markerIds, Points2fVector rejectedCandidates); + +void ArucoDrawDetectedMarkers(Mat image, Points2fVector markerCorners, IntVector markerIds, Scalar borderColor); +void ArucoGenerateImageMarker(int dictionaryId, int id, int sidePixels, Mat img, int borderBits); + +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_ARUCO_H_ diff --git a/vendor/gocv.io/x/gocv/aruco_dictionaries.go b/vendor/gocv.io/x/gocv/aruco_dictionaries.go new file mode 100644 index 00000000..fd4ee9e9 --- /dev/null +++ b/vendor/gocv.io/x/gocv/aruco_dictionaries.go @@ -0,0 +1,43 @@ +package gocv + +/* +#include +#include "aruco.h" +#include "core.h" +*/ +import "C" + +type ArucoDictionaryCode int + +const ( + ArucoDict4x4_50 ArucoDictionaryCode = iota + ArucoDict4x4_100 ArucoDictionaryCode = iota + ArucoDict4x4_250 ArucoDictionaryCode = iota + ArucoDict4x4_1000 ArucoDictionaryCode = iota + ArucoDict5x5_50 ArucoDictionaryCode = iota + ArucoDict5x5_100 ArucoDictionaryCode = iota + ArucoDict5x5_250 ArucoDictionaryCode = iota + ArucoDict5x5_1000 ArucoDictionaryCode = iota + ArucoDict6x6_50 ArucoDictionaryCode = iota + ArucoDict6x6_100 ArucoDictionaryCode = iota + ArucoDict6x6_250 ArucoDictionaryCode = iota + ArucoDict6x6_1000 ArucoDictionaryCode = iota + ArucoDict7x7_50 ArucoDictionaryCode = iota + ArucoDict7x7_100 ArucoDictionaryCode = iota + ArucoDict7x7_250 ArucoDictionaryCode = iota + ArucoDict7x7_1000 ArucoDictionaryCode = iota + ArucoDictArucoOriginal ArucoDictionaryCode = iota + ArucoDictAprilTag_16h5 ArucoDictionaryCode = iota ///< 4x4 bits, minimum hamming distance between any two codes = 5, 30 codes + ArucoDictAprilTag_25h9 ArucoDictionaryCode = iota ///< 5x5 bits, minimum hamming distance between any two codes = 9, 35 codes + ArucoDictAprilTag_36h10 ArucoDictionaryCode = iota ///< 6x6 bits, minimum hamming distance between any two codes = 10, 2320 codes + ArucoDictAprilTag_36h11 ArucoDictionaryCode = iota ///< 6x6 bits, minimum hamming distance between any two codes = 11, 587 codes +) + +type ArucoDictionary struct { + p C.ArucoDictionary +} + +func GetPredefinedDictionary(dictionaryId ArucoDictionaryCode) ArucoDictionary { + var p C.ArucoDictionary = C.getPredefinedDictionary(C.int(dictionaryId)) + return ArucoDictionary{p: p} +} diff --git a/vendor/gocv.io/x/gocv/asyncarray.cpp b/vendor/gocv.io/x/gocv/asyncarray.cpp new file mode 100644 index 00000000..b457ff89 --- /dev/null +++ b/vendor/gocv.io/x/gocv/asyncarray.cpp @@ -0,0 +1,28 @@ +// +build openvino + +#include +#include "asyncarray.h" + + +// AsyncArray_New creates a new empty AsyncArray +AsyncArray AsyncArray_New() { + return new cv::AsyncArray(); +} + +// AsyncArray_Close deletes an existing AsyncArray +void AsyncArray_Close(AsyncArray a) { + delete a; +} + +const char* AsyncArray_GetAsync(AsyncArray async_out,Mat out) { + try { + async_out->get(*out); + } catch(cv::Exception ex) { + return ex.err.c_str(); + } + return ""; +} + +AsyncArray Net_forwardAsync(Net net, const char* outputName) { + return new cv::AsyncArray(net->forwardAsync(outputName)); +} diff --git a/vendor/gocv.io/x/gocv/asyncarray.go b/vendor/gocv.io/x/gocv/asyncarray.go new file mode 100644 index 00000000..345ec5ef --- /dev/null +++ b/vendor/gocv.io/x/gocv/asyncarray.go @@ -0,0 +1,52 @@ +// +build openvino + +package gocv + +import ( + "errors" +) + +/* +#include +#include "dnn.h" +#include "asyncarray.h" +#include "core.h" +*/ +import "C" + +type AsyncArray struct { + p C.AsyncArray +} + +// NewAsyncArray returns a new empty AsyncArray. +func NewAsyncArray() AsyncArray { + return newAsyncArray(C.AsyncArray_New()) +} + +// Ptr returns the AsyncArray's underlying object pointer. +func (a *AsyncArray) Ptr() C.AsyncArray { + return a.p +} + +// Get async returns the Mat +func (m *AsyncArray) Get(mat *Mat) error { + result := C.AsyncArray_GetAsync(m.p, mat.p) + err := C.GoString(result) + + if len(err) > 0 { + return errors.New(err) + } + return nil +} + +// newAsyncArray returns a new AsyncArray from a C AsyncArray +func newAsyncArray(p C.AsyncArray) AsyncArray { + return AsyncArray{p: p} +} + +// Close the AsyncArray object. +func (a *AsyncArray) Close() error { + C.AsyncArray_Close(a.p) + a.p = nil + return nil +} diff --git a/vendor/gocv.io/x/gocv/asyncarray.h b/vendor/gocv.io/x/gocv/asyncarray.h new file mode 100644 index 00000000..cf894b6c --- /dev/null +++ b/vendor/gocv.io/x/gocv/asyncarray.h @@ -0,0 +1,23 @@ +#ifdef __cplusplus +#include +extern "C" { +#endif + +#include "core.h" +#include "dnn.h" + +#ifdef __cplusplus +typedef cv::AsyncArray* AsyncArray; +#else +typedef void* AsyncArray; +#endif + +AsyncArray AsyncArray_New(); +const char* AsyncArray_GetAsync(AsyncArray async_out,Mat out); +void AsyncArray_Close(AsyncArray a); +AsyncArray Net_forwardAsync(Net net, const char* outputName); + + +#ifdef __cplusplus +} +#endif diff --git a/vendor/gocv.io/x/gocv/calib3d.cpp b/vendor/gocv.io/x/gocv/calib3d.cpp new file mode 100644 index 00000000..8e3ce7de --- /dev/null +++ b/vendor/gocv.io/x/gocv/calib3d.cpp @@ -0,0 +1,86 @@ +#include "calib3d.h" + + +void Fisheye_UndistortImage(Mat distorted, Mat undistorted, Mat k, Mat d) { + cv::fisheye::undistortImage(*distorted, *undistorted, *k, *d); +} + +void Fisheye_UndistortImageWithParams(Mat distorted, Mat undistorted, Mat k, Mat d, Mat knew, Size size) { + cv::Size sz(size.width, size.height); + cv::fisheye::undistortImage(*distorted, *undistorted, *k, *d, *knew, sz); +} + +void Fisheye_UndistortPoints(Mat distorted, Mat undistorted, Mat k, Mat d, Mat r, Mat p) { + cv::fisheye::undistortPoints(*distorted, *undistorted, *k, *d, *r, *p); +} + +void Fisheye_EstimateNewCameraMatrixForUndistortRectify(Mat k, Mat d, Size imgSize, Mat r, Mat p, double balance, Size newSize, double fovScale) { + cv::Size newSz(newSize.width, newSize.height); + cv::Size imgSz(imgSize.width, imgSize.height); + cv::fisheye::estimateNewCameraMatrixForUndistortRectify(*k, *d, imgSz, *r, *p, balance, newSz, fovScale); +} + +void InitUndistortRectifyMap(Mat cameraMatrix,Mat distCoeffs,Mat r,Mat newCameraMatrix,Size size,int m1type,Mat map1,Mat map2) { + cv::Size sz(size.width, size.height); + cv::initUndistortRectifyMap(*cameraMatrix,*distCoeffs,*r,*newCameraMatrix,sz,m1type,*map1,*map2); +} + +Mat GetOptimalNewCameraMatrixWithParams(Mat cameraMatrix,Mat distCoeffs,Size size,double alpha,Size newImgSize,Rect* validPixROI,bool centerPrincipalPoint) { + cv::Size sz(size.width, size.height); + cv::Size newSize(newImgSize.width, newImgSize.height); + cv::Rect rect(validPixROI->x,validPixROI->y,validPixROI->width,validPixROI->height); + cv::Mat* mat = new cv::Mat(cv::getOptimalNewCameraMatrix(*cameraMatrix,*distCoeffs,sz,alpha,newSize,&rect,centerPrincipalPoint)); + validPixROI->x = rect.x; + validPixROI->y = rect.y; + validPixROI->width = rect.width; + validPixROI->height = rect.height; + return mat; +} + +double CalibrateCamera(Points3fVector objectPoints, Points2fVector imagePoints, Size imageSize, Mat cameraMatrix, Mat distCoeffs, Mat rvecs, Mat tvecs, int flag) { + return cv::calibrateCamera(*objectPoints, *imagePoints, cv::Size(imageSize.width, imageSize.height), *cameraMatrix, *distCoeffs, *rvecs, *tvecs, flag); +} + +void Undistort(Mat src, Mat dst, Mat cameraMatrix, Mat distCoeffs, Mat newCameraMatrix) { + cv::undistort(*src, *dst, *cameraMatrix, *distCoeffs, *newCameraMatrix); +} + +void UndistortPoints(Mat distorted, Mat undistorted, Mat k, Mat d, Mat r, Mat p) { + cv::undistortPoints(*distorted, *undistorted, *k, *d, *r, *p); +} + +bool FindChessboardCorners(Mat image, Size patternSize, Mat corners, int flags) { + cv::Size sz(patternSize.width, patternSize.height); + return cv::findChessboardCorners(*image, sz, *corners, flags); +} + +bool FindChessboardCornersSB(Mat image, Size patternSize, Mat corners, int flags) { + cv::Size sz(patternSize.width, patternSize.height); + return cv::findChessboardCornersSB(*image, sz, *corners, flags); +} + +bool FindChessboardCornersSBWithMeta(Mat image, Size patternSize, Mat corners, int flags, Mat meta) { + cv::Size sz(patternSize.width, patternSize.height); + return cv::findChessboardCornersSB(*image, sz, *corners, flags, *meta); +} + +void DrawChessboardCorners(Mat image, Size patternSize, Mat corners, bool patternWasFound) { + cv::Size sz(patternSize.width, patternSize.height); + cv::drawChessboardCorners(*image, sz, *corners, patternWasFound); +} + +Mat EstimateAffinePartial2D(Point2fVector from, Point2fVector to) { + return new cv::Mat(cv::estimateAffinePartial2D(*from, *to)); +} + +Mat EstimateAffinePartial2DWithParams(Point2fVector from, Point2fVector to, Mat inliers, int method, double ransacReprojThreshold, size_t maxIters, double confidence, size_t refineIters) { + return new cv::Mat(cv::estimateAffinePartial2D(*from, *to, *inliers, method, ransacReprojThreshold, maxIters, confidence, refineIters)); +} + +Mat EstimateAffine2D(Point2fVector from, Point2fVector to) { + return new cv::Mat(cv::estimateAffine2D(*from, *to)); +} + +Mat EstimateAffine2DWithParams(Point2fVector from, Point2fVector to, Mat inliers, int method, double ransacReprojThreshold, size_t maxIters, double confidence, size_t refineIters) { + return new cv::Mat(cv::estimateAffine2D(*from, *to, *inliers, method, ransacReprojThreshold, maxIters, confidence, refineIters)); +} diff --git a/vendor/gocv.io/x/gocv/calib3d.go b/vendor/gocv.io/x/gocv/calib3d.go new file mode 100644 index 00000000..409efd39 --- /dev/null +++ b/vendor/gocv.io/x/gocv/calib3d.go @@ -0,0 +1,266 @@ +package gocv + +/* +#include +#include "calib3d.h" +*/ +import "C" +import ( + "image" +) + +// Calib is a wrapper around OpenCV's "Camera Calibration and 3D Reconstruction" of +// Fisheye Camera model +// +// For more details, please see: +// https://docs.opencv.org/trunk/db/d58/group__calib3d__fisheye.html + +// CalibFlag value for calibration +type CalibFlag int32 + +const ( + // CalibUseIntrinsicGuess indicates that cameraMatrix contains valid initial values + // of fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially + // set to the image center ( imageSize is used), and focal distances are computed + // in a least-squares fashion. + CalibUseIntrinsicGuess CalibFlag = 1 << iota + + // CalibRecomputeExtrinsic indicates that extrinsic will be recomputed after each + // iteration of intrinsic optimization. + CalibRecomputeExtrinsic + + // CalibCheckCond indicates that the functions will check validity of condition number + CalibCheckCond + + // CalibFixSkew indicates that skew coefficient (alpha) is set to zero and stay zero + CalibFixSkew + + // CalibFixK1 indicates that selected distortion coefficients are set to zeros and stay zero + CalibFixK1 + + // CalibFixK2 indicates that selected distortion coefficients are set to zeros and stay zero + CalibFixK2 + + // CalibFixK3 indicates that selected distortion coefficients are set to zeros and stay zero + CalibFixK3 + + // CalibFixK4 indicates that selected distortion coefficients are set to zeros and stay zero + CalibFixK4 + + // CalibFixIntrinsic indicates that fix K1, K2? and D1, D2? so that only R, T matrices are estimated + CalibFixIntrinsic + + // CalibFixPrincipalPoint indicates that the principal point is not changed during the global optimization. + // It stays at the center or at a different location specified when CalibUseIntrinsicGuess is set too. + CalibFixPrincipalPoint +) + +// FisheyeUndistortImage transforms an image to compensate for fisheye lens distortion +func FisheyeUndistortImage(distorted Mat, undistorted *Mat, k, d Mat) { + C.Fisheye_UndistortImage(distorted.Ptr(), undistorted.Ptr(), k.Ptr(), d.Ptr()) +} + +// FisheyeUndistortImageWithParams transforms an image to compensate for fisheye lens distortion with Knew matrix +func FisheyeUndistortImageWithParams(distorted Mat, undistorted *Mat, k, d, knew Mat, size image.Point) { + sz := C.struct_Size{ + width: C.int(size.X), + height: C.int(size.Y), + } + C.Fisheye_UndistortImageWithParams(distorted.Ptr(), undistorted.Ptr(), k.Ptr(), d.Ptr(), knew.Ptr(), sz) +} + +// FisheyeUndistortPoints transforms points to compensate for fisheye lens distortion +// +// For further details, please see: +// https://docs.opencv.org/master/db/d58/group__calib3d__fisheye.html#gab738cdf90ceee97b2b52b0d0e7511541 +func FisheyeUndistortPoints(distorted Mat, undistorted *Mat, k, d, r, p Mat) { + C.Fisheye_UndistortPoints(distorted.Ptr(), undistorted.Ptr(), k.Ptr(), d.Ptr(), r.Ptr(), p.Ptr()) +} + +// EstimateNewCameraMatrixForUndistortRectify estimates new camera matrix for undistortion or rectification. +// +// For further details, please see: +// https://docs.opencv.org/master/db/d58/group__calib3d__fisheye.html#ga384940fdf04c03e362e94b6eb9b673c9 +func EstimateNewCameraMatrixForUndistortRectify(k, d Mat, imgSize image.Point, r Mat, p *Mat, balance float64, newSize image.Point, fovScale float64) { + imgSz := C.struct_Size{ + width: C.int(imgSize.X), + height: C.int(imgSize.Y), + } + newSz := C.struct_Size{ + width: C.int(newSize.X), + height: C.int(newSize.Y), + } + C.Fisheye_EstimateNewCameraMatrixForUndistortRectify(k.Ptr(), d.Ptr(), imgSz, r.Ptr(), p.Ptr(), C.double(balance), newSz, C.double(fovScale)) +} + +// InitUndistortRectifyMap computes the joint undistortion and rectification transformation and represents the result in the form of maps for remap +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#ga7dfb72c9cf9780a347fbe3d1c47e5d5a +// +func InitUndistortRectifyMap(cameraMatrix Mat, distCoeffs Mat, r Mat, newCameraMatrix Mat, size image.Point, m1type int, map1 Mat, map2 Mat) { + sz := C.struct_Size{ + width: C.int(size.X), + height: C.int(size.Y), + } + C.InitUndistortRectifyMap(cameraMatrix.Ptr(), distCoeffs.Ptr(), r.Ptr(), newCameraMatrix.Ptr(), sz, C.int(m1type), map1.Ptr(), map2.Ptr()) +} + +// GetOptimalNewCameraMatrixWithParams computes and returns the optimal new camera matrix based on the free scaling parameter. +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#ga7a6c4e032c97f03ba747966e6ad862b1 +// +func GetOptimalNewCameraMatrixWithParams(cameraMatrix Mat, distCoeffs Mat, imageSize image.Point, alpha float64, newImgSize image.Point, centerPrincipalPoint bool) (Mat, image.Rectangle) { + sz := C.struct_Size{ + width: C.int(imageSize.X), + height: C.int(imageSize.Y), + } + newSize := C.struct_Size{ + width: C.int(newImgSize.X), + height: C.int(newImgSize.Y), + } + rt := C.struct_Rect{} + return newMat(C.GetOptimalNewCameraMatrixWithParams(cameraMatrix.Ptr(), distCoeffs.Ptr(), sz, C.double(alpha), newSize, &rt, C.bool(centerPrincipalPoint))), toRect(rt) +} + +// CalibrateCamera finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern. +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#ga3207604e4b1a1758aa66acb6ed5aa65d +// +func CalibrateCamera(objectPoints Points3fVector, imagePoints Points2fVector, imageSize image.Point, + cameraMatrix *Mat, distCoeffs *Mat, rvecs *Mat, tvecs *Mat, calibFlag CalibFlag) float64 { + sz := C.struct_Size{ + width: C.int(imageSize.X), + height: C.int(imageSize.Y), + } + + res := C.CalibrateCamera(objectPoints.p, imagePoints.p, sz, cameraMatrix.p, distCoeffs.p, rvecs.p, tvecs.p, C.int(calibFlag)) + return float64(res) +} + +func Undistort(src Mat, dst *Mat, cameraMatrix Mat, distCoeffs Mat, newCameraMatrix Mat) { + C.Undistort(src.Ptr(), dst.Ptr(), cameraMatrix.Ptr(), distCoeffs.Ptr(), newCameraMatrix.Ptr()) +} + +// UndistortPoints transforms points to compensate for lens distortion +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#ga55c716492470bfe86b0ee9bf3a1f0f7e +func UndistortPoints(src Mat, dst *Mat, cameraMatrix, distCoeffs, rectificationTransform, newCameraMatrix Mat) { + C.UndistortPoints(src.Ptr(), dst.Ptr(), cameraMatrix.Ptr(), distCoeffs.Ptr(), rectificationTransform.Ptr(), newCameraMatrix.Ptr()) +} + +// CalibCBFlag value for chessboard calibration +// For more details, please see: +// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#ga93efa9b0aa890de240ca32b11253dd4a +type CalibCBFlag int + +const ( + // Various operation flags that can be zero or a combination of the following values: + // Use adaptive thresholding to convert the image to black and white, rather than a fixed threshold level (computed from the average image brightness). + CalibCBAdaptiveThresh CalibCBFlag = 1 << iota + // Normalize the image gamma with equalizeHist before applying fixed or adaptive thresholding. + CalibCBNormalizeImage + // Use additional criteria (like contour area, perimeter, square-like shape) to filter out false quads extracted at the contour retrieval stage. + CalibCBFilterQuads + // Run a fast check on the image that looks for chessboard corners, and shortcut the call if none is found. This can drastically speed up the call in the degenerate condition when no chessboard is observed. + CalibCBFastCheck + // Run an exhaustive search to improve detection rate. + CalibCBExhaustive + // Up sample input image to improve sub-pixel accuracy due to aliasing effects. + CalibCBAccuracy + // The detected pattern is allowed to be larger than patternSize (see description). + CalibCBLarger + // The detected pattern must have a marker (see description). This should be used if an accurate camera calibration is required. + CalibCBMarker +) + +// FindChessboardCorners finds the positions of internal corners of the chessboard. +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#ga93efa9b0aa890de240ca32b11253dd4a +// +func FindChessboardCorners(image Mat, patternSize image.Point, corners *Mat, flags CalibCBFlag) bool { + sz := C.struct_Size{ + width: C.int(patternSize.X), + height: C.int(patternSize.Y), + } + return bool(C.FindChessboardCorners(image.Ptr(), sz, corners.Ptr(), C.int(flags))) +} + +// FindChessboardCorners finds the positions of internal corners of the chessboard using a sector based approach. +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#gadc5bcb05cb21cf1e50963df26986d7c9 +// +func FindChessboardCornersSB(image Mat, patternSize image.Point, corners *Mat, flags CalibCBFlag) bool { + sz := C.struct_Size{ + width: C.int(patternSize.X), + height: C.int(patternSize.Y), + } + return bool(C.FindChessboardCornersSB(image.Ptr(), sz, corners.Ptr(), C.int(flags))) +} + +// FindChessboardCornersSBWithMeta finds the positions of internal corners of the chessboard using a sector based approach. +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#ga93efa9b0aa890de240ca32b11253dd4a +// +func FindChessboardCornersSBWithMeta(image Mat, patternSize image.Point, corners *Mat, flags CalibCBFlag, meta *Mat) bool { + sz := C.struct_Size{ + width: C.int(patternSize.X), + height: C.int(patternSize.Y), + } + return bool(C.FindChessboardCornersSBWithMeta(image.Ptr(), sz, corners.Ptr(), C.int(flags), meta.Ptr())) +} + +// DrawChessboardCorners renders the detected chessboard corners. +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#ga6a10b0bb120c4907e5eabbcd22319022 +// +func DrawChessboardCorners(image *Mat, patternSize image.Point, corners Mat, patternWasFound bool) { + sz := C.struct_Size{ + width: C.int(patternSize.X), + height: C.int(patternSize.Y), + } + C.DrawChessboardCorners(image.Ptr(), sz, corners.Ptr(), C.bool(patternWasFound)) +} + +// EstimateAffinePartial2D computes an optimal limited affine transformation +// with 4 degrees of freedom between two 2D point sets. +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#gad767faff73e9cbd8b9d92b955b50062d +func EstimateAffinePartial2D(from, to Point2fVector) Mat { + return newMat(C.EstimateAffinePartial2D(from.p, to.p)) +} + +// EstimateAffinePartial2DWithParams computes an optimal limited affine transformation +// with 4 degrees of freedom between two 2D point sets +// with additional optional parameters. +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#gad767faff73e9cbd8b9d92b955b50062d +func EstimateAffinePartial2DWithParams(from Point2fVector, to Point2fVector, inliers Mat, method int, ransacReprojThreshold float64, maxIters uint, confidence float64, refineIters uint) Mat { + return newMat(C.EstimateAffinePartial2DWithParams(from.p, to.p, inliers.p, C.int(method), C.double(ransacReprojThreshold), C.size_t(maxIters), C.double(confidence), C.size_t(refineIters))) +} + +// EstimateAffine2D Computes an optimal affine transformation between two 2D point sets. +// +// For further details, please see: +// https://docs.opencv.org/4.0.0/d9/d0c/group__calib3d.html#ga27865b1d26bac9ce91efaee83e94d4dd +func EstimateAffine2D(from, to Point2fVector) Mat { + return newMat(C.EstimateAffine2D(from.p, to.p)) +} + +// EstimateAffine2DWithParams Computes an optimal affine transformation between two 2D point sets +// with additional optional parameters. +// +// For further details, please see: +// https://docs.opencv.org/4.0.0/d9/d0c/group__calib3d.html#ga27865b1d26bac9ce91efaee83e94d4dd +func EstimateAffine2DWithParams(from Point2fVector, to Point2fVector, inliers Mat, method int, ransacReprojThreshold float64, maxIters uint, confidence float64, refineIters uint) Mat { + return newMat(C.EstimateAffine2DWithParams(from.p, to.p, inliers.p, C.int(method), C.double(ransacReprojThreshold), C.size_t(maxIters), C.double(confidence), C.size_t(refineIters))) +} diff --git a/vendor/gocv.io/x/gocv/calib3d.h b/vendor/gocv.io/x/gocv/calib3d.h new file mode 100644 index 00000000..9f2fed87 --- /dev/null +++ b/vendor/gocv.io/x/gocv/calib3d.h @@ -0,0 +1,37 @@ +#ifndef _OPENCV3_CALIB_H_ +#define _OPENCV3_CALIB_H_ + +#ifdef __cplusplus +#include +#include + + +extern "C" { +#endif + +#include "core.h" + +//Calib +void Fisheye_UndistortImage(Mat distorted, Mat undistorted, Mat k, Mat d); +void Fisheye_UndistortImageWithParams(Mat distorted, Mat undistorted, Mat k, Mat d, Mat knew, Size size); +void Fisheye_UndistortPoints(Mat distorted, Mat undistorted, Mat k, Mat d, Mat R, Mat P); +void Fisheye_EstimateNewCameraMatrixForUndistortRectify(Mat k, Mat d, Size imgSize, Mat r, Mat p, double balance, Size newSize, double fovScale); + +void InitUndistortRectifyMap(Mat cameraMatrix,Mat distCoeffs,Mat r,Mat newCameraMatrix,Size size,int m1type,Mat map1,Mat map2); +Mat GetOptimalNewCameraMatrixWithParams(Mat cameraMatrix,Mat distCoeffs,Size size,double alpha,Size newImgSize,Rect* validPixROI,bool centerPrincipalPoint); +double CalibrateCamera(Points3fVector objectPoints, Points2fVector imagePoints, Size imageSize, Mat cameraMatrix, Mat distCoeffs, Mat rvecs, Mat tvecs, int flag); +void Undistort(Mat src, Mat dst, Mat cameraMatrix, Mat distCoeffs, Mat newCameraMatrix); +void UndistortPoints(Mat distorted, Mat undistorted, Mat k, Mat d, Mat r, Mat p); +bool FindChessboardCorners(Mat image, Size patternSize, Mat corners, int flags); +bool FindChessboardCornersSB(Mat image, Size patternSize, Mat corners, int flags); +bool FindChessboardCornersSBWithMeta(Mat image, Size patternSize, Mat corners, int flags, Mat meta); +void DrawChessboardCorners(Mat image, Size patternSize, Mat corners, bool patternWasFound); +Mat EstimateAffinePartial2D(Point2fVector from, Point2fVector to); +Mat EstimateAffinePartial2DWithParams(Point2fVector from, Point2fVector to, Mat inliers, int method, double ransacReprojThreshold, size_t maxIters, double confidence, size_t refineIters); +Mat EstimateAffine2D(Point2fVector from, Point2fVector to); +Mat EstimateAffine2DWithParams(Point2fVector from, Point2fVector to, Mat inliers, int method, double ransacReprojThreshold, size_t maxIters, double confidence, size_t refineIters); +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_CALIB_H diff --git a/vendor/gocv.io/x/gocv/calib3d_string.go b/vendor/gocv.io/x/gocv/calib3d_string.go new file mode 100644 index 00000000..2cd6b9ff --- /dev/null +++ b/vendor/gocv.io/x/gocv/calib3d_string.go @@ -0,0 +1,49 @@ +package gocv + +func (c CalibFlag) String() string { + switch c { + case CalibUseIntrinsicGuess: + return "calib-use-intrinsec-guess" + case CalibRecomputeExtrinsic: + return "calib-recompute-extrinsic" + case CalibCheckCond: + return "calib-check-cond" + case CalibFixSkew: + return "calib-fix-skew" + case CalibFixK1: + return "calib-fix-k1" + case CalibFixK2: + return "calib-fix-k2" + case CalibFixK3: + return "calib-fix-k3" + case CalibFixK4: + return "calib-fix-k4" + case CalibFixIntrinsic: + return "calib-fix-intrinsic" + case CalibFixPrincipalPoint: + return "calib-fix-principal-point" + } + return "" +} + +func (c CalibCBFlag) String() string { + switch c { + case CalibCBAdaptiveThresh: + return "calib-cb-adaptive-thresh" + case CalibCBNormalizeImage: + return "calib-cb-normalize-image" + case CalibCBFilterQuads: + return "calib-cb-filter-quads" + case CalibCBFastCheck: + return "calib-cb-fast-check" + case CalibCBExhaustive: + return "calib-cb-exhaustive" + case CalibCBAccuracy: + return "calib-cb-accuracy" + case CalibCBLarger: + return "calib-cb-larger" + case CalibCBMarker: + return "calib-cb-marker" + } + return "" +} diff --git a/vendor/gocv.io/x/gocv/cgo.go b/vendor/gocv.io/x/gocv/cgo.go new file mode 100644 index 00000000..1db4b6a2 --- /dev/null +++ b/vendor/gocv.io/x/gocv/cgo.go @@ -0,0 +1,14 @@ +//go:build !customenv && !static +// +build !customenv,!static + +package gocv + +// Changes here should be mirrored in contrib/cgo.go and cuda/cgo.go. + +/* +#cgo !windows pkg-config: opencv4 +#cgo CXXFLAGS: --std=c++11 +#cgo windows CPPFLAGS: -IC:/opencv/build/install/include +#cgo windows LDFLAGS: -LC:/opencv/build/install/x64/mingw/lib -lopencv_core470 -lopencv_face470 -lopencv_videoio470 -lopencv_imgproc470 -lopencv_highgui470 -lopencv_imgcodecs470 -lopencv_objdetect470 -lopencv_features2d470 -lopencv_video470 -lopencv_dnn470 -lopencv_xfeatures2d470 -lopencv_plot470 -lopencv_tracking470 -lopencv_img_hash470 -lopencv_calib3d470 -lopencv_bgsegm470 -lopencv_photo470 -lopencv_aruco470 -lopencv_wechat_qrcode470 -lopencv_ximgproc470 +*/ +import "C" diff --git a/vendor/gocv.io/x/gocv/cgo_static.go b/vendor/gocv.io/x/gocv/cgo_static.go new file mode 100644 index 00000000..634a87a1 --- /dev/null +++ b/vendor/gocv.io/x/gocv/cgo_static.go @@ -0,0 +1,15 @@ +//go:build !customenv && static +// +build !customenv,static + +package gocv + +// Changes here should be mirrored in contrib/cgo_static.go and cuda/cgo_static.go. + +/* +#cgo CXXFLAGS: --std=c++11 +#cgo !windows CPPFLAGS: -I/usr/local/include -I/usr/local/include/opencv4 +#cgo !windows LDFLAGS: -L/usr/local/lib -L/usr/local/lib/opencv4/3rdparty -lopencv_gapi -lopencv_stitching -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dpm -lopencv_face -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_quality -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_highgui -lopencv_dnn -lopencv_plot -lopencv_videostab -lopencv_video -lopencv_videoio -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_wechat_qrcode -lopencv_photo -lopencv_imgproc -lopencv_core -littnotify -llibprotobuf -lIlmImf -lquirc -lippiw -lippicv -lade -lz -ljpeg -ldl -lm -lpthread -lrt -lquadmath +#cgo windows CPPFLAGS: -IC:/opencv/build/install/include +#cgo windows LDFLAGS: -LC:/opencv/build/install/x64/mingw/staticlib -lopencv_stereo470 -lopencv_tracking470 -lopencv_superres470 -lopencv_stitching470 -lopencv_optflow470 -lopencv_gapi470 -lopencv_face470 -lopencv_dpm470 -lopencv_dnn_objdetect470 -lopencv_ccalib470 -lopencv_bioinspired470 -lopencv_bgsegm470 -lopencv_aruco470 -lopencv_xobjdetect470 -lopencv_ximgproc470 -lopencv_xfeatures2d470 -lopencv_videostab470 -lopencv_video470 -lopencv_structured_light470 -lopencv_shape470 -lopencv_rgbd470 -lopencv_rapid470 -lopencv_objdetect470 -lopencv_mcc470 -lopencv_highgui470 -lopencv_datasets470 -lopencv_calib3d470 -lopencv_videoio470 -lopencv_text470 -lopencv_line_descriptor470 -lopencv_imgcodecs470 -lopencv_img_hash470 -lopencv_hfs470 -lopencv_fuzzy470 -lopencv_features2d470 -lopencv_dnn_superres470 -lopencv_dnn470 -lopencv_xphoto470 -lopencv_wechat_qrcode470 -lopencv_surface_matching470 -lopencv_reg470 -lopencv_quality470 -lopencv_plot470 -lopencv_photo470 -lopencv_phase_unwrapping470 -lopencv_ml470 -lopencv_intensity_transform470 -lopencv_imgproc470 -lopencv_flann470 -lopencv_core470 -lade -lquirc -llibprotobuf -lIlmImf -llibpng -llibopenjp2 -llibwebp -llibtiff -llibjpeg-turbo -lzlib -lkernel32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -luser32 +*/ +import "C" diff --git a/vendor/gocv.io/x/gocv/codecov.yml b/vendor/gocv.io/x/gocv/codecov.yml new file mode 100644 index 00000000..f6086209 --- /dev/null +++ b/vendor/gocv.io/x/gocv/codecov.yml @@ -0,0 +1,3 @@ +ignore: + - "*_string.go" + - "*/*_string.go" diff --git a/vendor/gocv.io/x/gocv/core.cpp b/vendor/gocv.io/x/gocv/core.cpp new file mode 100644 index 00000000..97d0f8f2 --- /dev/null +++ b/vendor/gocv.io/x/gocv/core.cpp @@ -0,0 +1,1163 @@ +#include "core.h" +#include + +// Mat_New creates a new empty Mat +Mat Mat_New() { + return new cv::Mat(); +} + +// Mat_NewWithSize creates a new Mat with a specific size dimension and number of channels. +Mat Mat_NewWithSize(int rows, int cols, int type) { + return new cv::Mat(rows, cols, type, 0.0); +} + +// Mat_NewWithSizes creates a new Mat with specific dimension sizes and number of channels. +Mat Mat_NewWithSizes(struct IntVector sizes, int type) { + std::vector sizess; + for (int i = 0; i < sizes.length; ++i) { + sizess.push_back(sizes.val[i]); + } + return new cv::Mat(sizess, type); +} + +// Mat_NewFromScalar creates a new Mat from a Scalar. Intended to be used +// for Mat comparison operation such as InRange. +Mat Mat_NewFromScalar(Scalar ar, int type) { + cv::Scalar c = cv::Scalar(ar.val1, ar.val2, ar.val3, ar.val4); + return new cv::Mat(1, 1, type, c); +} + +// Mat_NewWithSizeFromScalar creates a new Mat from a Scalar with a specific size dimension and number of channels +Mat Mat_NewWithSizeFromScalar(Scalar ar, int rows, int cols, int type) { + cv::Scalar c = cv::Scalar(ar.val1, ar.val2, ar.val3, ar.val4); + return new cv::Mat(rows, cols, type, c); +} + +Mat Mat_NewFromBytes(int rows, int cols, int type, struct ByteArray buf) { + return new cv::Mat(rows, cols, type, buf.data); +} + +// Mat_NewWithSizesFromScalar creates multidimensional Mat from a scalar +Mat Mat_NewWithSizesFromScalar(IntVector sizes, int type, Scalar ar) { + std::vector _sizes; + for (int i = 0, *v = sizes.val; i < sizes.length; ++v, ++i) { + _sizes.push_back(*v); + } + + cv::Scalar c = cv::Scalar(ar.val1, ar.val2, ar.val3, ar.val4); + return new cv::Mat(_sizes, type, c); +} + +// Mat_NewWithSizesFromBytes creates multidimensional Mat from a bytes +Mat Mat_NewWithSizesFromBytes(IntVector sizes, int type, struct ByteArray buf) { + std::vector _sizes; + for (int i = 0, *v = sizes.val; i < sizes.length; ++v, ++i) { + _sizes.push_back(*v); + } + + return new cv::Mat(_sizes, type, buf.data); +} + +Mat Eye(int rows, int cols, int type) { + cv::Mat* mat = new cv::Mat(rows, cols, type); + *mat = cv::Mat::eye(rows, cols, type); + return mat; +} + +Mat Zeros(int rows, int cols, int type) { + cv::Mat* mat = new cv::Mat(rows, cols, type); + *mat = cv::Mat::zeros(rows, cols, type); + return mat; +} + +Mat Ones(int rows, int cols, int type) { + cv::Mat* mat = new cv::Mat(rows, cols, type); + *mat = cv::Mat::ones(rows, cols, type); + return mat; +} + +Mat Mat_FromPtr(Mat m, int rows, int cols, int type, int prow, int pcol) { + return new cv::Mat(rows, cols, type, m->ptr(prow, pcol)); +} + +// Mat_Close deletes an existing Mat +void Mat_Close(Mat m) { + delete m; +} + +// Mat_Empty tests if a Mat is empty +int Mat_Empty(Mat m) { + return m->empty(); +} + +// Mat_IsContinuous tests if a Mat is continuous +bool Mat_IsContinuous(Mat m) { + return m->isContinuous(); +} + +// Mat_Clone returns a clone of this Mat +Mat Mat_Clone(Mat m) { + return new cv::Mat(m->clone()); +} + +// Mat_CopyTo copies this Mat to another Mat. +void Mat_CopyTo(Mat m, Mat dst) { + m->copyTo(*dst); +} + +// Mat_CopyToWithMask copies this Mat to another Mat while applying the mask +void Mat_CopyToWithMask(Mat m, Mat dst, Mat mask) { + m->copyTo(*dst, *mask); +} + +void Mat_ConvertTo(Mat m, Mat dst, int type) { + m->convertTo(*dst, type); +} + +void Mat_ConvertToWithParams(Mat m, Mat dst, int type, float alpha, float beta) { + m->convertTo(*dst, type, alpha, beta); +} + +// Mat_ToBytes returns the bytes representation of the underlying data. +struct ByteArray Mat_ToBytes(Mat m) { + return toByteArray(reinterpret_cast(m->data), m->total() * m->elemSize()); +} + +struct ByteArray Mat_DataPtr(Mat m) { + return ByteArray {reinterpret_cast(m->data), static_cast(m->total() * m->elemSize())}; +} + +// Mat_Region returns a Mat of a region of another Mat +Mat Mat_Region(Mat m, Rect r) { + return new cv::Mat(*m, cv::Rect(r.x, r.y, r.width, r.height)); +} + +Mat Mat_Reshape(Mat m, int cn, int rows) { + return new cv::Mat(m->reshape(cn, rows)); +} + +void Mat_PatchNaNs(Mat m) { + cv::patchNaNs(*m); +} + +Mat Mat_ConvertFp16(Mat m) { + Mat dst = new cv::Mat(); + cv::convertFp16(*m, *dst); + return dst; +} + +Mat Mat_Sqrt(Mat m) { + Mat dst = new cv::Mat(); + cv::sqrt(*m, *dst); + return dst; +} + +// Mat_Mean calculates the mean value M of array elements, independently for each channel, and return it as Scalar vector +Scalar Mat_Mean(Mat m) { + cv::Scalar c = cv::mean(*m); + Scalar scal = Scalar(); + scal.val1 = c.val[0]; + scal.val2 = c.val[1]; + scal.val3 = c.val[2]; + scal.val4 = c.val[3]; + return scal; +} + +// Mat_MeanWithMask calculates the mean value M of array elements, +// independently for each channel, and returns it as Scalar vector +// while applying the mask. + +Scalar Mat_MeanWithMask(Mat m, Mat mask){ + cv::Scalar c = cv::mean(*m, *mask); + Scalar scal = Scalar(); + scal.val1 = c.val[0]; + scal.val2 = c.val[1]; + scal.val3 = c.val[2]; + scal.val4 = c.val[3]; + return scal; +} + +void LUT(Mat src, Mat lut, Mat dst) { + cv::LUT(*src, *lut, *dst); +} + +// Mat_Rows returns how many rows in this Mat. +int Mat_Rows(Mat m) { + return m->rows; +} + +// Mat_Cols returns how many columns in this Mat. +int Mat_Cols(Mat m) { + return m->cols; +} + +// Mat_Channels returns how many channels in this Mat. +int Mat_Channels(Mat m) { + return m->channels(); +} + +// Mat_Type returns the type from this Mat. +int Mat_Type(Mat m) { + return m->type(); +} + +// Mat_Step returns the number of bytes each matrix row occupies. +int Mat_Step(Mat m) { + return m->step; +} + +int Mat_Total(Mat m) { + return m->total(); +} + +int Mat_ElemSize(Mat m){ + return m->elemSize(); +} + +void Mat_Size(Mat m, IntVector* res) { + cv::MatSize ms(m->size); + int* ids = new int[ms.dims()]; + + for (size_t i = 0; i < ms.dims(); ++i) { + ids[i] = ms[i]; + } + + res->length = ms.dims(); + res->val = ids; + return; +} + +// Mat_GetUChar returns a specific row/col value from this Mat expecting +// each element to contain a schar aka CV_8U. +uint8_t Mat_GetUChar(Mat m, int row, int col) { + return m->at(row, col); +} + +uint8_t Mat_GetUChar3(Mat m, int x, int y, int z) { + return m->at(x, y, z); +} + +// Mat_GetSChar returns a specific row/col value from this Mat expecting +// each element to contain a schar aka CV_8S. +int8_t Mat_GetSChar(Mat m, int row, int col) { + return m->at(row, col); +} + +int8_t Mat_GetSChar3(Mat m, int x, int y, int z) { + return m->at(x, y, z); +} + +// Mat_GetShort returns a specific row/col value from this Mat expecting +// each element to contain a short aka CV_16S. +int16_t Mat_GetShort(Mat m, int row, int col) { + return m->at(row, col); +} + +int16_t Mat_GetShort3(Mat m, int x, int y, int z) { + return m->at(x, y, z); +} + +// Mat_GetInt returns a specific row/col value from this Mat expecting +// each element to contain an int aka CV_32S. +int32_t Mat_GetInt(Mat m, int row, int col) { + return m->at(row, col); +} + +int32_t Mat_GetInt3(Mat m, int x, int y, int z) { + return m->at(x, y, z); +} + +// Mat_GetFloat returns a specific row/col value from this Mat expecting +// each element to contain a float aka CV_32F. +float Mat_GetFloat(Mat m, int row, int col) { + return m->at(row, col); +} + +float Mat_GetFloat3(Mat m, int x, int y, int z) { + return m->at(x, y, z); +} + +// Mat_GetDouble returns a specific row/col value from this Mat expecting +// each element to contain a double aka CV_64F. +double Mat_GetDouble(Mat m, int row, int col) { + return m->at(row, col); +} + +double Mat_GetDouble3(Mat m, int x, int y, int z) { + return m->at(x, y, z); +} + +void Mat_SetTo(Mat m, Scalar value) { + cv::Scalar c_value(value.val1, value.val2, value.val3, value.val4); + m->setTo(c_value); +} + +// Mat_SetUChar set a specific row/col value from this Mat expecting +// each element to contain a schar aka CV_8U. +void Mat_SetUChar(Mat m, int row, int col, uint8_t val) { + m->at(row, col) = val; +} + +void Mat_SetUChar3(Mat m, int x, int y, int z, uint8_t val) { + m->at(x, y, z) = val; +} + +// Mat_SetSChar set a specific row/col value from this Mat expecting +// each element to contain a schar aka CV_8S. +void Mat_SetSChar(Mat m, int row, int col, int8_t val) { + m->at(row, col) = val; +} + +void Mat_SetSChar3(Mat m, int x, int y, int z, int8_t val) { + m->at(x, y, z) = val; +} + +// Mat_SetShort set a specific row/col value from this Mat expecting +// each element to contain a short aka CV_16S. +void Mat_SetShort(Mat m, int row, int col, int16_t val) { + m->at(row, col) = val; +} + +void Mat_SetShort3(Mat m, int x, int y, int z, int16_t val) { + m->at(x, y, z) = val; +} + +// Mat_SetInt set a specific row/col value from this Mat expecting +// each element to contain an int aka CV_32S. +void Mat_SetInt(Mat m, int row, int col, int32_t val) { + m->at(row, col) = val; +} + +void Mat_SetInt3(Mat m, int x, int y, int z, int32_t val) { + m->at(x, y, z) = val; +} + +// Mat_SetFloat set a specific row/col value from this Mat expecting +// each element to contain a float aka CV_32F. +void Mat_SetFloat(Mat m, int row, int col, float val) { + m->at(row, col) = val; +} + +void Mat_SetFloat3(Mat m, int x, int y, int z, float val) { + m->at(x, y, z) = val; +} + +// Mat_SetDouble set a specific row/col value from this Mat expecting +// each element to contain a double aka CV_64F. +void Mat_SetDouble(Mat m, int row, int col, double val) { + m->at(row, col) = val; +} + +void Mat_SetDouble3(Mat m, int x, int y, int z, double val) { + m->at(x, y, z) = val; +} + +void Mat_AddUChar(Mat m, uint8_t val) { + *m += val; +} + +void Mat_SubtractUChar(Mat m, uint8_t val) { + *m -= val; +} + +void Mat_MultiplyUChar(Mat m, uint8_t val) { + *m *= val; +} + +void Mat_DivideUChar(Mat m, uint8_t val) { + *m /= val; +} + +void Mat_AddFloat(Mat m, float val) { + *m += val; +} + +void Mat_SubtractFloat(Mat m, float val) { + *m -= val; +} + +void Mat_MultiplyFloat(Mat m, float val) { + *m *= val; +} + +void Mat_DivideFloat(Mat m, float val) { + *m /= val; +} + +Mat Mat_MultiplyMatrix(Mat x, Mat y) { + return new cv::Mat((*x) * (*y)); +} + +Mat Mat_T(Mat x) { + return new cv::Mat(x->t()); +} + +void Mat_AbsDiff(Mat src1, Mat src2, Mat dst) { + cv::absdiff(*src1, *src2, *dst); +} + +void Mat_Add(Mat src1, Mat src2, Mat dst) { + cv::add(*src1, *src2, *dst); +} + +void Mat_AddWeighted(Mat src1, double alpha, Mat src2, double beta, double gamma, Mat dst) { + cv::addWeighted(*src1, alpha, *src2, beta, gamma, *dst); +} + +void Mat_BitwiseAnd(Mat src1, Mat src2, Mat dst) { + cv::bitwise_and(*src1, *src2, *dst); +} + +void Mat_BitwiseAndWithMask(Mat src1, Mat src2, Mat dst, Mat mask){ + cv::bitwise_and(*src1, *src2, *dst, *mask); +} + +void Mat_BitwiseNot(Mat src1, Mat dst) { + cv::bitwise_not(*src1, *dst); +} + +void Mat_BitwiseNotWithMask(Mat src1, Mat dst, Mat mask) { + cv::bitwise_not(*src1, *dst, *mask); +} + +void Mat_BitwiseOr(Mat src1, Mat src2, Mat dst) { + cv::bitwise_or(*src1, *src2, *dst); +} + +void Mat_BitwiseOrWithMask(Mat src1, Mat src2, Mat dst, Mat mask) { + cv::bitwise_or(*src1, *src2, *dst, *mask); +} + +void Mat_BitwiseXor(Mat src1, Mat src2, Mat dst) { + cv::bitwise_xor(*src1, *src2, *dst); +} + +void Mat_BitwiseXorWithMask(Mat src1, Mat src2, Mat dst, Mat mask) { + cv::bitwise_xor(*src1, *src2, *dst, *mask); +} + +void Mat_BatchDistance(Mat src1, Mat src2, Mat dist, int dtype, Mat nidx, int normType, int K, + Mat mask, int update, bool crosscheck) { + cv::batchDistance(*src1, *src2, *dist, dtype, *nidx, normType, K, *mask, update, crosscheck); +} + +int Mat_BorderInterpolate(int p, int len, int borderType) { + return cv::borderInterpolate(p, len, borderType); +} + +void Mat_CalcCovarMatrix(Mat samples, Mat covar, Mat mean, int flags, int ctype) { + cv::calcCovarMatrix(*samples, *covar, *mean, flags, ctype); +} + +void Mat_CartToPolar(Mat x, Mat y, Mat magnitude, Mat angle, bool angleInDegrees) { + cv::cartToPolar(*x, *y, *magnitude, *angle, angleInDegrees); +} + +bool Mat_CheckRange(Mat m) { + return cv::checkRange(*m); +} + +void Mat_Compare(Mat src1, Mat src2, Mat dst, int ct) { + cv::compare(*src1, *src2, *dst, ct); +} + +int Mat_CountNonZero(Mat src) { + return cv::countNonZero(*src); +} + + +void Mat_CompleteSymm(Mat m, bool lowerToUpper) { + cv::completeSymm(*m, lowerToUpper); +} + +void Mat_ConvertScaleAbs(Mat src, Mat dst, double alpha, double beta) { + cv::convertScaleAbs(*src, *dst, alpha, beta); +} + +void Mat_CopyMakeBorder(Mat src, Mat dst, int top, int bottom, int left, int right, int borderType, + Scalar value) { + cv::Scalar c_value(value.val1, value.val2, value.val3, value.val4); + cv::copyMakeBorder(*src, *dst, top, bottom, left, right, borderType, c_value); +} + +void Mat_DCT(Mat src, Mat dst, int flags) { + cv::dct(*src, *dst, flags); +} + +double Mat_Determinant(Mat m) { + return cv::determinant(*m); +} + +void Mat_DFT(Mat m, Mat dst, int flags) { + cv::dft(*m, *dst, flags); +} + +void Mat_Divide(Mat src1, Mat src2, Mat dst) { + cv::divide(*src1, *src2, *dst); +} + +bool Mat_Eigen(Mat src, Mat eigenvalues, Mat eigenvectors) { + return cv::eigen(*src, *eigenvalues, *eigenvectors); +} + +void Mat_EigenNonSymmetric(Mat src, Mat eigenvalues, Mat eigenvectors) { + cv::eigenNonSymmetric(*src, *eigenvalues, *eigenvectors); +} + +void Mat_Exp(Mat src, Mat dst) { + cv::exp(*src, *dst); +} + +void Mat_ExtractChannel(Mat src, Mat dst, int coi) { + cv::extractChannel(*src, *dst, coi); +} + +void Mat_FindNonZero(Mat src, Mat idx) { + cv::findNonZero(*src, *idx); +} + +void Mat_Flip(Mat src, Mat dst, int flipCode) { + cv::flip(*src, *dst, flipCode); +} + +void Mat_Gemm(Mat src1, Mat src2, double alpha, Mat src3, double beta, Mat dst, int flags) { + cv::gemm(*src1, *src2, alpha, *src3, beta, *dst, flags); +} + +int Mat_GetOptimalDFTSize(int vecsize) { + return cv::getOptimalDFTSize(vecsize); +} + +void Mat_Hconcat(Mat src1, Mat src2, Mat dst) { + cv::hconcat(*src1, *src2, *dst); +} + +void Mat_Vconcat(Mat src1, Mat src2, Mat dst) { + cv::vconcat(*src1, *src2, *dst); +} + +void Rotate(Mat src, Mat dst, int rotateCode) { + cv::rotate(*src, *dst, rotateCode); +} + +void Mat_Idct(Mat src, Mat dst, int flags) { + cv::idct(*src, *dst, flags); +} + +void Mat_Idft(Mat src, Mat dst, int flags, int nonzeroRows) { + cv::idft(*src, *dst, flags, nonzeroRows); +} + +void Mat_InRange(Mat src, Mat lowerb, Mat upperb, Mat dst) { + cv::inRange(*src, *lowerb, *upperb, *dst); +} + +void Mat_InRangeWithScalar(Mat src, Scalar lowerb, Scalar upperb, Mat dst) { + cv::Scalar lb = cv::Scalar(lowerb.val1, lowerb.val2, lowerb.val3, lowerb.val4); + cv::Scalar ub = cv::Scalar(upperb.val1, upperb.val2, upperb.val3, upperb.val4); + cv::inRange(*src, lb, ub, *dst); +} + +void Mat_InsertChannel(Mat src, Mat dst, int coi) { + cv::insertChannel(*src, *dst, coi); +} + +double Mat_Invert(Mat src, Mat dst, int flags) { + double ret = cv::invert(*src, *dst, flags); + return ret; +} + +double KMeans(Mat data, int k, Mat bestLabels, TermCriteria criteria, int attempts, int flags, Mat centers) { + double ret = cv::kmeans(*data, k, *bestLabels, *criteria, attempts, flags, *centers); + return ret; +} + +double KMeansPoints(PointVector points, int k, Mat bestLabels, TermCriteria criteria, int attempts, int flags, Mat centers) { + std::vector pts; + copyPointVectorToPoint2fVector(points, &pts); + double ret = cv::kmeans(pts, k, *bestLabels, *criteria, attempts, flags, *centers); + return ret; +} + +void Mat_Log(Mat src, Mat dst) { + cv::log(*src, *dst); +} + +void Mat_Magnitude(Mat x, Mat y, Mat magnitude) { + cv::magnitude(*x, *y, *magnitude); +} + +void Mat_Max(Mat src1, Mat src2, Mat dst) { + cv::max(*src1, *src2, *dst); +} + +void Mat_MeanStdDev(Mat src, Mat dstMean, Mat dstStdDev) { + cv::meanStdDev(*src, *dstMean, *dstStdDev); +} + +void Mat_Merge(struct Mats mats, Mat dst) { + std::vector images; + + for (int i = 0; i < mats.length; ++i) { + images.push_back(*mats.mats[i]); + } + + cv::merge(images, *dst); +} + +void Mat_Min(Mat src1, Mat src2, Mat dst) { + cv::min(*src1, *src2, *dst); +} + +void Mat_MinMaxIdx(Mat m, double* minVal, double* maxVal, int* minIdx, int* maxIdx) { + cv::minMaxIdx(*m, minVal, maxVal, minIdx, maxIdx); +} + +void Mat_MinMaxLoc(Mat m, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc) { + cv::Point cMinLoc; + cv::Point cMaxLoc; + cv::minMaxLoc(*m, minVal, maxVal, &cMinLoc, &cMaxLoc); + + minLoc->x = cMinLoc.x; + minLoc->y = cMinLoc.y; + maxLoc->x = cMaxLoc.x; + maxLoc->y = cMaxLoc.y; +} + +void Mat_MixChannels(struct Mats src, struct Mats dst, struct IntVector fromTo) { + std::vector srcMats; + + for (int i = 0; i < src.length; ++i) { + srcMats.push_back(*src.mats[i]); + } + + std::vector dstMats; + + for (int i = 0; i < dst.length; ++i) { + dstMats.push_back(*dst.mats[i]); + } + + std::vector fromTos; + + for (int i = 0; i < fromTo.length; ++i) { + fromTos.push_back(fromTo.val[i]); + } + + cv::mixChannels(srcMats, dstMats, fromTos); +} + +void Mat_MulSpectrums(Mat a, Mat b, Mat c, int flags) { + cv::mulSpectrums(*a, *b, *c, flags); +} + +void Mat_Multiply(Mat src1, Mat src2, Mat dst) { + cv::multiply(*src1, *src2, *dst); +} + +void Mat_MultiplyWithParams(Mat src1, Mat src2, Mat dst, double scale, int dtype) { + cv::multiply(*src1, *src2, *dst, scale, dtype); +} + +void Mat_Normalize(Mat src, Mat dst, double alpha, double beta, int typ) { + cv::normalize(*src, *dst, alpha, beta, typ); +} + +double Norm(Mat src1, int normType) { + return cv::norm(*src1, normType); +} + +double NormWithMats(Mat src1, Mat src2, int normType) { + return cv::norm(*src1, *src2, normType); +} + +void Mat_PerspectiveTransform(Mat src, Mat dst, Mat tm) { + cv::perspectiveTransform(*src, *dst, *tm); +} + +bool Mat_Solve(Mat src1, Mat src2, Mat dst, int flags) { + return cv::solve(*src1, *src2, *dst, flags); +} + +int Mat_SolveCubic(Mat coeffs, Mat roots) { + return cv::solveCubic(*coeffs, *roots); +} + +double Mat_SolvePoly(Mat coeffs, Mat roots, int maxIters) { + return cv::solvePoly(*coeffs, *roots, maxIters); +} + +void Mat_Reduce(Mat src, Mat dst, int dim, int rType, int dType) { + cv::reduce(*src, *dst, dim, rType, dType); +} + +void Mat_ReduceArgMax(Mat src, Mat dst, int axis, bool lastIndex) { + cv::reduceArgMax(*src, *dst, axis, lastIndex); +} + +void Mat_ReduceArgMin(Mat src, Mat dst, int axis, bool lastIndex) { + cv::reduceArgMin(*src, *dst, axis, lastIndex); +} + + +void Mat_Repeat(Mat src, int nY, int nX, Mat dst) { + cv::repeat(*src, nY, nX, *dst); +} + +void Mat_ScaleAdd(Mat src1, double alpha, Mat src2, Mat dst) { + cv::scaleAdd(*src1, alpha, *src2, *dst); +} + +void Mat_SetIdentity(Mat src, double scalar) { + cv::setIdentity(*src, scalar); +} + +void Mat_Sort(Mat src, Mat dst, int flags) { + cv::sort(*src, *dst, flags); +} + +void Mat_SortIdx(Mat src, Mat dst, int flags) { + cv::sortIdx(*src, *dst, flags); +} + +void Mat_Split(Mat src, struct Mats* mats) { + std::vector channels; + cv::split(*src, channels); + mats->mats = new Mat[channels.size()]; + + for (size_t i = 0; i < channels.size(); ++i) { + mats->mats[i] = new cv::Mat(channels[i]); + } + + mats->length = (int)channels.size(); +} + +void Mat_Subtract(Mat src1, Mat src2, Mat dst) { + cv::subtract(*src1, *src2, *dst); +} + +Scalar Mat_Trace(Mat src) { + cv::Scalar c = cv::trace(*src); + Scalar scal = Scalar(); + scal.val1 = c.val[0]; + scal.val2 = c.val[1]; + scal.val3 = c.val[2]; + scal.val4 = c.val[3]; + return scal; +} + +void Mat_Transform(Mat src, Mat dst, Mat tm) { + cv::transform(*src, *dst, *tm); +} + +void Mat_Transpose(Mat src, Mat dst) { + cv::transpose(*src, *dst); +} + +void Mat_PolarToCart(Mat magnitude, Mat degree, Mat x, Mat y, bool angleInDegrees) { + cv::polarToCart(*magnitude, *degree, *x, *y, angleInDegrees); +} + +void Mat_Pow(Mat src, double power, Mat dst) { + cv::pow(*src, power, *dst); +} + +void Mat_Phase(Mat x, Mat y, Mat angle, bool angleInDegrees) { + cv::phase(*x, *y, *angle, angleInDegrees); +} + + +Scalar Mat_Sum(Mat src) { + cv::Scalar c = cv::sum(*src); + Scalar scal = Scalar(); + scal.val1 = c.val[0]; + scal.val2 = c.val[1]; + scal.val3 = c.val[2]; + scal.val4 = c.val[3]; + return scal; +} + +// TermCriteria_New creates a new TermCriteria +TermCriteria TermCriteria_New(int typ, int maxCount, double epsilon) { + return new cv::TermCriteria(typ, maxCount, epsilon); +} + +void Contours_Close(struct Contours cs) { + for (int i = 0; i < cs.length; i++) { + Points_Close(cs.contours[i]); + } + + delete[] cs.contours; +} + +void CStrings_Close(struct CStrings cstrs) { + for ( int i = 0; i < cstrs.length; i++ ) { + delete [] cstrs.strs[i]; + } + delete [] cstrs.strs; +} + +void KeyPoints_Close(struct KeyPoints ks) { + delete[] ks.keypoints; +} + +void Points_Close(Points ps) { + for (size_t i = 0; i < ps.length; i++) { + Point_Close(ps.points[i]); + } + + delete[] ps.points; +} + +void Point_Close(Point p) {} + +void Rects_Close(struct Rects rs) { + delete[] rs.rects; +} + +void DMatches_Close(struct DMatches ds) { + delete[] ds.dmatches; +} + +void MultiDMatches_Close(struct MultiDMatches mds) { + for (size_t i = 0; i < mds.length; i++) { + DMatches_Close(mds.dmatches[i]); + } + + delete[] mds.dmatches; +} + +struct DMatches MultiDMatches_get(struct MultiDMatches mds, int index) { + return mds.dmatches[index]; +} + +// since it is next to impossible to iterate over mats.mats on the cgo side +Mat Mats_get(struct Mats mats, int i) { + return mats.mats[i]; +} + +void Mats_Close(struct Mats mats) { + delete[] mats.mats; +} + +void ByteArray_Release(struct ByteArray buf) { + delete[] buf.data; +} + +struct ByteArray toByteArray(const char* buf, int len) { + ByteArray ret = {new char[len], len}; + memcpy(ret.data, buf, len); + return ret; +} + +int64 GetCVTickCount() { + return cv::getTickCount(); +} + +double GetTickFrequency() { + return cv::getTickFrequency(); +} + +Mat Mat_rowRange(Mat m,int startrow,int endrow) { + return new cv::Mat(m->rowRange(startrow,endrow)); +} + +Mat Mat_colRange(Mat m,int startrow,int endrow) { + return new cv::Mat(m->colRange(startrow,endrow)); +} + +PointVector PointVector_New() { + return new std::vector< cv::Point >; +} + +PointVector PointVector_NewFromPoints(Contour points) { + std::vector* cntr = new std::vector; + + for (size_t i = 0; i < points.length; i++) { + cntr->push_back(cv::Point(points.points[i].x, points.points[i].y)); + } + + return cntr; +} + +PointVector PointVector_NewFromMat(Mat mat) { + std::vector* pts = new std::vector; + *pts = (std::vector) *mat; + return pts; +} + +Point PointVector_At(PointVector pv, int idx) { + cv::Point p = pv->at(idx); + return Point{.x = p.x, .y = p.y}; +} + +void PointVector_Append(PointVector pv, Point p) { + pv->push_back(cv::Point(p.x, p.y)); +} + +int PointVector_Size(PointVector p) { + return p->size(); +} + +void PointVector_Close(PointVector p) { + p->clear(); + delete p; +} + +PointsVector PointsVector_New() { + return new std::vector< std::vector< cv::Point > >; +} + +PointsVector PointsVector_NewFromPoints(Contours points) { + std::vector< std::vector< cv::Point > >* pv = new std::vector< std::vector< cv::Point > >; + + for (size_t i = 0; i < points.length; i++) { + Contour contour = points.contours[i]; + + std::vector cntr; + + for (size_t i = 0; i < contour.length; i++) { + cntr.push_back(cv::Point(contour.points[i].x, contour.points[i].y)); + } + + pv->push_back(cntr); + } + + return pv; +} + +int PointsVector_Size(PointsVector ps) { + return ps->size(); +} + +PointVector PointsVector_At(PointsVector ps, int idx) { + std::vector< cv::Point >* p = &(ps->at(idx)); + return p; +} + +void PointsVector_Append(PointsVector psv, PointVector pv) { + psv->push_back(*pv); +} + +void PointsVector_Close(PointsVector ps) { + ps->clear(); + delete ps; +} + +Point2fVector Point2fVector_New() { + return new std::vector< cv::Point2f >; +} + +Point2fVector Point2fVector_NewFromPoints(Contour2f points) { + std::vector* cntr = new std::vector; + + for (size_t i = 0; i < points.length; i++) { + cntr->push_back(cv::Point2f(points.points[i].x, points.points[i].y)); + } + + return cntr; +} + +Point2fVector Point2fVector_NewFromMat(Mat mat) { + std::vector* pts = new std::vector; + *pts = (std::vector) *mat; + return pts; +} + +Point2f Point2fVector_At(Point2fVector pfv, int idx) { + cv::Point2f p = pfv->at(idx); + return Point2f{.x = p.x, .y = p.y}; +} + +int Point2fVector_Size(Point2fVector pfv) { + return pfv->size(); +} + +void Point2fVector_Close(Point2fVector pv) { + pv->clear(); + delete pv; +} + + +void IntVector_Close(struct IntVector ivec) { + delete[] ivec.val; +} + +RNG TheRNG() { + return &cv::theRNG(); +} + +void SetRNGSeed(int seed) { + cv::setRNGSeed(seed); +} + +void RNG_Fill(RNG rng, Mat mat, int distType, double a, double b, bool saturateRange) { + rng->fill(*mat, distType, a, b, saturateRange); +} + +double RNG_Gaussian(RNG rng, double sigma) { + return rng->gaussian(sigma); +} + +unsigned int RNG_Next(RNG rng) { + return rng->next(); +} + +void RandN(Mat mat, Scalar mean, Scalar stddev) { + cv::Scalar m = cv::Scalar(mean.val1, mean.val2, mean.val3, mean.val4); + cv::Scalar s = cv::Scalar(stddev.val1, stddev.val2, stddev.val3, stddev.val4); + cv::randn(*mat, m, s); +} + +void RandShuffle(Mat mat) { + cv::randShuffle(*mat); +} + +void RandShuffleWithParams(Mat mat, double iterFactor, RNG rng) { + cv::randShuffle(*mat, iterFactor, rng); +} + +void RandU(Mat mat, Scalar low, Scalar high) { + cv::Scalar l = cv::Scalar(low.val1, low.val2, low.val3, low.val4); + cv::Scalar h = cv::Scalar(high.val1, high.val2, high.val3, high.val4); + cv::randn(*mat, l, h); +} + +void copyPointVectorToPoint2fVector(PointVector src, Point2fVector dest) { + for (size_t i = 0; i < src->size(); i++) { + dest->push_back(cv::Point2f(src->at(i).x, src->at(i).y)); + } +} + +void StdByteVectorInitialize(void* data) { + new (data) std::vector(); +} + +void StdByteVectorFree(void *data) { + reinterpret_cast *>(data)->~vector(); +} + +size_t StdByteVectorLen(void *data) { + return reinterpret_cast *>(data)->size(); +} + +uint8_t* StdByteVectorData(void *data) { + return reinterpret_cast *>(data)->data(); +} + +Points2fVector Points2fVector_New(){ + return new std::vector< std::vector< cv::Point2f > >; +} + +Points2fVector Points2fVector_NewFromPoints(Contours2f points) { + Points2fVector pv = Points2fVector_New(); + for(size_t i = 0;isize(); +} + +Point2fVector Points2fVector_At(Points2fVector ps, int idx) { + return &(ps->at(idx)); +} + +void Points2fVector_Append(Points2fVector psv, Point2fVector pv) { + psv->push_back(*pv); +} + +void Points2fVector_Close(Points2fVector ps) { + ps->clear(); + delete ps; +} + +Point3fVector Point3fVector_New() { + return new std::vector< cv::Point3f >; +} + + +Point3fVector Point3fVector_NewFromPoints(Contour3f points) { + std::vector *cntr = new std::vector; + for(size_t i = 0;i< points.length;i++) { + cntr->push_back(cv::Point3f( + points.points[i].x, + points.points[i].y, + points.points[i].z + )); + } + + return cntr; +} + +Point3fVector Point3fVector_NewFromMat(Mat mat) { + std::vector *pts = new std::vector; + *pts = (std::vector) *mat; + return pts; +} + +Point3f Point3fVector_At(Point3fVector pfv, int idx) { + cv::Point3f p = pfv->at(idx); + return Point3f{ + .x = p.x, + .y = p.y, + .z = p.z + }; +} + +void Point3fVector_Append(Point3fVector pfv, Point3f point) { + pfv->push_back(cv::Point3f(point.x, point.y, point.z)); +} + +int Point3fVector_Size(Point3fVector pfv) { + return pfv->size(); +} + +void Point3fVector_Close(Point3fVector pv) { + pv->clear(); + delete pv; +} + +Points3fVector Points3fVector_New(){ + return new std::vector< std::vector< cv::Point3f > >; +} + +Points3fVector Points3fVector_NewFromPoints(Contours3f points) { + Points3fVector pv = Points3fVector_New(); + for(size_t i = 0;isize(); +} + +Point3fVector Points3fVector_At(Points3fVector ps, int idx) { + return &(ps->at(idx)); +} + +void Points3fVector_Append(Points3fVector psv, Point3fVector pv) { + psv->push_back(*pv); +} + +void Points3fVector_Close(Points3fVector ps) { + ps->clear(); + delete ps; +} + +void SetNumThreads(int n) { + cv::setNumThreads(n); +} + +int GetNumThreads() { + return cv::getNumThreads(); +} diff --git a/vendor/gocv.io/x/gocv/core.go b/vendor/gocv.io/x/gocv/core.go new file mode 100644 index 00000000..3f30900b --- /dev/null +++ b/vendor/gocv.io/x/gocv/core.go @@ -0,0 +1,2846 @@ +package gocv + +/* +#include +#include "core.h" +*/ +import "C" +import ( + "errors" + "image" + "image/color" + "reflect" + "unsafe" +) + +const ( + // MatChannels1 is a single channel Mat. + MatChannels1 = 0 + + // MatChannels2 is 2 channel Mat. + MatChannels2 = 8 + + // MatChannels3 is 3 channel Mat. + MatChannels3 = 16 + + // MatChannels4 is 4 channel Mat. + MatChannels4 = 24 +) + +// MatType is the type for the various different kinds of Mat you can create. +type MatType int + +const ( + // MatTypeCV8U is a Mat of 8-bit unsigned int + MatTypeCV8U MatType = 0 + + // MatTypeCV8S is a Mat of 8-bit signed int + MatTypeCV8S MatType = 1 + + // MatTypeCV16U is a Mat of 16-bit unsigned int + MatTypeCV16U MatType = 2 + + // MatTypeCV16S is a Mat of 16-bit signed int + MatTypeCV16S MatType = 3 + + // MatTypeCV16SC2 is a Mat of 16-bit signed int with 2 channels + MatTypeCV16SC2 = MatTypeCV16S + MatChannels2 + + // MatTypeCV32S is a Mat of 32-bit signed int + MatTypeCV32S MatType = 4 + + // MatTypeCV32F is a Mat of 32-bit float + MatTypeCV32F MatType = 5 + + // MatTypeCV64F is a Mat of 64-bit float + MatTypeCV64F MatType = 6 + + // MatTypeCV8UC1 is a Mat of 8-bit unsigned int with a single channel + MatTypeCV8UC1 = MatTypeCV8U + MatChannels1 + + // MatTypeCV8UC2 is a Mat of 8-bit unsigned int with 2 channels + MatTypeCV8UC2 = MatTypeCV8U + MatChannels2 + + // MatTypeCV8UC3 is a Mat of 8-bit unsigned int with 3 channels + MatTypeCV8UC3 = MatTypeCV8U + MatChannels3 + + // MatTypeCV8UC4 is a Mat of 8-bit unsigned int with 4 channels + MatTypeCV8UC4 = MatTypeCV8U + MatChannels4 + + // MatTypeCV8SC1 is a Mat of 8-bit signed int with a single channel + MatTypeCV8SC1 = MatTypeCV8S + MatChannels1 + + // MatTypeCV8SC2 is a Mat of 8-bit signed int with 2 channels + MatTypeCV8SC2 = MatTypeCV8S + MatChannels2 + + // MatTypeCV8SC3 is a Mat of 8-bit signed int with 3 channels + MatTypeCV8SC3 = MatTypeCV8S + MatChannels3 + + // MatTypeCV8SC4 is a Mat of 8-bit signed int with 4 channels + MatTypeCV8SC4 = MatTypeCV8S + MatChannels4 + + // MatTypeCV16UC1 is a Mat of 16-bit unsigned int with a single channel + MatTypeCV16UC1 = MatTypeCV16U + MatChannels1 + + // MatTypeCV16UC2 is a Mat of 16-bit unsigned int with 2 channels + MatTypeCV16UC2 = MatTypeCV16U + MatChannels2 + + // MatTypeCV16UC3 is a Mat of 16-bit unsigned int with 3 channels + MatTypeCV16UC3 = MatTypeCV16U + MatChannels3 + + // MatTypeCV16UC4 is a Mat of 16-bit unsigned int with 4 channels + MatTypeCV16UC4 = MatTypeCV16U + MatChannels4 + + // MatTypeCV16SC1 is a Mat of 16-bit signed int with a single channel + MatTypeCV16SC1 = MatTypeCV16S + MatChannels1 + + // MatTypeCV16SC3 is a Mat of 16-bit signed int with 3 channels + MatTypeCV16SC3 = MatTypeCV16S + MatChannels3 + + // MatTypeCV16SC4 is a Mat of 16-bit signed int with 4 channels + MatTypeCV16SC4 = MatTypeCV16S + MatChannels4 + + // MatTypeCV32SC1 is a Mat of 32-bit signed int with a single channel + MatTypeCV32SC1 = MatTypeCV32S + MatChannels1 + + // MatTypeCV32SC2 is a Mat of 32-bit signed int with 2 channels + MatTypeCV32SC2 = MatTypeCV32S + MatChannels2 + + // MatTypeCV32SC3 is a Mat of 32-bit signed int with 3 channels + MatTypeCV32SC3 = MatTypeCV32S + MatChannels3 + + // MatTypeCV32SC4 is a Mat of 32-bit signed int with 4 channels + MatTypeCV32SC4 = MatTypeCV32S + MatChannels4 + + // MatTypeCV32FC1 is a Mat of 32-bit float int with a single channel + MatTypeCV32FC1 = MatTypeCV32F + MatChannels1 + + // MatTypeCV32FC2 is a Mat of 32-bit float int with 2 channels + MatTypeCV32FC2 = MatTypeCV32F + MatChannels2 + + // MatTypeCV32FC3 is a Mat of 32-bit float int with 3 channels + MatTypeCV32FC3 = MatTypeCV32F + MatChannels3 + + // MatTypeCV32FC4 is a Mat of 32-bit float int with 4 channels + MatTypeCV32FC4 = MatTypeCV32F + MatChannels4 + + // MatTypeCV64FC1 is a Mat of 64-bit float int with a single channel + MatTypeCV64FC1 = MatTypeCV64F + MatChannels1 + + // MatTypeCV64FC2 is a Mat of 64-bit float int with 2 channels + MatTypeCV64FC2 = MatTypeCV64F + MatChannels2 + + // MatTypeCV64FC3 is a Mat of 64-bit float int with 3 channels + MatTypeCV64FC3 = MatTypeCV64F + MatChannels3 + + // MatTypeCV64FC4 is a Mat of 64-bit float int with 4 channels + MatTypeCV64FC4 = MatTypeCV64F + MatChannels4 +) + +// CompareType is used for Compare operations to indicate which kind of +// comparison to use. +type CompareType int + +const ( + // CompareEQ src1 is equal to src2. + CompareEQ CompareType = 0 + + // CompareGT src1 is greater than src2. + CompareGT CompareType = 1 + + // CompareGE src1 is greater than or equal to src2. + CompareGE CompareType = 2 + + // CompareLT src1 is less than src2. + CompareLT CompareType = 3 + + // CompareLE src1 is less than or equal to src2. + CompareLE CompareType = 4 + + // CompareNE src1 is unequal to src2. + CompareNE CompareType = 5 +) + +type Point2f struct { + X float32 + Y float32 +} + +func NewPoint2f(x, y float32) Point2f { + return Point2f{x, y} +} + +var ErrEmptyByteSlice = errors.New("empty byte array") + +// Mat represents an n-dimensional dense numerical single-channel +// or multi-channel array. It can be used to store real or complex-valued +// vectors and matrices, grayscale or color images, voxel volumes, +// vector fields, point clouds, tensors, and histograms. +// +// For further details, please see: +// http://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html +// +type Mat struct { + p C.Mat + + // Non-nil if Mat was created with a []byte (using NewMatFromBytes()). Nil otherwise. + d []byte +} + +// NewMat returns a new empty Mat. +func NewMat() Mat { + return newMat(C.Mat_New()) +} + +// NewMatWithSize returns a new Mat with a specific size and type. +func NewMatWithSize(rows int, cols int, mt MatType) Mat { + return newMat(C.Mat_NewWithSize(C.int(rows), C.int(cols), C.int(mt))) +} + +// NewMatWithSizes returns a new multidimensional Mat with a specific size and type. +func NewMatWithSizes(sizes []int, mt MatType) Mat { + sizesArray := make([]C.int, len(sizes)) + for i, s := range sizes { + sizesArray[i] = C.int(s) + } + + sizesIntVector := C.IntVector{ + val: (*C.int)(&sizesArray[0]), + length: C.int(len(sizes)), + } + return newMat(C.Mat_NewWithSizes(sizesIntVector, C.int(mt))) +} + +// NewMatWithSizesWithScalar returns a new multidimensional Mat with a specific size, type and scalar value. +func NewMatWithSizesWithScalar(sizes []int, mt MatType, s Scalar) Mat { + csizes := []C.int{} + for _, v := range sizes { + csizes = append(csizes, C.int(v)) + } + sizesVector := C.struct_IntVector{} + sizesVector.val = (*C.int)(&csizes[0]) + sizesVector.length = (C.int)(len(csizes)) + + sVal := C.struct_Scalar{ + val1: C.double(s.Val1), + val2: C.double(s.Val2), + val3: C.double(s.Val3), + val4: C.double(s.Val4), + } + + return newMat(C.Mat_NewWithSizesFromScalar(sizesVector, C.int(mt), sVal)) +} + +// NewMatWithSizesWithScalar returns a new multidimensional Mat with a specific size, type and preexisting data. +func NewMatWithSizesFromBytes(sizes []int, mt MatType, data []byte) (Mat, error) { + cBytes, err := toByteArray(data) + if err != nil { + return Mat{}, err + } + + csizes := []C.int{} + for _, v := range sizes { + csizes = append(csizes, C.int(v)) + } + sizesVector := C.struct_IntVector{} + sizesVector.val = (*C.int)(&csizes[0]) + sizesVector.length = (C.int)(len(csizes)) + + return newMat(C.Mat_NewWithSizesFromBytes(sizesVector, C.int(mt), *cBytes)), nil +} + +// NewMatFromScalar returns a new Mat for a specific Scalar value +func NewMatFromScalar(s Scalar, mt MatType) Mat { + sVal := C.struct_Scalar{ + val1: C.double(s.Val1), + val2: C.double(s.Val2), + val3: C.double(s.Val3), + val4: C.double(s.Val4), + } + + return newMat(C.Mat_NewFromScalar(sVal, C.int(mt))) +} + +// NewMatWithSizeFromScalar returns a new Mat for a specific Scala value with a specific size and type +// This simplifies creation of specific color filters or creating Mats of specific colors and sizes +func NewMatWithSizeFromScalar(s Scalar, rows int, cols int, mt MatType) Mat { + sVal := C.struct_Scalar{ + val1: C.double(s.Val1), + val2: C.double(s.Val2), + val3: C.double(s.Val3), + val4: C.double(s.Val4), + } + + return newMat(C.Mat_NewWithSizeFromScalar(sVal, C.int(rows), C.int(cols), C.int(mt))) +} + +// NewMatFromBytes returns a new Mat with a specific size and type, initialized from a []byte. +func NewMatFromBytes(rows int, cols int, mt MatType, data []byte) (Mat, error) { + cBytes, err := toByteArray(data) + if err != nil { + return Mat{}, err + } + mat := newMat(C.Mat_NewFromBytes(C.int(rows), C.int(cols), C.int(mt), *cBytes)) + + // Store a reference to the backing data slice. This is needed because we pass the backing + // array directly to C code and without keeping a Go reference to it, it might end up + // garbage collected which would result in crashes. + // + // TODO(bga): This could live in newMat() but I wanted to reduce the change surface. + // TODO(bga): Code that needs access to the array from Go could use this directly. + mat.d = data + + return mat, nil +} + +// Returns an identity matrix of the specified size and type. +// +// The method returns a Matlab-style identity matrix initializer, similarly to Mat::zeros. Similarly to Mat::ones. +// For further details, please see: +// https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#a2cf9b9acde7a9852542bbc20ef851ed2 +func Eye(rows int, cols int, mt MatType) Mat { + return newMat(C.Eye(C.int(rows), C.int(cols), C.int(mt))) +} + +// Returns a zero array of the specified size and type. +// +// The method returns a Matlab-style zero array initializer. +// For further details, please see: +// https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#a0b57b6a326c8876d944d188a46e0f556 +func Zeros(rows int, cols int, mt MatType) Mat { + return newMat(C.Zeros(C.int(rows), C.int(cols), C.int(mt))) +} + +// Returns an array of all 1's of the specified size and type. +// +// The method returns a Matlab-style 1's array initializer +// For further details, please see: +// https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#a69ae0402d116fc9c71908d8508dc2f09 +func Ones(rows int, cols int, mt MatType) Mat { + return newMat(C.Ones(C.int(rows), C.int(cols), C.int(mt))) +} + +// FromPtr returns a new Mat with a specific size and type, initialized from a Mat Ptr. +func (m *Mat) FromPtr(rows int, cols int, mt MatType, prow int, pcol int) (Mat, error) { + return newMat(C.Mat_FromPtr(m.p, C.int(rows), C.int(cols), C.int(mt), C.int(prow), C.int(pcol))), nil +} + +// Ptr returns the Mat's underlying object pointer. +func (m *Mat) Ptr() C.Mat { + return m.p +} + +// Empty determines if the Mat is empty or not. +func (m *Mat) Empty() bool { + isEmpty := C.Mat_Empty(m.p) + return isEmpty != 0 +} + +// IsContinuous determines if the Mat is continuous. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#aa90cea495029c7d1ee0a41361ccecdf3 +// +func (m *Mat) IsContinuous() bool { + return bool(C.Mat_IsContinuous(m.p)) +} + +// Clone returns a cloned full copy of the Mat. +func (m *Mat) Clone() Mat { + return newMat(C.Mat_Clone(m.p)) +} + +// CopyTo copies Mat into destination Mat. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#a33fd5d125b4c302b0c9aa86980791a77 +// +func (m *Mat) CopyTo(dst *Mat) { + C.Mat_CopyTo(m.p, dst.p) + return +} + +// CopyToWithMask copies Mat into destination Mat after applying the mask Mat. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#a626fe5f96d02525e2604d2ad46dd574f +// +func (m *Mat) CopyToWithMask(dst *Mat, mask Mat) { + C.Mat_CopyToWithMask(m.p, dst.p, mask.p) + return +} + +// ConvertTo converts Mat into destination Mat. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b +// +func (m *Mat) ConvertTo(dst *Mat, mt MatType) { + C.Mat_ConvertTo(m.p, dst.p, C.int(mt)) + return +} + +func (m *Mat) ConvertToWithParams(dst *Mat, mt MatType, alpha, beta float32) { + C.Mat_ConvertToWithParams(m.p, dst.p, C.int(mt), C.float(alpha), C.float(beta)) + return +} + +// Total returns the total number of array elements. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#aa4d317d43fb0cba9c2503f3c61b866c8 +// +func (m *Mat) Total() int { + return int(C.Mat_Total(m.p)) +} + +// Size returns an array with one element for each dimension containing the size of that dimension for the Mat. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#aa4d317d43fb0cba9c2503f3c61b866c8 +// +func (m *Mat) Size() (dims []int) { + cdims := C.IntVector{} + C.Mat_Size(m.p, &cdims) + defer C.IntVector_Close(cdims) + + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(cdims.val)), + Len: int(cdims.length), + Cap: int(cdims.length), + } + pdims := *(*[]C.int)(unsafe.Pointer(h)) + + for i := 0; i < int(cdims.length); i++ { + dims = append(dims, int(pdims[i])) + } + return +} + +// ToBytes copies the underlying Mat data to a byte array. +// +// For further details, please see: +// https://docs.opencv.org/3.3.1/d3/d63/classcv_1_1Mat.html#a4d33bed1c850265370d2af0ff02e1564 +func (m *Mat) ToBytes() []byte { + b := C.Mat_DataPtr(m.p) + return toGoBytes(b) +} + +// DataPtrUint8 returns a slice that references the OpenCV allocated data. +// +// The data is no longer valid once the Mat has been closed. Any data that +// needs to be accessed after the Mat is closed must be copied into Go memory. +func (m *Mat) DataPtrUint8() ([]uint8, error) { + if !m.IsContinuous() { + return nil, errors.New("DataPtrUint8 requires continuous Mat") + } + + p := C.Mat_DataPtr(m.p) + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(p.data)), + Len: int(p.length), + Cap: int(p.length), + } + return *(*[]uint8)(unsafe.Pointer(h)), nil +} + +// DataPtrInt8 returns a slice that references the OpenCV allocated data. +// +// The data is no longer valid once the Mat has been closed. Any data that +// needs to be accessed after the Mat is closed must be copied into Go memory. +func (m *Mat) DataPtrInt8() ([]int8, error) { + if m.Type()&MatTypeCV8S != MatTypeCV8S { + return nil, errors.New("DataPtrInt8 only supports MatTypeCV8S") + } + + if !m.IsContinuous() { + return nil, errors.New("DataPtrInt8 requires continuous Mat") + } + + p := C.Mat_DataPtr(m.p) + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(p.data)), + Len: int(p.length), + Cap: int(p.length), + } + return *(*[]int8)(unsafe.Pointer(h)), nil +} + +// DataPtrUint16 returns a slice that references the OpenCV allocated data. +// +// The data is no longer valid once the Mat has been closed. Any data that +// needs to be accessed after the Mat is closed must be copied into Go memory. +func (m *Mat) DataPtrUint16() ([]uint16, error) { + if m.Type()&MatTypeCV16U != MatTypeCV16U { + return nil, errors.New("DataPtrUint16 only supports MatTypeCV16U") + } + + if !m.IsContinuous() { + return nil, errors.New("DataPtrUint16 requires continuous Mat") + } + + p := C.Mat_DataPtr(m.p) + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(p.data)), + Len: int(p.length) / 2, + Cap: int(p.length) / 2, + } + return *(*[]uint16)(unsafe.Pointer(h)), nil +} + +// DataPtrInt16 returns a slice that references the OpenCV allocated data. +// +// The data is no longer valid once the Mat has been closed. Any data that +// needs to be accessed after the Mat is closed must be copied into Go memory. +func (m *Mat) DataPtrInt16() ([]int16, error) { + if m.Type()&MatTypeCV16S != MatTypeCV16S { + return nil, errors.New("DataPtrInt16 only supports MatTypeCV16S") + } + + if !m.IsContinuous() { + return nil, errors.New("DataPtrInt16 requires continuous Mat") + } + + p := C.Mat_DataPtr(m.p) + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(p.data)), + Len: int(p.length) / 2, + Cap: int(p.length) / 2, + } + return *(*[]int16)(unsafe.Pointer(h)), nil +} + +// DataPtrFloat32 returns a slice that references the OpenCV allocated data. +// +// The data is no longer valid once the Mat has been closed. Any data that +// needs to be accessed after the Mat is closed must be copied into Go memory. +func (m *Mat) DataPtrFloat32() ([]float32, error) { + if m.Type()&MatTypeCV32F != MatTypeCV32F { + return nil, errors.New("DataPtrFloat32 only supports MatTypeCV32F") + } + + if !m.IsContinuous() { + return nil, errors.New("DataPtrFloat32 requires continuous Mat") + } + + p := C.Mat_DataPtr(m.p) + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(p.data)), + Len: int(p.length) / 4, + Cap: int(p.length) / 4, + } + return *(*[]float32)(unsafe.Pointer(h)), nil +} + +// DataPtrFloat64 returns a slice that references the OpenCV allocated data. +// +// The data is no longer valid once the Mat has been closed. Any data that +// needs to be accessed after the Mat is closed must be copied into Go memory. +func (m *Mat) DataPtrFloat64() ([]float64, error) { + if m.Type()&MatTypeCV64F != MatTypeCV64F { + return nil, errors.New("DataPtrFloat64 only supports MatTypeCV64F") + } + + if !m.IsContinuous() { + return nil, errors.New("DataPtrFloat64 requires continuous Mat") + } + + p := C.Mat_DataPtr(m.p) + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(p.data)), + Len: int(p.length) / 8, + Cap: int(p.length) / 8, + } + return *(*[]float64)(unsafe.Pointer(h)), nil +} + +// Region returns a new Mat that points to a region of this Mat. Changes made to the +// region Mat will affect the original Mat, since they are pointers to the underlying +// OpenCV Mat object. +func (m *Mat) Region(rio image.Rectangle) Mat { + cRect := C.struct_Rect{ + x: C.int(rio.Min.X), + y: C.int(rio.Min.Y), + width: C.int(rio.Size().X), + height: C.int(rio.Size().Y), + } + + return newMat(C.Mat_Region(m.p, cRect)) +} + +// Reshape changes the shape and/or the number of channels of a 2D matrix without copying the data. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#a4eb96e3251417fa88b78e2abd6cfd7d8 +// +func (m *Mat) Reshape(cn int, rows int) Mat { + return newMat(C.Mat_Reshape(m.p, C.int(cn), C.int(rows))) +} + +// ConvertFp16 converts a Mat to half-precision floating point. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga9c25d9ef44a2a48ecc3774b30cb80082 +// +func (m *Mat) ConvertFp16() Mat { + return newMat(C.Mat_ConvertFp16(m.p)) +} + +// Mean calculates the mean value M of array elements, independently for each channel, and return it as Scalar +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga191389f8a0e58180bb13a727782cd461 +// +func (m *Mat) Mean() Scalar { + s := C.Mat_Mean(m.p) + return NewScalar(float64(s.val1), float64(s.val2), float64(s.val3), float64(s.val4)) +} + +// MeanWithMask calculates the mean value M of array elements,independently for each channel, +// and returns it as Scalar vector while applying the mask. +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga191389f8a0e58180bb13a727782cd461 +// +func (m *Mat) MeanWithMask(mask Mat) Scalar { + s := C.Mat_MeanWithMask(m.p, mask.p) + return NewScalar(float64(s.val1), float64(s.val2), float64(s.val3), float64(s.val4)) +} + +// Sqrt calculates a square root of array elements. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga186222c3919657890f88df5a1f64a7d7 +// +func (m *Mat) Sqrt() Mat { + return newMat(C.Mat_Sqrt(m.p)) +} + +// Sum calculates the per-channel pixel sum of an image. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga716e10a2dd9e228e4d3c95818f106722 +// +func (m *Mat) Sum() Scalar { + s := C.Mat_Sum(m.p) + return NewScalar(float64(s.val1), float64(s.val2), float64(s.val3), float64(s.val4)) +} + +// PatchNaNs converts NaN's to zeros. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga62286befb7cde3568ff8c7d14d5079da +// +func (m *Mat) PatchNaNs() { + C.Mat_PatchNaNs(m.p) +} + +// LUT performs a look-up table transform of an array. +// +// The function LUT fills the output array with values from the look-up table. +// Indices of the entries are taken from the input array. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gab55b8d062b7f5587720ede032d34156f +func LUT(src, wbLUT Mat, dst *Mat) { + C.LUT(src.p, wbLUT.p, dst.p) +} + +// Rows returns the number of rows for this Mat. +func (m *Mat) Rows() int { + return int(C.Mat_Rows(m.p)) +} + +// Cols returns the number of columns for this Mat. +func (m *Mat) Cols() int { + return int(C.Mat_Cols(m.p)) +} + +// Channels returns the number of channels for this Mat. +func (m *Mat) Channels() int { + return int(C.Mat_Channels(m.p)) +} + +// Type returns the type for this Mat. +func (m *Mat) Type() MatType { + return MatType(C.Mat_Type(m.p)) +} + +// Step returns the number of bytes each matrix row occupies. +func (m *Mat) Step() int { + return int(C.Mat_Step(m.p)) +} + +// ElemSize returns the matrix element size in bytes. +func (m *Mat) ElemSize() int { + return int(C.Mat_ElemSize(m.p)) +} + +// GetUCharAt returns a value from a specific row/col +// in this Mat expecting it to be of type uchar aka CV_8U. +func (m *Mat) GetUCharAt(row int, col int) uint8 { + return uint8(C.Mat_GetUChar(m.p, C.int(row), C.int(col))) +} + +// GetUCharAt3 returns a value from a specific x, y, z coordinate location +// in this Mat expecting it to be of type uchar aka CV_8U. +func (m *Mat) GetUCharAt3(x, y, z int) uint8 { + return uint8(C.Mat_GetUChar3(m.p, C.int(x), C.int(y), C.int(z))) +} + +// GetSCharAt returns a value from a specific row/col +// in this Mat expecting it to be of type schar aka CV_8S. +func (m *Mat) GetSCharAt(row int, col int) int8 { + return int8(C.Mat_GetSChar(m.p, C.int(row), C.int(col))) +} + +// GetSCharAt3 returns a value from a specific x, y, z coordinate location +// in this Mat expecting it to be of type schar aka CV_8S. +func (m *Mat) GetSCharAt3(x, y, z int) int8 { + return int8(C.Mat_GetSChar3(m.p, C.int(x), C.int(y), C.int(z))) +} + +// GetShortAt returns a value from a specific row/col +// in this Mat expecting it to be of type short aka CV_16S. +func (m *Mat) GetShortAt(row int, col int) int16 { + return int16(C.Mat_GetShort(m.p, C.int(row), C.int(col))) +} + +// GetShortAt3 returns a value from a specific x, y, z coordinate location +// in this Mat expecting it to be of type short aka CV_16S. +func (m *Mat) GetShortAt3(x, y, z int) int16 { + return int16(C.Mat_GetShort3(m.p, C.int(x), C.int(y), C.int(z))) +} + +// GetIntAt returns a value from a specific row/col +// in this Mat expecting it to be of type int aka CV_32S. +func (m *Mat) GetIntAt(row int, col int) int32 { + return int32(C.Mat_GetInt(m.p, C.int(row), C.int(col))) +} + +// GetIntAt3 returns a value from a specific x, y, z coordinate location +// in this Mat expecting it to be of type int aka CV_32S. +func (m *Mat) GetIntAt3(x, y, z int) int32 { + return int32(C.Mat_GetInt3(m.p, C.int(x), C.int(y), C.int(z))) +} + +// GetFloatAt returns a value from a specific row/col +// in this Mat expecting it to be of type float aka CV_32F. +func (m *Mat) GetFloatAt(row int, col int) float32 { + return float32(C.Mat_GetFloat(m.p, C.int(row), C.int(col))) +} + +// GetFloatAt3 returns a value from a specific x, y, z coordinate location +// in this Mat expecting it to be of type float aka CV_32F. +func (m *Mat) GetFloatAt3(x, y, z int) float32 { + return float32(C.Mat_GetFloat3(m.p, C.int(x), C.int(y), C.int(z))) +} + +// GetDoubleAt returns a value from a specific row/col +// in this Mat expecting it to be of type double aka CV_64F. +func (m *Mat) GetDoubleAt(row int, col int) float64 { + return float64(C.Mat_GetDouble(m.p, C.int(row), C.int(col))) +} + +// GetDoubleAt3 returns a value from a specific x, y, z coordinate location +// in this Mat expecting it to be of type double aka CV_64F. +func (m *Mat) GetDoubleAt3(x, y, z int) float64 { + return float64(C.Mat_GetDouble3(m.p, C.int(x), C.int(y), C.int(z))) +} + +// SetTo sets all or some of the array elements to the specified scalar value. +func (m *Mat) SetTo(s Scalar) { + sVal := C.struct_Scalar{ + val1: C.double(s.Val1), + val2: C.double(s.Val2), + val3: C.double(s.Val3), + val4: C.double(s.Val4), + } + + C.Mat_SetTo(m.p, sVal) +} + +// SetUCharAt sets a value at a specific row/col +// in this Mat expecting it to be of type uchar aka CV_8U. +func (m *Mat) SetUCharAt(row int, col int, val uint8) { + C.Mat_SetUChar(m.p, C.int(row), C.int(col), C.uint8_t(val)) +} + +// SetUCharAt3 sets a value at a specific x, y, z coordinate location +// in this Mat expecting it to be of type uchar aka CV_8U. +func (m *Mat) SetUCharAt3(x, y, z int, val uint8) { + C.Mat_SetUChar3(m.p, C.int(x), C.int(y), C.int(z), C.uint8_t(val)) +} + +// SetSCharAt sets a value at a specific row/col +// in this Mat expecting it to be of type schar aka CV_8S. +func (m *Mat) SetSCharAt(row int, col int, val int8) { + C.Mat_SetSChar(m.p, C.int(row), C.int(col), C.int8_t(val)) +} + +// SetSCharAt3 sets a value at a specific x, y, z coordinate location +// in this Mat expecting it to be of type schar aka CV_8S. +func (m *Mat) SetSCharAt3(x, y, z int, val int8) { + C.Mat_SetSChar3(m.p, C.int(x), C.int(y), C.int(z), C.int8_t(val)) +} + +// SetShortAt sets a value at a specific row/col +// in this Mat expecting it to be of type short aka CV_16S. +func (m *Mat) SetShortAt(row int, col int, val int16) { + C.Mat_SetShort(m.p, C.int(row), C.int(col), C.int16_t(val)) +} + +// SetShortAt3 sets a value at a specific x, y, z coordinate location +// in this Mat expecting it to be of type short aka CV_16S. +func (m *Mat) SetShortAt3(x, y, z int, val int16) { + C.Mat_SetShort3(m.p, C.int(x), C.int(y), C.int(z), C.int16_t(val)) +} + +// SetIntAt sets a value at a specific row/col +// in this Mat expecting it to be of type int aka CV_32S. +func (m *Mat) SetIntAt(row int, col int, val int32) { + C.Mat_SetInt(m.p, C.int(row), C.int(col), C.int32_t(val)) +} + +// SetIntAt3 sets a value at a specific x, y, z coordinate location +// in this Mat expecting it to be of type int aka CV_32S. +func (m *Mat) SetIntAt3(x, y, z int, val int32) { + C.Mat_SetInt3(m.p, C.int(x), C.int(y), C.int(z), C.int32_t(val)) +} + +// SetFloatAt sets a value at a specific row/col +// in this Mat expecting it to be of type float aka CV_32F. +func (m *Mat) SetFloatAt(row int, col int, val float32) { + C.Mat_SetFloat(m.p, C.int(row), C.int(col), C.float(val)) +} + +// SetFloatAt3 sets a value at a specific x, y, z coordinate location +// in this Mat expecting it to be of type float aka CV_32F. +func (m *Mat) SetFloatAt3(x, y, z int, val float32) { + C.Mat_SetFloat3(m.p, C.int(x), C.int(y), C.int(z), C.float(val)) +} + +// SetDoubleAt sets a value at a specific row/col +// in this Mat expecting it to be of type double aka CV_64F. +func (m *Mat) SetDoubleAt(row int, col int, val float64) { + C.Mat_SetDouble(m.p, C.int(row), C.int(col), C.double(val)) +} + +// SetDoubleAt3 sets a value at a specific x, y, z coordinate location +// in this Mat expecting it to be of type double aka CV_64F. +func (m *Mat) SetDoubleAt3(x, y, z int, val float64) { + C.Mat_SetDouble3(m.p, C.int(x), C.int(y), C.int(z), C.double(val)) +} + +// AddUChar adds a uchar value to each element in the Mat. Performs a +// mat += val operation. +func (m *Mat) AddUChar(val uint8) { + C.Mat_AddUChar(m.p, C.uint8_t(val)) +} + +// SubtractUChar subtracts a uchar value from each element in the Mat. Performs a +// mat -= val operation. +func (m *Mat) SubtractUChar(val uint8) { + C.Mat_SubtractUChar(m.p, C.uint8_t(val)) +} + +// MultiplyUChar multiplies each element in the Mat by a uint value. Performs a +// mat *= val operation. +func (m *Mat) MultiplyUChar(val uint8) { + C.Mat_MultiplyUChar(m.p, C.uint8_t(val)) +} + +// DivideUChar divides each element in the Mat by a uint value. Performs a +// mat /= val operation. +func (m *Mat) DivideUChar(val uint8) { + C.Mat_DivideUChar(m.p, C.uint8_t(val)) +} + +// AddFloat adds a float value to each element in the Mat. Performs a +// mat += val operation. +func (m *Mat) AddFloat(val float32) { + C.Mat_AddFloat(m.p, C.float(val)) +} + +// SubtractFloat subtracts a float value from each element in the Mat. Performs a +// mat -= val operation. +func (m *Mat) SubtractFloat(val float32) { + C.Mat_SubtractFloat(m.p, C.float(val)) +} + +// MultiplyFloat multiplies each element in the Mat by a float value. Performs a +// mat *= val operation. +func (m *Mat) MultiplyFloat(val float32) { + C.Mat_MultiplyFloat(m.p, C.float(val)) +} + +// DivideFloat divides each element in the Mat by a float value. Performs a +// mat /= val operation. +func (m *Mat) DivideFloat(val float32) { + C.Mat_DivideFloat(m.p, C.float(val)) +} + +// MultiplyMatrix multiplies matrix (m*x) +func (m *Mat) MultiplyMatrix(x Mat) Mat { + return newMat(C.Mat_MultiplyMatrix(m.p, x.p)) +} + +// T transpose matrix +// https://docs.opencv.org/4.1.2/d3/d63/classcv_1_1Mat.html#aaa428c60ccb6d8ea5de18f63dfac8e11 +func (m *Mat) T() Mat { + return newMat(C.Mat_T(m.p)) +} + +// AbsDiff calculates the per-element absolute difference between two arrays +// or between an array and a scalar. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6fef31bc8c4071cbc114a758a2b79c14 +// +func AbsDiff(src1, src2 Mat, dst *Mat) { + C.Mat_AbsDiff(src1.p, src2.p, dst.p) +} + +// Add calculates the per-element sum of two arrays or an array and a scalar. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga10ac1bfb180e2cfda1701d06c24fdbd6 +// +func Add(src1, src2 Mat, dst *Mat) { + C.Mat_Add(src1.p, src2.p, dst.p) +} + +// AddWeighted calculates the weighted sum of two arrays. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gafafb2513349db3bcff51f54ee5592a19 +// +func AddWeighted(src1 Mat, alpha float64, src2 Mat, beta float64, gamma float64, dst *Mat) { + C.Mat_AddWeighted(src1.p, C.double(alpha), + src2.p, C.double(beta), C.double(gamma), dst.p) +} + +// BitwiseAnd computes bitwise conjunction of the two arrays (dst = src1 & src2). +// Calculates the per-element bit-wise conjunction of two arrays +// or an array and a scalar. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga60b4d04b251ba5eb1392c34425497e14 +// +func BitwiseAnd(src1 Mat, src2 Mat, dst *Mat) { + C.Mat_BitwiseAnd(src1.p, src2.p, dst.p) +} + +// BitwiseAndWithMask computes bitwise conjunction of the two arrays (dst = src1 & src2). +// Calculates the per-element bit-wise conjunction of two arrays +// or an array and a scalar. It has an additional parameter for a mask. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga60b4d04b251ba5eb1392c34425497e14 +// +func BitwiseAndWithMask(src1 Mat, src2 Mat, dst *Mat, mask Mat) { + C.Mat_BitwiseAndWithMask(src1.p, src2.p, dst.p, mask.p) +} + +// BitwiseNot inverts every bit of an array. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga0002cf8b418479f4cb49a75442baee2f +// +func BitwiseNot(src1 Mat, dst *Mat) { + C.Mat_BitwiseNot(src1.p, dst.p) +} + +// BitwiseNotWithMask inverts every bit of an array. It has an additional parameter for a mask. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga0002cf8b418479f4cb49a75442baee2f +// +func BitwiseNotWithMask(src1 Mat, dst *Mat, mask Mat) { + C.Mat_BitwiseNotWithMask(src1.p, dst.p, mask.p) +} + +// BitwiseOr calculates the per-element bit-wise disjunction of two arrays +// or an array and a scalar. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gab85523db362a4e26ff0c703793a719b4 +// +func BitwiseOr(src1 Mat, src2 Mat, dst *Mat) { + C.Mat_BitwiseOr(src1.p, src2.p, dst.p) +} + +// BitwiseOrWithMask calculates the per-element bit-wise disjunction of two arrays +// or an array and a scalar. It has an additional parameter for a mask. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gab85523db362a4e26ff0c703793a719b4 +// +func BitwiseOrWithMask(src1 Mat, src2 Mat, dst *Mat, mask Mat) { + C.Mat_BitwiseOrWithMask(src1.p, src2.p, dst.p, mask.p) +} + +// BitwiseXor calculates the per-element bit-wise "exclusive or" operation +// on two arrays or an array and a scalar. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga84b2d8188ce506593dcc3f8cd00e8e2c +// +func BitwiseXor(src1 Mat, src2 Mat, dst *Mat) { + C.Mat_BitwiseXor(src1.p, src2.p, dst.p) +} + +// BitwiseXorWithMask calculates the per-element bit-wise "exclusive or" operation +// on two arrays or an array and a scalar. It has an additional parameter for a mask. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga84b2d8188ce506593dcc3f8cd00e8e2c +// +func BitwiseXorWithMask(src1 Mat, src2 Mat, dst *Mat, mask Mat) { + C.Mat_BitwiseXorWithMask(src1.p, src2.p, dst.p, mask.p) +} + +// BatchDistance is a naive nearest neighbor finder. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga4ba778a1c57f83233b1d851c83f5a622 +// +func BatchDistance(src1 Mat, src2 Mat, dist Mat, dtype MatType, nidx Mat, normType NormType, K int, mask Mat, update int, crosscheck bool) { + C.Mat_BatchDistance(src1.p, src2.p, dist.p, C.int(dtype), nidx.p, C.int(normType), C.int(K), mask.p, C.int(update), C.bool(crosscheck)) +} + +// BorderInterpolate computes the source location of an extrapolated pixel. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga247f571aa6244827d3d798f13892da58 +// +func BorderInterpolate(p int, len int, borderType CovarFlags) int { + ret := C.Mat_BorderInterpolate(C.int(p), C.int(len), C.int(borderType)) + return int(ret) +} + +// CovarFlags are the covariation flags used by functions such as BorderInterpolate. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/de1/group__core.html#ga719ebd4a73f30f4fab258ab7616d0f0f +// +type CovarFlags int + +const ( + // CovarScrambled indicates to scramble the results. + CovarScrambled CovarFlags = 0 + + // CovarNormal indicates to use normal covariation. + CovarNormal CovarFlags = 1 + + // CovarUseAvg indicates to use average covariation. + CovarUseAvg CovarFlags = 2 + + // CovarScale indicates to use scaled covariation. + CovarScale CovarFlags = 4 + + // CovarRows indicates to use covariation on rows. + CovarRows CovarFlags = 8 + + // CovarCols indicates to use covariation on columns. + CovarCols CovarFlags = 16 +) + +// CalcCovarMatrix calculates the covariance matrix of a set of vectors. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga017122d912af19d7d0d2cccc2d63819f +// +func CalcCovarMatrix(samples Mat, covar *Mat, mean *Mat, flags CovarFlags, ctype MatType) { + C.Mat_CalcCovarMatrix(samples.p, covar.p, mean.p, C.int(flags), C.int(ctype)) +} + +// CartToPolar calculates the magnitude and angle of 2D vectors. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gac5f92f48ec32cacf5275969c33ee837d +// +func CartToPolar(x Mat, y Mat, magnitude *Mat, angle *Mat, angleInDegrees bool) { + C.Mat_CartToPolar(x.p, y.p, magnitude.p, angle.p, C.bool(angleInDegrees)) +} + +// CheckRange checks every element of an input array for invalid values. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga2bd19d89cae59361416736f87e3c7a64 +// +func CheckRange(src Mat) bool { + return bool(C.Mat_CheckRange(src.p)) +} + +// Compare performs the per-element comparison of two arrays +// or an array and scalar value. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga303cfb72acf8cbb36d884650c09a3a97 +// +func Compare(src1 Mat, src2 Mat, dst *Mat, ct CompareType) { + C.Mat_Compare(src1.p, src2.p, dst.p, C.int(ct)) +} + +// CountNonZero counts non-zero array elements. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaa4b89393263bb4d604e0fe5986723914 +// +func CountNonZero(src Mat) int { + return int(C.Mat_CountNonZero(src.p)) +} + +// CompleteSymm copies the lower or the upper half of a square matrix to its another half. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaa9d88dcd0e54b6d1af38d41f2a3e3d25 +// +func CompleteSymm(m Mat, lowerToUpper bool) { + C.Mat_CompleteSymm(m.p, C.bool(lowerToUpper)) +} + +// ConvertScaleAbs scales, calculates absolute values, and converts the result to 8-bit. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga3460e9c9f37b563ab9dd550c4d8c4e7d +// +func ConvertScaleAbs(src Mat, dst *Mat, alpha float64, beta float64) { + C.Mat_ConvertScaleAbs(src.p, dst.p, C.double(alpha), C.double(beta)) +} + +// CopyMakeBorder forms a border around an image (applies padding). +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga2ac1049c2c3dd25c2b41bffe17658a36 +// +func CopyMakeBorder(src Mat, dst *Mat, top int, bottom int, left int, right int, bt BorderType, value color.RGBA) { + + cValue := C.struct_Scalar{ + val1: C.double(value.B), + val2: C.double(value.G), + val3: C.double(value.R), + val4: C.double(value.A), + } + + C.Mat_CopyMakeBorder(src.p, dst.p, C.int(top), C.int(bottom), C.int(left), C.int(right), C.int(bt), cValue) +} + +// DftFlags represents a DFT or DCT flag. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaf4dde112b483b38175621befedda1f1c +// +type DftFlags int + +const ( + // DftForward performs forward 1D or 2D dft or dct. + DftForward DftFlags = 0 + + // DftInverse performs an inverse 1D or 2D transform. + DftInverse DftFlags = 1 + + // DftScale scales the result: divide it by the number of array elements. Normally, it is combined with DFT_INVERSE. + DftScale DftFlags = 2 + + // DftRows performs a forward or inverse transform of every individual row of the input matrix. + DftRows DftFlags = 4 + + // DftComplexOutput performs a forward transformation of 1D or 2D real array; the result, though being a complex array, has complex-conjugate symmetry + DftComplexOutput DftFlags = 16 + + // DftRealOutput performs an inverse transformation of a 1D or 2D complex array; the result is normally a complex array of the same size, + // however, if the input array has conjugate-complex symmetry (for example, it is a result of forward transformation with DFT_COMPLEX_OUTPUT flag), + // the output is a real array. + DftRealOutput DftFlags = 32 + + // DftComplexInput specifies that input is complex input. If this flag is set, the input must have 2 channels. + DftComplexInput DftFlags = 64 + + // DctInverse performs an inverse 1D or 2D dct transform. + DctInverse = DftInverse + + // DctRows performs a forward or inverse dct transform of every individual row of the input matrix. + DctRows = DftRows +) + +// DCT performs a forward or inverse discrete Cosine transform of 1D or 2D array. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga85aad4d668c01fbd64825f589e3696d4 +// +func DCT(src Mat, dst *Mat, flags DftFlags) { + C.Mat_DCT(src.p, dst.p, C.int(flags)) +} + +// Determinant returns the determinant of a square floating-point matrix. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaf802bd9ca3e07b8b6170645ef0611d0c +// +func Determinant(src Mat) float64 { + return float64(C.Mat_Determinant(src.p)) +} + +// DFT performs a forward or inverse Discrete Fourier Transform (DFT) +// of a 1D or 2D floating-point array. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gadd6cf9baf2b8b704a11b5f04aaf4f39d +// +func DFT(src Mat, dst *Mat, flags DftFlags) { + C.Mat_DFT(src.p, dst.p, C.int(flags)) +} + +// Divide performs the per-element division +// on two arrays or an array and a scalar. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6db555d30115642fedae0cda05604874 +// +func Divide(src1 Mat, src2 Mat, dst *Mat) { + C.Mat_Divide(src1.p, src2.p, dst.p) +} + +// Eigen calculates eigenvalues and eigenvectors of a symmetric matrix. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga9fa0d58657f60eaa6c71f6fbb40456e3 +// +func Eigen(src Mat, eigenvalues *Mat, eigenvectors *Mat) bool { + ret := C.Mat_Eigen(src.p, eigenvalues.p, eigenvectors.p) + return bool(ret) +} + +// EigenNonSymmetric calculates eigenvalues and eigenvectors of a non-symmetric matrix (real eigenvalues only). +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaf51987e03cac8d171fbd2b327cf966f6 +// +func EigenNonSymmetric(src Mat, eigenvalues *Mat, eigenvectors *Mat) { + C.Mat_EigenNonSymmetric(src.p, eigenvalues.p, eigenvectors.p) +} + +// Exp calculates the exponent of every array element. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga3e10108e2162c338f1b848af619f39e5 +// +func Exp(src Mat, dst *Mat) { + C.Mat_Exp(src.p, dst.p) +} + +// ExtractChannel extracts a single channel from src (coi is 0-based index). +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gacc6158574aa1f0281878c955bcf35642 +// +func ExtractChannel(src Mat, dst *Mat, coi int) { + C.Mat_ExtractChannel(src.p, dst.p, C.int(coi)) +} + +// FindNonZero returns the list of locations of non-zero pixels. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaed7df59a3539b4cc0fe5c9c8d7586190 +// +func FindNonZero(src Mat, idx *Mat) { + C.Mat_FindNonZero(src.p, idx.p) +} + +// Flip flips a 2D array around horizontal(0), vertical(1), or both axes(-1). +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaca7be533e3dac7feb70fc60635adf441 +// +func Flip(src Mat, dst *Mat, flipCode int) { + C.Mat_Flip(src.p, dst.p, C.int(flipCode)) +} + +// Gemm performs generalized matrix multiplication. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gacb6e64071dffe36434e1e7ee79e7cb35 +// +func Gemm(src1, src2 Mat, alpha float64, src3 Mat, beta float64, dst *Mat, flags int) { + C.Mat_Gemm(src1.p, src2.p, C.double(alpha), src3.p, C.double(beta), dst.p, C.int(flags)) +} + +// GetOptimalDFTSize returns the optimal Discrete Fourier Transform (DFT) size +// for a given vector size. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6577a2e59968936ae02eb2edde5de299 +// +func GetOptimalDFTSize(vecsize int) int { + return int(C.Mat_GetOptimalDFTSize(C.int(vecsize))) +} + +// Hconcat applies horizontal concatenation to given matrices. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaab5ceee39e0580f879df645a872c6bf7 +// +func Hconcat(src1, src2 Mat, dst *Mat) { + C.Mat_Hconcat(src1.p, src2.p, dst.p) +} + +// Vconcat applies vertical concatenation to given matrices. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaab5ceee39e0580f879df645a872c6bf7 +// +func Vconcat(src1, src2 Mat, dst *Mat) { + C.Mat_Vconcat(src1.p, src2.p, dst.p) +} + +// RotateFlag for image rotation +// +// +// For further details please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6f45d55c0b1cc9d97f5353a7c8a7aac2 +type RotateFlag int + +const ( + // Rotate90Clockwise allows to rotate image 90 degrees clockwise + Rotate90Clockwise RotateFlag = 0 + // Rotate180Clockwise allows to rotate image 180 degrees clockwise + Rotate180Clockwise RotateFlag = 1 + // Rotate90CounterClockwise allows to rotate 270 degrees clockwise + Rotate90CounterClockwise RotateFlag = 2 +) + +// Rotate rotates a 2D array in multiples of 90 degrees +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga4ad01c0978b0ce64baa246811deeac24 +func Rotate(src Mat, dst *Mat, code RotateFlag) { + C.Rotate(src.p, dst.p, C.int(code)) +} + +// IDCT calculates the inverse Discrete Cosine Transform of a 1D or 2D array. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga77b168d84e564c50228b69730a227ef2 +// +func IDCT(src Mat, dst *Mat, flags int) { + C.Mat_Idct(src.p, dst.p, C.int(flags)) +} + +// IDFT calculates the inverse Discrete Fourier Transform of a 1D or 2D array. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaa708aa2d2e57a508f968eb0f69aa5ff1 +// +func IDFT(src Mat, dst *Mat, flags, nonzeroRows int) { + C.Mat_Idft(src.p, dst.p, C.int(flags), C.int(nonzeroRows)) +} + +// InRange checks if array elements lie between the elements of two Mat arrays. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga48af0ab51e36436c5d04340e036ce981 +// +func InRange(src, lb, ub Mat, dst *Mat) { + C.Mat_InRange(src.p, lb.p, ub.p, dst.p) +} + +// InRangeWithScalar checks if array elements lie between the elements of two Scalars +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga48af0ab51e36436c5d04340e036ce981 +// +func InRangeWithScalar(src Mat, lb, ub Scalar, dst *Mat) { + lbVal := C.struct_Scalar{ + val1: C.double(lb.Val1), + val2: C.double(lb.Val2), + val3: C.double(lb.Val3), + val4: C.double(lb.Val4), + } + + ubVal := C.struct_Scalar{ + val1: C.double(ub.Val1), + val2: C.double(ub.Val2), + val3: C.double(ub.Val3), + val4: C.double(ub.Val4), + } + + C.Mat_InRangeWithScalar(src.p, lbVal, ubVal, dst.p) +} + +// InsertChannel inserts a single channel to dst (coi is 0-based index) +// (it replaces channel i with another in dst). +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga1d4bd886d35b00ec0b764cb4ce6eb515 +// +func InsertChannel(src Mat, dst *Mat, coi int) { + C.Mat_InsertChannel(src.p, dst.p, C.int(coi)) +} + +// Invert finds the inverse or pseudo-inverse of a matrix. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gad278044679d4ecf20f7622cc151aaaa2 +// +func Invert(src Mat, dst *Mat, flags SolveDecompositionFlags) float64 { + ret := C.Mat_Invert(src.p, dst.p, C.int(flags)) + return float64(ret) +} + +// KMeansFlags for kmeans center selection +// +// For further details, please see: +// https://docs.opencv.org/master/d0/de1/group__core.html#ga276000efe55ee2756e0c471c7b270949 +type KMeansFlags int + +const ( + // KMeansRandomCenters selects random initial centers in each attempt. + KMeansRandomCenters KMeansFlags = 0 + // KMeansPPCenters uses kmeans++ center initialization by Arthur and Vassilvitskii [Arthur2007]. + KMeansPPCenters KMeansFlags = 1 + // KMeansUseInitialLabels uses the user-supplied lables during the first (and possibly the only) attempt + // instead of computing them from the initial centers. For the second and further attempts, use the random or semi-random // centers. Use one of KMEANS_*_CENTERS flag to specify the exact method. + KMeansUseInitialLabels KMeansFlags = 2 +) + +// KMeans finds centers of clusters and groups input samples around the clusters. +// +// For further details, please see: +// https://docs.opencv.org/master/d5/d38/group__core__cluster.html#ga9a34dc06c6ec9460e90860f15bcd2f88 +// +func KMeans(data Mat, k int, bestLabels *Mat, criteria TermCriteria, attempts int, flags KMeansFlags, centers *Mat) float64 { + ret := C.KMeans(data.p, C.int(k), bestLabels.p, criteria.p, C.int(attempts), C.int(flags), centers.p) + return float64(ret) +} + +// KMeansPoints finds centers of clusters and groups input samples around the clusters. +// +// For further details, please see: +// https://docs.opencv.org/master/d5/d38/group__core__cluster.html#ga9a34dc06c6ec9460e90860f15bcd2f88 +// +func KMeansPoints(points PointVector, k int, bestLabels *Mat, criteria TermCriteria, attempts int, flags KMeansFlags, centers *Mat) float64 { + ret := C.KMeansPoints(points.p, C.int(k), bestLabels.p, criteria.p, C.int(attempts), C.int(flags), centers.p) + return float64(ret) +} + +// Log calculates the natural logarithm of every array element. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga937ecdce4679a77168730830a955bea7 +// +func Log(src Mat, dst *Mat) { + C.Mat_Log(src.p, dst.p) +} + +// Magnitude calculates the magnitude of 2D vectors. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6d3b097586bca4409873d64a90fe64c3 +// +func Magnitude(x, y Mat, magnitude *Mat) { + C.Mat_Magnitude(x.p, y.p, magnitude.p) +} + +// Max calculates per-element maximum of two arrays or an array and a scalar. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gacc40fa15eac0fb83f8ca70b7cc0b588d +// +func Max(src1, src2 Mat, dst *Mat) { + C.Mat_Max(src1.p, src2.p, dst.p) +} + +// MeanStdDev calculates a mean and standard deviation of array elements. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga846c858f4004d59493d7c6a4354b301d +// +func MeanStdDev(src Mat, dst *Mat, dstStdDev *Mat) { + C.Mat_MeanStdDev(src.p, dst.p, dstStdDev.p) +} + +// Merge creates one multi-channel array out of several single-channel ones. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga7d7b4d6c6ee504b30a20b1680029c7b4 +// +func Merge(mv []Mat, dst *Mat) { + cMatArray := make([]C.Mat, len(mv)) + for i, r := range mv { + cMatArray[i] = r.p + } + cMats := C.struct_Mats{ + mats: (*C.Mat)(&cMatArray[0]), + length: C.int(len(mv)), + } + + C.Mat_Merge(cMats, dst.p) +} + +// Min calculates per-element minimum of two arrays or an array and a scalar. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga9af368f182ee76d0463d0d8d5330b764 +// +func Min(src1, src2 Mat, dst *Mat) { + C.Mat_Min(src1.p, src2.p, dst.p) +} + +// MinMaxIdx finds the global minimum and maximum in an array. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga7622c466c628a75d9ed008b42250a73f +// +func MinMaxIdx(input Mat) (minVal, maxVal float32, minIdx, maxIdx int) { + var cMinVal C.double + var cMaxVal C.double + var cMinIdx C.int + var cMaxIdx C.int + + C.Mat_MinMaxIdx(input.p, &cMinVal, &cMaxVal, &cMinIdx, &cMaxIdx) + + return float32(cMinVal), float32(cMaxVal), int(minIdx), int(maxIdx) +} + +// MinMaxLoc finds the global minimum and maximum in an array. +// +// For further details, please see: +// https://docs.opencv.org/trunk/d2/de8/group__core__array.html#gab473bf2eb6d14ff97e89b355dac20707 +// +func MinMaxLoc(input Mat) (minVal, maxVal float32, minLoc, maxLoc image.Point) { + var cMinVal C.double + var cMaxVal C.double + var cMinLoc C.struct_Point + var cMaxLoc C.struct_Point + + C.Mat_MinMaxLoc(input.p, &cMinVal, &cMaxVal, &cMinLoc, &cMaxLoc) + + minLoc = image.Pt(int(cMinLoc.x), int(cMinLoc.y)) + maxLoc = image.Pt(int(cMaxLoc.x), int(cMaxLoc.y)) + + return float32(cMinVal), float32(cMaxVal), minLoc, maxLoc +} + +// Copies specified channels from input arrays to the specified channels of output arrays. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga51d768c270a1cdd3497255017c4504be +// +func MixChannels(src []Mat, dst []Mat, fromTo []int) { + cSrcArray := make([]C.Mat, len(src)) + for i, r := range src { + cSrcArray[i] = r.p + } + cSrcMats := C.struct_Mats{ + mats: (*C.Mat)(&cSrcArray[0]), + length: C.int(len(src)), + } + + cDstArray := make([]C.Mat, len(dst)) + for i, r := range dst { + cDstArray[i] = r.p + } + cDstMats := C.struct_Mats{ + mats: (*C.Mat)(&cDstArray[0]), + length: C.int(len(dst)), + } + + cFromToArray := make([]C.int, len(fromTo)) + for i, ft := range fromTo { + cFromToArray[i] = C.int(ft) + } + + cFromToIntVector := C.IntVector{ + val: (*C.int)(&cFromToArray[0]), + length: C.int(len(fromTo)), + } + + C.Mat_MixChannels(cSrcMats, cDstMats, cFromToIntVector) + + for i := C.int(0); i < cDstMats.length; i++ { + dst[i].p = C.Mats_get(cDstMats, i) + } +} + +//Mulspectrums performs the per-element multiplication of two Fourier spectrums. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga3ab38646463c59bf0ce962a9d51db64f +// +func MulSpectrums(a Mat, b Mat, dst *Mat, flags DftFlags) { + C.Mat_MulSpectrums(a.p, b.p, dst.p, C.int(flags)) +} + +// Multiply calculates the per-element scaled product of two arrays. +// Both input arrays must be of the same size and the same type. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga979d898a58d7f61c53003e162e7ad89f +// +func Multiply(src1 Mat, src2 Mat, dst *Mat) { + C.Mat_Multiply(src1.p, src2.p, dst.p) +} + +// MultiplyWithParams calculates the per-element scaled product of two arrays. +// Both input arrays must be of the same size and the same type. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga979d898a58d7f61c53003e162e7ad89f +// +func MultiplyWithParams(src1 Mat, src2 Mat, dst *Mat, scale float64, dtype MatType) { + C.Mat_MultiplyWithParams(src1.p, src2.p, dst.p, C.double(scale), C.int(dtype)) +} + +// NormType for normalization operations. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gad12cefbcb5291cf958a85b4b67b6149f +// +type NormType int + +const ( + // NormInf indicates use infinite normalization. + NormInf NormType = 1 + + // NormL1 indicates use L1 normalization. + NormL1 NormType = 2 + + // NormL2 indicates use L2 normalization. + NormL2 NormType = 4 + + // NormL2Sqr indicates use L2 squared normalization. + NormL2Sqr NormType = 5 + + // NormHamming indicates use Hamming normalization. + NormHamming NormType = 6 + + // NormHamming2 indicates use Hamming 2-bit normalization. + NormHamming2 NormType = 7 + + // NormTypeMask indicates use type mask for normalization. + NormTypeMask NormType = 7 + + // NormRelative indicates use relative normalization. + NormRelative NormType = 8 + + // NormMinMax indicates use min/max normalization. + NormMinMax NormType = 32 +) + +// Normalize normalizes the norm or value range of an array. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga87eef7ee3970f86906d69a92cbf064bd +// +func Normalize(src Mat, dst *Mat, alpha float64, beta float64, typ NormType) { + C.Mat_Normalize(src.p, dst.p, C.double(alpha), C.double(beta), C.int(typ)) +} + +// Norm calculates the absolute norm of an array. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga7c331fb8dd951707e184ef4e3f21dd33 +// +func Norm(src1 Mat, normType NormType) float64 { + return float64(C.Norm(src1.p, C.int(normType))) +} + +// Norm calculates the absolute difference/relative norm of two arrays. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga7c331fb8dd951707e184ef4e3f21dd33 +// +func NormWithMats(src1 Mat, src2 Mat, normType NormType) float64 { + return float64(C.NormWithMats(src1.p, src2.p, C.int(normType))) +} + +// PerspectiveTransform performs the perspective matrix transformation of vectors. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gad327659ac03e5fd6894b90025e6900a7 +// +func PerspectiveTransform(src Mat, dst *Mat, tm Mat) { + C.Mat_PerspectiveTransform(src.p, dst.p, tm.p) +} + +// TermCriteriaType for TermCriteria. +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d5d/classcv_1_1TermCriteria.html#a56fecdc291ccaba8aad27d67ccf72c57 +// +type TermCriteriaType int + +const ( + // Count is the maximum number of iterations or elements to compute. + Count TermCriteriaType = 1 + + // MaxIter is the maximum number of iterations or elements to compute. + MaxIter TermCriteriaType = 1 + + // EPS is the desired accuracy or change in parameters at which the + // iterative algorithm stops. + EPS TermCriteriaType = 2 +) + +type SolveDecompositionFlags int + +const ( + // Gaussian elimination with the optimal pivot element chosen. + SolveDecompositionLu SolveDecompositionFlags = 0 + + // Singular value decomposition (SVD) method. The system can be over-defined and/or the matrix src1 can be singular. + SolveDecompositionSvd SolveDecompositionFlags = 1 + + // Eigenvalue decomposition. The matrix src1 must be symmetrical. + SolveDecompositionEing SolveDecompositionFlags = 2 + + // Cholesky LL^T factorization. The matrix src1 must be symmetrical and positively defined. + SolveDecompositionCholesky SolveDecompositionFlags = 3 + + // QR factorization. The system can be over-defined and/or the matrix src1 can be singular. + SolveDecompositionQr SolveDecompositionFlags = 4 + + // While all the previous flags are mutually exclusive, this flag can be used together with any of the previous. + // It means that the normal equations 𝚜𝚛𝚌𝟷^T⋅𝚜𝚛𝚌𝟷⋅𝚍𝚜𝚝=𝚜𝚛𝚌𝟷^T𝚜𝚛𝚌𝟸 are solved instead of the original system + // 𝚜𝚛𝚌𝟷⋅𝚍𝚜𝚝=𝚜𝚛𝚌𝟸. + SolveDecompositionNormal SolveDecompositionFlags = 5 +) + +// Solve solves one or more linear systems or least-squares problems. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga12b43690dbd31fed96f213eefead2373 +// +func Solve(src1 Mat, src2 Mat, dst *Mat, flags SolveDecompositionFlags) bool { + return bool(C.Mat_Solve(src1.p, src2.p, dst.p, C.int(flags))) +} + +// SolveCubic finds the real roots of a cubic equation. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga1c3b0b925b085b6e96931ee309e6a1da +// +func SolveCubic(coeffs Mat, roots *Mat) int { + return int(C.Mat_SolveCubic(coeffs.p, roots.p)) +} + +// SolvePoly finds the real or complex roots of a polynomial equation. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gac2f5e953016fabcdf793d762f4ec5dce +// +func SolvePoly(coeffs Mat, roots *Mat, maxIters int) float64 { + return float64(C.Mat_SolvePoly(coeffs.p, roots.p, C.int(maxIters))) +} + +type ReduceTypes int + +const ( + // The output is the sum of all rows/columns of the matrix. + ReduceSum ReduceTypes = 0 + + // The output is the mean vector of all rows/columns of the matrix. + ReduceAvg ReduceTypes = 1 + + // The output is the maximum (column/row-wise) of all rows/columns of the matrix. + ReduceMax ReduceTypes = 2 + + // The output is the minimum (column/row-wise) of all rows/columns of the matrix. + ReduceMin ReduceTypes = 3 +) + +// Reduce reduces a matrix to a vector. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga4b78072a303f29d9031d56e5638da78e +// +func Reduce(src Mat, dst *Mat, dim int, rType ReduceTypes, dType MatType) { + C.Mat_Reduce(src.p, dst.p, C.int(dim), C.int(rType), C.int(dType)) +} + +// Finds indices of max elements along provided axis. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaa87ea34d99bcc5bf9695048355163da0 +// +func ReduceArgMax(src Mat, dst *Mat, axis int, lastIndex bool) { + C.Mat_ReduceArgMax(src.p, dst.p, C.int(axis), C.bool(lastIndex)) +} + +// Finds indices of min elements along provided axis. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaeecd548276bfb91b938989e66b722088 +// +func ReduceArgMin(src Mat, dst *Mat, axis int, lastIndex bool) { + C.Mat_ReduceArgMin(src.p, dst.p, C.int(axis), C.bool(lastIndex)) +} + +// Repeat fills the output array with repeated copies of the input array. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga496c3860f3ac44c40b48811333cfda2d +// +func Repeat(src Mat, nY int, nX int, dst *Mat) { + C.Mat_Repeat(src.p, C.int(nY), C.int(nX), dst.p) +} + +// Calculates the sum of a scaled array and another array. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga9e0845db4135f55dcf20227402f00d98 +// +func ScaleAdd(src1 Mat, alpha float64, src2 Mat, dst *Mat) { + C.Mat_ScaleAdd(src1.p, C.double(alpha), src2.p, dst.p) +} + +// SetIdentity initializes a scaled identity matrix. +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga388d7575224a4a277ceb98ccaa327c99 +// +func SetIdentity(src Mat, scalar float64) { + C.Mat_SetIdentity(src.p, C.double(scalar)) +} + +type SortFlags int + +const ( + // Each matrix row is sorted independently + SortEveryRow SortFlags = 0 + + // Each matrix column is sorted independently; this flag and the previous one are mutually exclusive. + SortEveryColumn SortFlags = 1 + + // Each matrix row is sorted in the ascending order. + SortAscending SortFlags = 0 + + // Each matrix row is sorted in the descending order; this flag and the previous one are also mutually exclusive. + SortDescending SortFlags = 16 +) + +// Sort sorts each row or each column of a matrix. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga45dd56da289494ce874be2324856898f +// +func Sort(src Mat, dst *Mat, flags SortFlags) { + C.Mat_Sort(src.p, dst.p, C.int(flags)) +} + +// SortIdx sorts each row or each column of a matrix. +// Instead of reordering the elements themselves, it stores the indices of sorted elements in the output array +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gadf35157cbf97f3cb85a545380e383506 +// +func SortIdx(src Mat, dst *Mat, flags SortFlags) { + C.Mat_SortIdx(src.p, dst.p, C.int(flags)) +} + +// Split creates an array of single channel images from a multi-channel image +// Created images should be closed manualy to avoid memory leaks. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga0547c7fed86152d7e9d0096029c8518a +// +func Split(src Mat) (mv []Mat) { + cMats := C.struct_Mats{} + C.Mat_Split(src.p, &(cMats)) + defer C.Mats_Close(cMats) + mv = make([]Mat, cMats.length) + for i := C.int(0); i < cMats.length; i++ { + mv[i].p = C.Mats_get(cMats, i) + addMatToProfile(mv[i].p) + } + return +} + +// Subtract calculates the per-element subtraction of two arrays or an array and a scalar. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaa0f00d98b4b5edeaeb7b8333b2de353b +// +func Subtract(src1 Mat, src2 Mat, dst *Mat) { + C.Mat_Subtract(src1.p, src2.p, dst.p) +} + +// Trace returns the trace of a matrix. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga3419ac19c7dcd2be4bd552a23e147dd8 +// +func Trace(src Mat) Scalar { + s := C.Mat_Trace(src.p) + return NewScalar(float64(s.val1), float64(s.val2), float64(s.val3), float64(s.val4)) +} + +// Transform performs the matrix transformation of every array element. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga393164aa54bb9169ce0a8cc44e08ff22 +// +func Transform(src Mat, dst *Mat, tm Mat) { + C.Mat_Transform(src.p, dst.p, tm.p) +} + +// Transpose transposes a matrix. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga46630ed6c0ea6254a35f447289bd7404 +// +func Transpose(src Mat, dst *Mat) { + C.Mat_Transpose(src.p, dst.p) +} + +// Pow raises every array element to a power. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaf0d056b5bd1dc92500d6f6cf6bac41ef +// +func Pow(src Mat, power float64, dst *Mat) { + C.Mat_Pow(src.p, C.double(power), dst.p) +} + +// PolatToCart calculates x and y coordinates of 2D vectors from their magnitude and angle. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga581ff9d44201de2dd1b40a50db93d665 +// +func PolarToCart(magnitude Mat, degree Mat, x *Mat, y *Mat, angleInDegrees bool) { + C.Mat_PolarToCart(magnitude.p, degree.p, x.p, y.p, C.bool(angleInDegrees)) +} + +// Phase calculates the rotation angle of 2D vectors. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga9db9ca9b4d81c3bde5677b8f64dc0137 +// +func Phase(x, y Mat, angle *Mat, angleInDegrees bool) { + C.Mat_Phase(x.p, y.p, angle.p, C.bool(angleInDegrees)) +} + +// TermCriteria is the criteria for iterative algorithms. +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d5d/classcv_1_1TermCriteria.html +// +type TermCriteria struct { + p C.TermCriteria +} + +// NewTermCriteria returns a new TermCriteria. +func NewTermCriteria(typ TermCriteriaType, maxCount int, epsilon float64) TermCriteria { + return TermCriteria{p: C.TermCriteria_New(C.int(typ), C.int(maxCount), C.double(epsilon))} +} + +// Scalar is a 4-element vector widely used in OpenCV to pass pixel values. +// +// For further details, please see: +// http://docs.opencv.org/master/d1/da0/classcv_1_1Scalar__.html +// +type Scalar struct { + Val1 float64 + Val2 float64 + Val3 float64 + Val4 float64 +} + +// NewScalar returns a new Scalar. These are usually colors typically being in BGR order. +func NewScalar(v1 float64, v2 float64, v3 float64, v4 float64) Scalar { + s := Scalar{Val1: v1, Val2: v2, Val3: v3, Val4: v4} + return s +} + +// KeyPoint is data structure for salient point detectors. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/d29/classcv_1_1KeyPoint.html +// +type KeyPoint struct { + X, Y float64 + Size, Angle, Response float64 + Octave, ClassID int +} + +// DMatch is data structure for matching keypoint descriptors. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/de0/classcv_1_1DMatch.html#a546ddb9a87898f06e510e015a6de596e +// +type DMatch struct { + QueryIdx int + TrainIdx int + ImgIdx int + Distance float64 +} + +// Vecb is a generic vector of bytes. +type Vecb []uint8 + +// GetVecbAt returns a vector of bytes. Its size corresponds to the number +// of channels of the Mat. +func (m *Mat) GetVecbAt(row int, col int) Vecb { + ch := m.Channels() + v := make(Vecb, ch) + + for c := 0; c < ch; c++ { + v[c] = m.GetUCharAt(row, col*ch+c) + } + + return v +} + +// Vecf is a generic vector of floats. +type Vecf []float32 + +// GetVecfAt returns a vector of floats. Its size corresponds to the number of +// channels of the Mat. +func (m *Mat) GetVecfAt(row int, col int) Vecf { + ch := m.Channels() + v := make(Vecf, ch) + + for c := 0; c < ch; c++ { + v[c] = m.GetFloatAt(row, col*ch+c) + } + + return v +} + +// Vecd is a generic vector of float64/doubles. +type Vecd []float64 + +// GetVecdAt returns a vector of float64s. Its size corresponds to the number +// of channels of the Mat. +func (m *Mat) GetVecdAt(row int, col int) Vecd { + ch := m.Channels() + v := make(Vecd, ch) + + for c := 0; c < ch; c++ { + v[c] = m.GetDoubleAt(row, col*ch+c) + } + + return v +} + +// Veci is a generic vector of integers. +type Veci []int32 + +// GetVeciAt returns a vector of integers. Its size corresponds to the number +// of channels of the Mat. +func (m *Mat) GetVeciAt(row int, col int) Veci { + ch := m.Channels() + v := make(Veci, ch) + + for c := 0; c < ch; c++ { + v[c] = m.GetIntAt(row, col*ch+c) + } + + return v +} + +// PointVector is a wrapper around a std::vector< cv::Point >* +// This is needed anytime that you need to pass or receive a collection of points. +type PointVector struct { + p C.PointVector +} + +// NewPointVector returns a new empty PointVector. +func NewPointVector() PointVector { + return PointVector{p: C.PointVector_New()} +} + +// NewPointVectorFromPoints returns a new PointVector that has been +// initialized to a slice of image.Point. +func NewPointVectorFromPoints(pts []image.Point) PointVector { + p := (*C.struct_Point)(C.malloc(C.size_t(C.sizeof_struct_Point * len(pts)))) + defer C.free(unsafe.Pointer(p)) + + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(p)), + Len: len(pts), + Cap: len(pts), + } + pa := *(*[]C.Point)(unsafe.Pointer(h)) + + for j, point := range pts { + pa[j] = C.struct_Point{ + x: C.int(point.X), + y: C.int(point.Y), + } + } + + cpoints := C.struct_Points{ + points: (*C.Point)(p), + length: C.int(len(pts)), + } + + return PointVector{p: C.PointVector_NewFromPoints(cpoints)} +} + +// NewPointVectorFromMat returns a new PointVector that has been +// wrapped around a Mat of type CV_32SC2 with a single columm. +func NewPointVectorFromMat(mat Mat) PointVector { + return PointVector{p: C.PointVector_NewFromMat(mat.p)} +} + +// IsNil checks the CGo pointer in the PointVector. +func (pv PointVector) IsNil() bool { + return pv.p == nil +} + +// Size returns how many Point are in the PointVector. +func (pv PointVector) Size() int { + return int(C.PointVector_Size(pv.p)) +} + +// At returns the image.Point +func (pv PointVector) At(idx int) image.Point { + if idx > pv.Size() { + return image.Point{} + } + + cp := C.PointVector_At(pv.p, C.int(idx)) + return image.Pt(int(cp.x), int(cp.y)) +} + +// Append appends an image.Point at end of the PointVector. +func (pv PointVector) Append(point image.Point) { + p := C.struct_Point{ + x: C.int(point.X), + y: C.int(point.Y), + } + + C.PointVector_Append(pv.p, p) + + return +} + +// ToPoints returns a slice of image.Point for the data in this PointVector. +func (pv PointVector) ToPoints() []image.Point { + points := make([]image.Point, pv.Size()) + + for j := 0; j < pv.Size(); j++ { + points[j] = pv.At(j) + } + return points +} + +// Close closes and frees memory for this PointVector. +func (pv PointVector) Close() { + C.PointVector_Close(pv.p) +} + +// PointsVector is a wrapper around a std::vector< std::vector< cv::Point > >* +type PointsVector struct { + p C.PointsVector +} + +// NewPointsVector returns a new empty PointsVector. +func NewPointsVector() PointsVector { + return PointsVector{p: C.PointsVector_New()} +} + +// NewPointsVectorFromPoints returns a new PointsVector that has been +// initialized to a slice of slices of image.Point. +func NewPointsVectorFromPoints(pts [][]image.Point) PointsVector { + if len(pts) <= 0 { + return NewPointsVector() + } + points := make([]C.struct_Points, len(pts)) + + for i, pt := range pts { + p := (*C.struct_Point)(C.malloc(C.size_t(C.sizeof_struct_Point * len(pt)))) + defer C.free(unsafe.Pointer(p)) + + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(p)), + Len: len(pt), + Cap: len(pt), + } + pa := *(*[]C.Point)(unsafe.Pointer(h)) + + for j, point := range pt { + pa[j] = C.struct_Point{ + x: C.int(point.X), + y: C.int(point.Y), + } + } + + points[i] = C.struct_Points{ + points: (*C.Point)(p), + length: C.int(len(pt)), + } + } + + cPoints := C.struct_Contours{ + contours: (*C.struct_Points)(&points[0]), + length: C.int(len(pts)), + } + + return PointsVector{p: C.PointsVector_NewFromPoints(cPoints)} +} + +func (pvs PointsVector) P() C.PointsVector { + return pvs.p +} + +// ToPoints returns a slice of slices of image.Point for the data in this PointsVector. +func (pvs PointsVector) ToPoints() [][]image.Point { + ppoints := make([][]image.Point, pvs.Size()) + for i := 0; i < pvs.Size(); i++ { + pts := pvs.At(i) + points := make([]image.Point, pts.Size()) + + for j := 0; j < pts.Size(); j++ { + points[j] = pts.At(j) + } + ppoints[i] = points + } + + return ppoints +} + +// IsNil checks the CGo pointer in the PointsVector. +func (pvs PointsVector) IsNil() bool { + return pvs.p == nil +} + +// Size returns how many vectors of Points are in the PointsVector. +func (pvs PointsVector) Size() int { + return int(C.PointsVector_Size(pvs.p)) +} + +// At returns the PointVector at that index of the PointsVector. +func (pvs PointsVector) At(idx int) PointVector { + if idx > pvs.Size() { + return PointVector{} + } + + return PointVector{p: C.PointsVector_At(pvs.p, C.int(idx))} +} + +// Append appends a PointVector at end of the PointsVector. +func (pvs PointsVector) Append(pv PointVector) { + if !pv.IsNil() { + C.PointsVector_Append(pvs.p, pv.p) + } + + return +} + +// Close closes and frees memory for this PointsVector. +func (pvs PointsVector) Close() { + C.PointsVector_Close(pvs.p) +} + +// Point2fVector is a wrapper around a std::vector< cv::Point2f >* +// This is needed anytime that you need to pass or receive a collection of points. +type Point2fVector struct { + p C.Point2fVector +} + +// NewPoint2fVector returns a new empty Point2fVector. +func NewPoint2fVector() Point2fVector { + return Point2fVector{p: C.Point2fVector_New()} +} + +// NewPoint2fVectorFromPoints returns a new Point2fVector that has been +// initialized to a slice of image.Point. +func NewPoint2fVectorFromPoints(pts []Point2f) Point2fVector { + p := (*C.struct_Point2f)(C.malloc(C.size_t(C.sizeof_struct_Point2f * len(pts)))) + defer C.free(unsafe.Pointer(p)) + + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(p)), + Len: len(pts), + Cap: len(pts), + } + pa := *(*[]C.Point2f)(unsafe.Pointer(h)) + + for j, point := range pts { + pa[j] = C.struct_Point2f{ + x: C.float(point.X), + y: C.float(point.Y), + } + } + + cpoints := C.struct_Points2f{ + points: (*C.Point2f)(p), + length: C.int(len(pts)), + } + + return Point2fVector{p: C.Point2fVector_NewFromPoints(cpoints)} +} + +// NewPoint2fVectorFromMat returns a new Point2fVector that has been +// wrapped around a Mat of type CV_32FC2 with a single columm. +func NewPoint2fVectorFromMat(mat Mat) Point2fVector { + return Point2fVector{p: C.Point2fVector_NewFromMat(mat.p)} +} + +// IsNil checks the CGo pointer in the Point2fVector. +func (pfv Point2fVector) IsNil() bool { + return pfv.p == nil +} + +// Size returns how many Point are in the PointVector. +func (pfv Point2fVector) Size() int { + return int(C.Point2fVector_Size(pfv.p)) +} + +// At returns the image.Point +func (pfv Point2fVector) At(idx int) Point2f { + if idx > pfv.Size() { + return Point2f{} + } + + cp := C.Point2fVector_At(pfv.p, C.int(idx)) + return Point2f{float32(cp.x), float32(cp.y)} +} + +// ToPoints returns a slice of image.Point for the data in this PointVector. +func (pfv Point2fVector) ToPoints() []Point2f { + points := make([]Point2f, pfv.Size()) + + for j := 0; j < pfv.Size(); j++ { + points[j] = pfv.At(j) + } + return points +} + +// Close closes and frees memory for this Point2fVector. +func (pfv Point2fVector) Close() { + C.Point2fVector_Close(pfv.p) +} + +// GetTickCount returns the number of ticks. +// +// For further details, please see: +// https://docs.opencv.org/master/db/de0/group__core__utils.html#gae73f58000611a1af25dd36d496bf4487 +// +func GetTickCount() float64 { + return float64(C.GetCVTickCount()) +} + +// GetTickFrequency returns the number of ticks per second. +// +// For further details, please see: +// https://docs.opencv.org/master/db/de0/group__core__utils.html#ga705441a9ef01f47acdc55d87fbe5090c +// +func GetTickFrequency() float64 { + return float64(C.GetTickFrequency()) +} + +func toByteArray(b []byte) (*C.struct_ByteArray, error) { + if len(b) == 0 { + return nil, ErrEmptyByteSlice + } + return &C.struct_ByteArray{ + data: (*C.char)(unsafe.Pointer(&b[0])), + length: C.int(len(b)), + }, nil +} + +func toGoBytes(b C.struct_ByteArray) []byte { + return C.GoBytes(unsafe.Pointer(b.data), b.length) +} + +// Converts CStrings to a slice of Go strings even when the C strings are not contiguous in memory +func toGoStrings(strs C.CStrings) []string { + length := int(strs.length) + tmpslice := (*[1 << 20]*C.char)(unsafe.Pointer(strs.strs))[:length:length] + gostrings := make([]string, length) + for i, s := range tmpslice { + gostrings[i] = C.GoString(s) + } + return gostrings +} + +func toRectangles(ret C.Rects) []image.Rectangle { + cArray := ret.rects + length := int(ret.length) + hdr := reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(cArray)), + Len: length, + Cap: length, + } + s := *(*[]C.Rect)(unsafe.Pointer(&hdr)) + + rects := make([]image.Rectangle, length) + for i, r := range s { + rects[i] = image.Rect(int(r.x), int(r.y), int(r.x+r.width), int(r.y+r.height)) + } + return rects +} + +func toRect(rect C.Rect) image.Rectangle { + return image.Rect(int(rect.x), int(rect.y), int(rect.x+rect.width), int(rect.y+rect.height)) +} + +func toCPoints(points []image.Point) C.struct_Points { + cPointSlice := make([]C.struct_Point, len(points)) + for i, point := range points { + cPointSlice[i] = C.struct_Point{ + x: C.int(point.X), + y: C.int(point.Y), + } + } + + return C.struct_Points{ + points: (*C.Point)(&cPointSlice[0]), + length: C.int(len(points)), + } +} + +func toCPoints2f(points []Point2f) C.struct_Points2f { + cPointSlice := make([]C.struct_Point2f, len(points)) + for i, point := range points { + cPointSlice[i] = C.struct_Point2f{ + x: C.float(point.X), + y: C.float(point.Y), + } + } + + return C.struct_Points2f{ + points: (*C.Point2f)(&cPointSlice[0]), + length: C.int(len(points)), + } +} + +func toCStrings(strs []string) C.struct_CStrings { + cStringsSlice := make([]*C.char, len(strs)) + for i, s := range strs { + cStringsSlice[i] = C.CString(s) + } + + return C.struct_CStrings{ + strs: (**C.char)(&cStringsSlice[0]), + length: C.int(len(strs)), + } +} + +// RowRange creates a matrix header for the specified row span. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#aa6542193430356ad631a9beabc624107 +// +func (m *Mat) RowRange(start, end int) Mat { + return newMat(C.Mat_rowRange(m.p, C.int(start), C.int(end))) +} + +// ColRange creates a matrix header for the specified column span. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#aadc8f9210fe4dec50513746c246fa8d9 +// +func (m *Mat) ColRange(start, end int) Mat { + return newMat(C.Mat_colRange(m.p, C.int(start), C.int(end))) +} + +// RNG Random Number Generator. +// It encapsulates the state (currently, a 64-bit integer) and +// has methods to return scalar random values and to fill arrays +// with random values +// +// For further details, please see: +// https://docs.opencv.org/master/d1/dd6/classcv_1_1RNG.html +// +type RNG struct { + p C.RNG +} + +type RNGDistType int + +const ( + // Uniform distribution + RNGDistUniform RNGDistType = 0 + // Normal distribution + RNGDistNormal RNGDistType = 1 +) + +// TheRNG Returns the default random number generator. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga75843061d150ad6564b5447e38e57722 +// +func TheRNG() RNG { + return RNG{ + p: C.TheRNG(), + } +} + +// TheRNG Sets state of default random number generator. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga757e657c037410d9e19e819569e7de0f +// +func SetRNGSeed(seed int) { + C.SetRNGSeed(C.int(seed)) +} + +// Fill Fills arrays with random numbers. +// +// For further details, please see: +// https://docs.opencv.org/master/d1/dd6/classcv_1_1RNG.html#ad26f2b09d9868cf108e84c9814aa682d +// +func (r *RNG) Fill(mat *Mat, distType RNGDistType, a, b float64, saturateRange bool) { + C.RNG_Fill(r.p, mat.p, C.int(distType), C.double(a), C.double(b), C.bool(saturateRange)) +} + +// Gaussian Returns the next random number sampled from +// the Gaussian distribution. +// +// For further details, please see: +// https://docs.opencv.org/master/d1/dd6/classcv_1_1RNG.html#a8df8ce4dc7d15916cee743e5a884639d +// +func (r *RNG) Gaussian(sigma float64) float64 { + return float64(C.RNG_Gaussian(r.p, C.double(sigma))) +} + +// Next The method updates the state using the MWC algorithm +// and returns the next 32-bit random number. +// +// For further details, please see: +// https://docs.opencv.org/master/d1/dd6/classcv_1_1RNG.html#a8df8ce4dc7d15916cee743e5a884639d +// +func (r *RNG) Next() uint { + return uint(C.RNG_Next(r.p)) +} + +// RandN Fills the array with normally distributed random numbers. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaeff1f61e972d133a04ce3a5f81cf6808 +// +func RandN(mat *Mat, mean, stddev Scalar) { + meanVal := C.struct_Scalar{ + val1: C.double(mean.Val1), + val2: C.double(mean.Val2), + val3: C.double(mean.Val3), + val4: C.double(mean.Val4), + } + stddevVal := C.struct_Scalar{ + val1: C.double(stddev.Val1), + val2: C.double(stddev.Val2), + val3: C.double(stddev.Val3), + val4: C.double(stddev.Val4), + } + + C.RandN(mat.p, meanVal, stddevVal) +} + +// RandShuffle Shuffles the array elements randomly. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6a789c8a5cb56c6dd62506179808f763 +// +func RandShuffle(mat *Mat) { + C.RandShuffle(mat.p) +} + +// RandShuffleWithParams Shuffles the array elements randomly. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6a789c8a5cb56c6dd62506179808f763 +// +func RandShuffleWithParams(mat *Mat, iterFactor float64, rng RNG) { + C.RandShuffleWithParams(mat.p, C.double(iterFactor), rng.p) +} + +// RandU Generates a single uniformly-distributed random +// number or an array of random numbers. +// +// For further details, please see: +// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga1ba1026dca0807b27057ba6a49d258c0 +// +func RandU(mat *Mat, low, high Scalar) { + lowVal := C.struct_Scalar{ + val1: C.double(low.Val1), + val2: C.double(low.Val2), + val3: C.double(low.Val3), + val4: C.double(low.Val4), + } + highVal := C.struct_Scalar{ + val1: C.double(high.Val1), + val2: C.double(high.Val2), + val3: C.double(high.Val3), + val4: C.double(high.Val4), + } + + C.RandU(mat.p, lowVal, highVal) +} + +type NativeByteBuffer struct { + // std::vector is build of 3 pointers And this will not change ever. + stdVectorOpaq [3]uintptr +} + +func newNativeByteBuffer() *NativeByteBuffer { + buffer := &NativeByteBuffer{} + C.StdByteVectorInitialize(buffer.nativePointer()) + return buffer +} + +func (buffer *NativeByteBuffer) nativePointer() unsafe.Pointer { + return unsafe.Pointer(&buffer.stdVectorOpaq[0]) +} + +func (buffer *NativeByteBuffer) dataPointer() unsafe.Pointer { + return unsafe.Pointer(C.StdByteVectorData(buffer.nativePointer())) +} + +// GetBytes returns slice of bytes backed by native buffer +func (buffer *NativeByteBuffer) GetBytes() []byte { + var result []byte + sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&result)) + vectorLen := int(C.StdByteVectorLen(buffer.nativePointer())) + sliceHeader.Cap = vectorLen + sliceHeader.Len = vectorLen + sliceHeader.Data = uintptr(buffer.dataPointer()) + return result +} + +// Len - returns length in bytes of underlying buffer +func (buffer *NativeByteBuffer) Len() int { + return int(C.StdByteVectorLen(buffer.nativePointer())) +} + +// Close the buffer releasing all its resources +func (buffer *NativeByteBuffer) Close() { + C.StdByteVectorFree(buffer.nativePointer()) +} + +// Points2fVector is a wrapper around a std::vector< std::vector< cv::Point2f > >* +type Points2fVector struct { + p C.Points2fVector +} + +// NewPoints2fVector returns a new empty Points2fVector. +func NewPoints2fVector() Points2fVector { + return Points2fVector{p: C.Points2fVector_New()} +} + +// NewPoints2fVectorFromPoints returns a new Points2fVector that has been +// initialized to a slice of slices of Point2f. +func NewPoints2fVectorFromPoints(pts [][]Point2f) Points2fVector { + pvf := NewPoints2fVector() + for j := 0; j < len(pts); j++ { + pv := NewPoint2fVectorFromPoints(pts[j]) + pvf.Append(pv) + pv.Close() + } + return pvf +} + +func (pvs Points2fVector) P() C.Points2fVector { + return pvs.p +} + +// ToPoints returns a slice of slices of Point2f for the data in this Points2fVector. +func (pvs Points2fVector) ToPoints() [][]Point2f { + ppoints := make([][]Point2f, pvs.Size()) + for j := 0; j < pvs.Size(); j++ { + pts := pvs.At(j) + points := pts.ToPoints() + ppoints[j] = points + } + return ppoints +} + +// IsNil checks the CGo pointer in the Points2fVector. +func (pvs Points2fVector) IsNil() bool { + return pvs.p == nil +} + +// Size returns how many vectors of Points are in the Points2fVector. +func (pvs Points2fVector) Size() int { + return int(C.Points2fVector_Size(pvs.p)) +} + +// At returns the Point2fVector at that index of the Points2fVector. +func (pvs Points2fVector) At(idx int) Point2fVector { + if idx > pvs.Size() { + return Point2fVector{} + } + return Point2fVector{p: C.Points2fVector_At(pvs.p, C.int(idx))} +} + +// Append appends a Point2fVector at end of the Points2fVector. +func (pvs Points2fVector) Append(pv Point2fVector) { + if !pv.IsNil() { + C.Points2fVector_Append(pvs.p, pv.p) + } +} + +// Close closes and frees memory for this Points2fVector. +func (pvs Points2fVector) Close() { + C.Points2fVector_Close(pvs.p) +} + +type Point3f struct { + X float32 + Y float32 + Z float32 +} + +func NewPoint3f(x, y, z float32) Point3f { + return Point3f{x, y, z} +} + +// Point3fVector is a wrapper around a std::vector< cv::Point3f >* +type Point3fVector struct { + p C.Point3fVector +} + +// NewPoint3fVector returns a new empty Point3fVector. +func NewPoint3fVector() Point3fVector { + return Point3fVector{p: C.Point3fVector_New()} +} + +// NewPoint3fVectorFromPoints returns a new Point3fVector that has been +// initialized to a slice of image.Point. +func NewPoint3fVectorFromPoints(pts []Point3f) Point3fVector { + p := (*C.struct_Point3f)(C.malloc(C.size_t(C.sizeof_struct_Point3f * len(pts)))) + defer C.free(unsafe.Pointer(p)) + + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(p)), + Len: len(pts), + Cap: len(pts), + } + pa := *(*[]C.Point3f)(unsafe.Pointer(h)) + + for j, point := range pts { + pa[j] = C.struct_Point3f{ + x: C.float(point.X), + y: C.float(point.Y), + z: C.float(point.Z), + } + } + + cPoints := C.struct_Points3f{ + points: (*C.Point3f)(p), + length: C.int(len(pts)), + } + + return Point3fVector{p: C.Point3fVector_NewFromPoints(cPoints)} +} + +// NewPoint3fVectorFromMat returns a new Point3fVector that has been +// wrapped around a Mat of type CV_32FC3 with a single columm. +func NewPoint3fVectorFromMat(mat Mat) Point3fVector { + return Point3fVector{p: C.Point3fVector_NewFromMat(mat.p)} +} + +// IsNil checks the CGo pointer in the Point3fVector. +func (pfv Point3fVector) IsNil() bool { + return pfv.p == nil +} + +// Size returns how many Point are in the Point3fVector. +func (pfv Point3fVector) Size() int { + return int(C.Point3fVector_Size(pfv.p)) +} + +// At returns the Point3f +func (pfv Point3fVector) At(idx int) Point3f { + if idx > pfv.Size() { + return Point3f{} + } + cp := C.Point3fVector_At(pfv.p, C.int(idx)) + return Point3f{X: float32(cp.x), Y: float32(cp.y), Z: float32(cp.z)} +} + +func (pfv Point3fVector) Append(point Point3f) { + C.Point3fVector_Append(pfv.p, C.Point3f{ + x: C.float(point.X), + y: C.float(point.Y), + z: C.float(point.Z), + }) +} + +// ToPoints returns a slice of Point3f for the data in this Point3fVector. +func (pfv Point3fVector) ToPoints() []Point3f { + points := make([]Point3f, pfv.Size()) + for j := 0; j < pfv.Size(); j++ { + points[j] = pfv.At(j) + } + return points +} + +// Close closes and frees memory for this Point3fVector. +func (pfv Point3fVector) Close() { + C.Point3fVector_Close(pfv.p) +} + +// Points3fVector is a wrapper around a std::vector< std::vector< cv::Point3f > >* +type Points3fVector struct { + p C.Points3fVector +} + +// NewPoints3fVector returns a new empty Points3fVector. +func NewPoints3fVector() Points3fVector { + return Points3fVector{p: C.Points3fVector_New()} +} + +// NewPoints3fVectorFromPoints returns a new Points3fVector that has been +// initialized to a slice of slices of Point3f. +func NewPoints3fVectorFromPoints(pts [][]Point3f) Points3fVector { + pvf := NewPoints3fVector() + for j := 0; j < len(pts); j++ { + pv := NewPoint3fVectorFromPoints(pts[j]) + pvf.Append(pv) + pv.Close() + } + return pvf +} + +// ToPoints returns a slice of slices of Point3f for the data in this Points3fVector. +func (pvs Points3fVector) ToPoints() [][]Point3f { + ppoints := make([][]Point3f, pvs.Size()) + for j := 0; j < pvs.Size(); j++ { + pts := pvs.At(j) + points := pts.ToPoints() + ppoints[j] = points + } + return ppoints +} + +// IsNil checks the CGo pointer in the Points3fVector. +func (pvs Points3fVector) IsNil() bool { + return pvs.p == nil +} + +// Size returns how many vectors of Points are in the Points3fVector. +func (pvs Points3fVector) Size() int { + return int(C.Points3fVector_Size(pvs.p)) +} + +// At returns the Point3fVector at that index of the Points3fVector. +func (pvs Points3fVector) At(idx int) Point3fVector { + if idx > pvs.Size() { + return Point3fVector{} + } + return Point3fVector{p: C.Points3fVector_At(pvs.p, C.int(idx))} +} + +// Append appends a Point3fVector at end of the Points3fVector. +func (pvs Points3fVector) Append(pv Point3fVector) { + if !pv.IsNil() { + C.Points3fVector_Append(pvs.p, pv.p) + } +} + +// Close closes and frees memory for this Points3fVector. +func (pvs Points3fVector) Close() { + C.Points3fVector_Close(pvs.p) +} + +// Set the number of threads for OpenCV. +func SetNumThreads(n int) { + C.SetNumThreads(C.int(n)) +} + +// Get the number of threads for OpenCV. +func GetNumThreads() int { + return int(C.GetNumThreads()) +} diff --git a/vendor/gocv.io/x/gocv/core.h b/vendor/gocv.io/x/gocv/core.h new file mode 100644 index 00000000..19dc3ed5 --- /dev/null +++ b/vendor/gocv.io/x/gocv/core.h @@ -0,0 +1,524 @@ +#ifndef _OPENCV3_CORE_H_ +#define _OPENCV3_CORE_H_ + +#include +#include + +// Wrapper for std::vector +typedef struct CStrings { + const char** strs; + int length; +} CStrings; + +typedef struct ByteArray { + char* data; + int length; +} ByteArray; + +// Wrapper for std::vector +typedef struct IntVector { + int* val; + int length; +} IntVector; + +// Wrapper for std::vector +typedef struct FloatVector { + float* val; + int length; +} FloatVector; + +#ifdef __cplusplus +#include +extern "C" { +#endif + +typedef struct RawData { + int width; + int height; + struct ByteArray data; +} RawData; + +// Wrapper for an individual cv::Point2f +typedef struct Point2f { + float x; + float y; +} Point2f; + +typedef struct Point3f { + float x; + float y; + float z; +} Point3f; + +// Wrapper for an individual cv::cvPoint +typedef struct Point { + int x; + int y; +} Point; + +// Wrapper for the vector of Point structs aka std::vector +typedef struct Points { + Point* points; + int length; +} Points; + +// Wrapper for the vector of Point2f structs aka std::vector +typedef struct Points2f { + Point2f* points; + int length; +} Points2f; + +typedef struct Points3f { + Point3f *points; + int length; +} Points3f; + +// Contour is alias for Points +typedef Points Contour; + + +// Contour2f is alias for Points2f +typedef Points2f Contour2f; + +typedef struct Contours2f { + Contour2f *contours; + int length; +} Contours2f; + +// Contour3f is alias for Points3f +typedef Points3f Contour3f; + +// Wrapper for the vector of Points3f vectors aka std::vector< std::vector > +typedef struct Contours3f { + Contour3f *contours; + int length; +} Contours3f; + + +// Wrapper for the vector of Points vectors aka std::vector< std::vector > +typedef struct Contours { + Contour* contours; + int length; +} Contours; + +// Wrapper for an individual cv::cvRect +typedef struct Rect { + int x; + int y; + int width; + int height; +} Rect; + +// Wrapper for the vector of Rect struct aka std::vector +typedef struct Rects { + Rect* rects; + int length; +} Rects; + +// Wrapper for an individual cv::cvSize +typedef struct Size { + int width; + int height; +} Size; + +// Wrapper for an individual cv::RotatedRect +typedef struct RotatedRect { + Points pts; + Rect boundingRect; + Point center; + Size size; + double angle; +} RotatedRect; + +// Wrapper for an individual cv::cvScalar +typedef struct Scalar { + double val1; + double val2; + double val3; + double val4; +} Scalar; + +// Wrapper for a individual cv::KeyPoint +typedef struct KeyPoint { + double x; + double y; + double size; + double angle; + double response; + int octave; + int classID; +} KeyPoint; + +// Wrapper for the vector of KeyPoint struct aka std::vector +typedef struct KeyPoints { + KeyPoint* keypoints; + int length; +} KeyPoints; + +// Wrapper for SimpleBlobDetectorParams aka SimpleBlobDetector::Params +typedef struct SimpleBlobDetectorParams { + unsigned char blobColor; + bool filterByArea; + bool filterByCircularity; + bool filterByColor; + bool filterByConvexity; + bool filterByInertia; + float maxArea; + float maxCircularity; + float maxConvexity; + float maxInertiaRatio; + float maxThreshold; + float minArea; + float minCircularity; + float minConvexity; + float minDistBetweenBlobs; + float minInertiaRatio; + size_t minRepeatability; + float minThreshold; + float thresholdStep; +} SimpleBlobDetectorParams; + +// Wrapper for an individual cv::DMatch +typedef struct DMatch { + int queryIdx; + int trainIdx; + int imgIdx; + float distance; +} DMatch; + +// Wrapper for the vector of DMatch struct aka std::vector +typedef struct DMatches { + DMatch* dmatches; + int length; +} DMatches; + +// Wrapper for the vector vector of DMatch struct aka std::vector> +typedef struct MultiDMatches { + DMatches* dmatches; + int length; +} MultiDMatches; + +// Wrapper for an individual cv::Moment +typedef struct Moment { + double m00; + double m10; + double m01; + double m20; + double m11; + double m02; + double m30; + double m21; + double m12; + double m03; + + double mu20; + double mu11; + double mu02; + double mu30; + double mu21; + double mu12; + double mu03; + + double nu20; + double nu11; + double nu02; + double nu30; + double nu21; + double nu12; + double nu03; +} Moment; + +#ifdef __cplusplus +typedef cv::Mat* Mat; +typedef cv::TermCriteria* TermCriteria; +typedef cv::RNG* RNG; +typedef std::vector< cv::Point >* PointVector; +typedef std::vector< std::vector< cv::Point > >* PointsVector; +typedef std::vector< cv::Point2f >* Point2fVector; +typedef std::vector< std::vector< cv::Point2f> >* Points2fVector; +typedef std::vector< cv::Point3f >* Point3fVector; +typedef std::vector< std::vector< cv::Point3f > >* Points3fVector; +#else +typedef void* Mat; +typedef void* TermCriteria; +typedef void* RNG; +typedef void* PointVector; +typedef void* PointsVector; +typedef void* Point2fVector; +typedef void* Points2fVector; +typedef void* Point3fVector; +typedef void* Points3fVector; +#endif + +// Wrapper for the vector of Mat aka std::vector +typedef struct Mats { + Mat* mats; + int length; +} Mats; + +Mat Mats_get(struct Mats mats, int i); +struct DMatches MultiDMatches_get(struct MultiDMatches mds, int index); + +struct ByteArray toByteArray(const char* buf, int len); +void ByteArray_Release(struct ByteArray buf); + +void Contours_Close(struct Contours cs); +void KeyPoints_Close(struct KeyPoints ks); +void Rects_Close(struct Rects rs); +void Mats_Close(struct Mats mats); +void Point_Close(struct Point p); +void Points_Close(struct Points ps); +void DMatches_Close(struct DMatches ds); +void MultiDMatches_Close(struct MultiDMatches mds); + +Mat Mat_New(); +Mat Mat_NewWithSize(int rows, int cols, int type); +Mat Mat_NewWithSizes(struct IntVector sizes, int type); +Mat Mat_NewWithSizesFromScalar(IntVector sizes, int type, Scalar ar); +Mat Mat_NewWithSizesFromBytes(IntVector sizes, int type, struct ByteArray buf); +Mat Mat_NewFromScalar(const Scalar ar, int type); +Mat Mat_NewWithSizeFromScalar(const Scalar ar, int rows, int cols, int type); +Mat Mat_NewFromBytes(int rows, int cols, int type, struct ByteArray buf); +Mat Mat_FromPtr(Mat m, int rows, int cols, int type, int prows, int pcols); +void Mat_Close(Mat m); +int Mat_Empty(Mat m); +bool Mat_IsContinuous(Mat m); +Mat Mat_Clone(Mat m); +void Mat_CopyTo(Mat m, Mat dst); +int Mat_Total(Mat m); +void Mat_Size(Mat m, IntVector* res); +void Mat_CopyToWithMask(Mat m, Mat dst, Mat mask); +void Mat_ConvertTo(Mat m, Mat dst, int type); +void Mat_ConvertToWithParams(Mat m, Mat dst, int type, float alpha, float beta); +struct ByteArray Mat_ToBytes(Mat m); +struct ByteArray Mat_DataPtr(Mat m); +Mat Mat_Region(Mat m, Rect r); +Mat Mat_Reshape(Mat m, int cn, int rows); +void Mat_PatchNaNs(Mat m); +Mat Mat_ConvertFp16(Mat m); +Scalar Mat_Mean(Mat m); +Scalar Mat_MeanWithMask(Mat m, Mat mask); +Mat Mat_Sqrt(Mat m); +int Mat_Rows(Mat m); +int Mat_Cols(Mat m); +int Mat_Channels(Mat m); +int Mat_Type(Mat m); +int Mat_Step(Mat m); +int Mat_ElemSize(Mat m); +Mat Eye(int rows, int cols, int type); +Mat Zeros(int rows, int cols, int type); +Mat Ones(int rows, int cols, int type); + +uint8_t Mat_GetUChar(Mat m, int row, int col); +uint8_t Mat_GetUChar3(Mat m, int x, int y, int z); +int8_t Mat_GetSChar(Mat m, int row, int col); +int8_t Mat_GetSChar3(Mat m, int x, int y, int z); +int16_t Mat_GetShort(Mat m, int row, int col); +int16_t Mat_GetShort3(Mat m, int x, int y, int z); +int32_t Mat_GetInt(Mat m, int row, int col); +int32_t Mat_GetInt3(Mat m, int x, int y, int z); +float Mat_GetFloat(Mat m, int row, int col); +float Mat_GetFloat3(Mat m, int x, int y, int z); +double Mat_GetDouble(Mat m, int row, int col); +double Mat_GetDouble3(Mat m, int x, int y, int z); + +void Mat_SetTo(Mat m, Scalar value); +void Mat_SetUChar(Mat m, int row, int col, uint8_t val); +void Mat_SetUChar3(Mat m, int x, int y, int z, uint8_t val); +void Mat_SetSChar(Mat m, int row, int col, int8_t val); +void Mat_SetSChar3(Mat m, int x, int y, int z, int8_t val); +void Mat_SetShort(Mat m, int row, int col, int16_t val); +void Mat_SetShort3(Mat m, int x, int y, int z, int16_t val); +void Mat_SetInt(Mat m, int row, int col, int32_t val); +void Mat_SetInt3(Mat m, int x, int y, int z, int32_t val); +void Mat_SetFloat(Mat m, int row, int col, float val); +void Mat_SetFloat3(Mat m, int x, int y, int z, float val); +void Mat_SetDouble(Mat m, int row, int col, double val); +void Mat_SetDouble3(Mat m, int x, int y, int z, double val); + +void Mat_AddUChar(Mat m, uint8_t val); +void Mat_SubtractUChar(Mat m, uint8_t val); +void Mat_MultiplyUChar(Mat m, uint8_t val); +void Mat_DivideUChar(Mat m, uint8_t val); +void Mat_AddFloat(Mat m, float val); +void Mat_SubtractFloat(Mat m, float val); +void Mat_MultiplyFloat(Mat m, float val); +void Mat_DivideFloat(Mat m, float val); +Mat Mat_MultiplyMatrix(Mat x, Mat y); + +Mat Mat_T(Mat x); + +void LUT(Mat src, Mat lut, Mat dst); + +void Mat_AbsDiff(Mat src1, Mat src2, Mat dst); +void Mat_Add(Mat src1, Mat src2, Mat dst); +void Mat_AddWeighted(Mat src1, double alpha, Mat src2, double beta, double gamma, Mat dst); +void Mat_BitwiseAnd(Mat src1, Mat src2, Mat dst); +void Mat_BitwiseAndWithMask(Mat src1, Mat src2, Mat dst, Mat mask); +void Mat_BitwiseNot(Mat src1, Mat dst); +void Mat_BitwiseNotWithMask(Mat src1, Mat dst, Mat mask); +void Mat_BitwiseOr(Mat src1, Mat src2, Mat dst); +void Mat_BitwiseOrWithMask(Mat src1, Mat src2, Mat dst, Mat mask); +void Mat_BitwiseXor(Mat src1, Mat src2, Mat dst); +void Mat_BitwiseXorWithMask(Mat src1, Mat src2, Mat dst, Mat mask); +void Mat_Compare(Mat src1, Mat src2, Mat dst, int ct); +void Mat_BatchDistance(Mat src1, Mat src2, Mat dist, int dtype, Mat nidx, int normType, int K, + Mat mask, int update, bool crosscheck); +int Mat_BorderInterpolate(int p, int len, int borderType); +void Mat_CalcCovarMatrix(Mat samples, Mat covar, Mat mean, int flags, int ctype); +void Mat_CartToPolar(Mat x, Mat y, Mat magnitude, Mat angle, bool angleInDegrees); +bool Mat_CheckRange(Mat m); +void Mat_CompleteSymm(Mat m, bool lowerToUpper); +void Mat_ConvertScaleAbs(Mat src, Mat dst, double alpha, double beta); +void Mat_CopyMakeBorder(Mat src, Mat dst, int top, int bottom, int left, int right, int borderType, + Scalar value); +int Mat_CountNonZero(Mat src); +void Mat_DCT(Mat src, Mat dst, int flags); +double Mat_Determinant(Mat m); +void Mat_DFT(Mat m, Mat dst, int flags); +void Mat_Divide(Mat src1, Mat src2, Mat dst); +bool Mat_Eigen(Mat src, Mat eigenvalues, Mat eigenvectors); +void Mat_EigenNonSymmetric(Mat src, Mat eigenvalues, Mat eigenvectors); +void Mat_Exp(Mat src, Mat dst); +void Mat_ExtractChannel(Mat src, Mat dst, int coi); +void Mat_FindNonZero(Mat src, Mat idx); +void Mat_Flip(Mat src, Mat dst, int flipCode); +void Mat_Gemm(Mat src1, Mat src2, double alpha, Mat src3, double beta, Mat dst, int flags); +int Mat_GetOptimalDFTSize(int vecsize); +void Mat_Hconcat(Mat src1, Mat src2, Mat dst); +void Mat_Vconcat(Mat src1, Mat src2, Mat dst); +void Rotate(Mat src, Mat dst, int rotationCode); +void Mat_Idct(Mat src, Mat dst, int flags); +void Mat_Idft(Mat src, Mat dst, int flags, int nonzeroRows); +void Mat_InRange(Mat src, Mat lowerb, Mat upperb, Mat dst); +void Mat_InRangeWithScalar(Mat src, const Scalar lowerb, const Scalar upperb, Mat dst); +void Mat_InsertChannel(Mat src, Mat dst, int coi); +double Mat_Invert(Mat src, Mat dst, int flags); +double KMeans(Mat data, int k, Mat bestLabels, TermCriteria criteria, int attempts, int flags, Mat centers); +double KMeansPoints(PointVector pts, int k, Mat bestLabels, TermCriteria criteria, int attempts, int flags, Mat centers); +void Mat_Log(Mat src, Mat dst); +void Mat_Magnitude(Mat x, Mat y, Mat magnitude); +void Mat_Max(Mat src1, Mat src2, Mat dst); +void Mat_MeanStdDev(Mat src, Mat dstMean, Mat dstStdDev); +void Mat_Merge(struct Mats mats, Mat dst); +void Mat_Min(Mat src1, Mat src2, Mat dst); +void Mat_MinMaxIdx(Mat m, double* minVal, double* maxVal, int* minIdx, int* maxIdx); +void Mat_MinMaxLoc(Mat m, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc); +void Mat_MixChannels(struct Mats src, struct Mats dst, struct IntVector fromTo); +void Mat_MulSpectrums(Mat a, Mat b, Mat c, int flags); +void Mat_Multiply(Mat src1, Mat src2, Mat dst); +void Mat_MultiplyWithParams(Mat src1, Mat src2, Mat dst, double scale, int dtype); +void Mat_Subtract(Mat src1, Mat src2, Mat dst); +void Mat_Normalize(Mat src, Mat dst, double alpha, double beta, int typ); +double Norm(Mat src1, int normType); +double NormWithMats(Mat src1, Mat src2, int normType); +void Mat_PerspectiveTransform(Mat src, Mat dst, Mat tm); +bool Mat_Solve(Mat src1, Mat src2, Mat dst, int flags); +int Mat_SolveCubic(Mat coeffs, Mat roots); +double Mat_SolvePoly(Mat coeffs, Mat roots, int maxIters); +void Mat_Reduce(Mat src, Mat dst, int dim, int rType, int dType); +void Mat_ReduceArgMax(Mat src, Mat dst, int axis, bool lastIndex); +void Mat_ReduceArgMin(Mat src, Mat dst, int axis, bool lastIndex); +void Mat_Repeat(Mat src, int nY, int nX, Mat dst); +void Mat_ScaleAdd(Mat src1, double alpha, Mat src2, Mat dst); +void Mat_SetIdentity(Mat src, double scalar); +void Mat_Sort(Mat src, Mat dst, int flags); +void Mat_SortIdx(Mat src, Mat dst, int flags); +void Mat_Split(Mat src, struct Mats* mats); +void Mat_Subtract(Mat src1, Mat src2, Mat dst); +Scalar Mat_Trace(Mat src); +void Mat_Transform(Mat src, Mat dst, Mat tm); +void Mat_Transpose(Mat src, Mat dst); +void Mat_PolarToCart(Mat magnitude, Mat degree, Mat x, Mat y, bool angleInDegrees); +void Mat_Pow(Mat src, double power, Mat dst); +void Mat_Phase(Mat x, Mat y, Mat angle, bool angleInDegrees); +Scalar Mat_Sum(Mat src1); + +TermCriteria TermCriteria_New(int typ, int maxCount, double epsilon); + +int64_t GetCVTickCount(); +double GetTickFrequency(); + +Mat Mat_rowRange(Mat m,int startrow,int endrow); +Mat Mat_colRange(Mat m,int startrow,int endrow); + +PointVector PointVector_New(); +PointVector PointVector_NewFromPoints(Contour points); +PointVector PointVector_NewFromMat(Mat mat); +Point PointVector_At(PointVector pv, int idx); +void PointVector_Append(PointVector pv, Point p); +int PointVector_Size(PointVector pv); +void PointVector_Close(PointVector pv); + +PointsVector PointsVector_New(); +PointsVector PointsVector_NewFromPoints(Contours points); +PointVector PointsVector_At(PointsVector psv, int idx); +void PointsVector_Append(PointsVector psv, PointVector pv); +int PointsVector_Size(PointsVector psv); +void PointsVector_Close(PointsVector psv); + +Point2fVector Point2fVector_New(); +void Point2fVector_Close(Point2fVector pfv); +Point2fVector Point2fVector_NewFromPoints(Contour2f pts); +Point2fVector Point2fVector_NewFromMat(Mat mat); +Point2f Point2fVector_At(Point2fVector pfv, int idx); +int Point2fVector_Size(Point2fVector pfv); + +void IntVector_Close(struct IntVector ivec); + +void CStrings_Close(struct CStrings cstrs); + +RNG TheRNG(); + +void SetRNGSeed(int seed); + +void RNG_Fill(RNG rng, Mat mat, int distType, double a, double b, bool saturateRange); + +double RNG_Gaussian(RNG rng, double sigma); + +unsigned int RNG_Next(RNG rng); + +void RandN(Mat mat, Scalar mean, Scalar stddev); + +void RandShuffle(Mat mat); + +void RandShuffleWithParams(Mat mat, double iterFactor, RNG rng); + +void RandU(Mat mat, Scalar low, Scalar high); + +void copyPointVectorToPoint2fVector(PointVector src, Point2fVector dest); + +void StdByteVectorInitialize(void* data); +void StdByteVectorFree(void *data); +size_t StdByteVectorLen(void *data); +uint8_t* StdByteVectorData(void *data); + +Points2fVector Points2fVector_New(); +Points2fVector Points2fVector_NewFromPoints(Contours2f points); +int Points2fVector_Size(Points2fVector ps); +Point2fVector Points2fVector_At(Points2fVector ps, int idx); +void Points2fVector_Append(Points2fVector psv, Point2fVector pv); +void Points2fVector_Close(Points2fVector ps); + +Point3fVector Point3fVector_New(); +Point3fVector Point3fVector_NewFromPoints(Contour3f points); +Point3fVector Point3fVector_NewFromMat(Mat mat); +void Point3fVector_Append(Point3fVector pfv, Point3f point); +Point3f Point3fVector_At(Point3fVector pfv, int idx); +int Point3fVector_Size(Point3fVector pfv); +void Point3fVector_Close(Point3fVector pv); +Points3fVector Points3fVector_New(); +Points3fVector Points3fVector_NewFromPoints(Contours3f points); +int Points3fVector_Size(Points3fVector ps); +Point3fVector Points3fVector_At(Points3fVector ps, int idx); +void Points3fVector_Append(Points3fVector psv, Point3fVector pv); +void Points3fVector_Close(Points3fVector ps); + +void SetNumThreads(int n); +int GetNumThreads(); + +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_CORE_H_ diff --git a/vendor/gocv.io/x/gocv/core_string.go b/vendor/gocv.io/x/gocv/core_string.go new file mode 100644 index 00000000..39d5d22b --- /dev/null +++ b/vendor/gocv.io/x/gocv/core_string.go @@ -0,0 +1,211 @@ +package gocv + +func (c MatType) String() string { + switch c { + case MatTypeCV8U: + return "CV8U" + case MatTypeCV8UC2: + return "CV8UC2" + case MatTypeCV8UC3: + return "CV8UC3" + case MatTypeCV8UC4: + return "CV8UC4" + case MatTypeCV16U: + return "CV16U" + case MatTypeCV16UC2: + return "CV16UC2" + case MatTypeCV16UC3: + return "CV16UC3" + case MatTypeCV16UC4: + return "CV16UC4" + case MatTypeCV16S: + return "CV16S" + case MatTypeCV16SC2: + return "CV16SC2" + case MatTypeCV16SC3: + return "CV16SC3" + case MatTypeCV16SC4: + return "CV16SC4" + case MatTypeCV32S: + return "CV32S" + case MatTypeCV32SC2: + return "CV32SC2" + case MatTypeCV32SC3: + return "CV32SC3" + case MatTypeCV32SC4: + return "CV32SC4" + case MatTypeCV32F: + return "CV32F" + case MatTypeCV32FC2: + return "CV32FC2" + case MatTypeCV32FC3: + return "CV32FC3" + case MatTypeCV32FC4: + return "CV32FC4" + case MatTypeCV64F: + return "CV64F" + case MatTypeCV64FC2: + return "CV64FC2" + case MatTypeCV64FC3: + return "CV64FC3" + case MatTypeCV64FC4: + return "CV64FC4" + } + return "" +} + +func (c CompareType) String() string { + switch c { + case CompareEQ: + return "eq" + case CompareGT: + return "gt" + case CompareGE: + return "ge" + case CompareLT: + return "lt" + case CompareLE: + return "le" + case CompareNE: + return "ne" + } + return "" +} + +func (c CovarFlags) String() string { + switch c { + case CovarScrambled: + return "covar-scrambled" + case CovarNormal: + return "covar-normal" + case CovarUseAvg: + return "covar-use-avg" + case CovarScale: + return "covar-scale" + case CovarRows: + return "covar-rows" + case CovarCols: + return "covar-cols" + } + return "" +} + +func (c DftFlags) String() string { + switch c { + case DftForward: + return "dft-forward" + case DftInverse: + return "dft-inverse" + case DftScale: + return "dft-scale" + case DftRows: + return "dft-rows" + case DftComplexOutput: + return "dft-complex-output" + case DftRealOutput: + return "dft-real-output" + case DftComplexInput: + return "dft-complex-input" + } + return "" +} + +func (c RotateFlag) String() string { + switch c { + case Rotate90Clockwise: + return "rotate-90-clockwise" + case Rotate180Clockwise: + return "rotate-180-clockwise" + case Rotate90CounterClockwise: + return "rotate-90-counter-clockwise" + } + return "" +} + +func (c KMeansFlags) String() string { + switch c { + case KMeansRandomCenters: + return "kmeans-random-centers" + case KMeansPPCenters: + return "kmeans-pp-centers" + case KMeansUseInitialLabels: + return "kmeans-use-initial-labels" + } + return "" +} + +func (c NormType) String() string { + switch c { + case NormInf: + return "norm-inf" + case NormL1: + return "norm-l1" + case NormL2: + return "norm-l2" + case NormL2Sqr: + return "norm-l2-sqr" + case NormHamming: + return "norm-hamming" + case NormHamming2: + return "norm-hamming2" + case NormRelative: + return "norm-relative" + case NormMinMax: + return "norm-minmax" + } + return "" +} + +func (c TermCriteriaType) String() string { + switch c { + case Count: + return "count" + case EPS: + return "eps" + } + return "" +} + +func (c SolveDecompositionFlags) String() string { + switch c { + case SolveDecompositionLu: + return "solve-decomposition-lu" + case SolveDecompositionSvd: + return "solve-decomposition-svd" + case SolveDecompositionEing: + return "solve-decomposition-eing" + case SolveDecompositionCholesky: + return "solve-decomposition-cholesky" + case SolveDecompositionQr: + return "solve-decomposition-qr" + case SolveDecompositionNormal: + return "solve-decomposition-normal" + } + return "" +} + +func (c ReduceTypes) String() string { + switch c { + case ReduceSum: + return "reduce-sum" + case ReduceAvg: + return "reduce-avg" + case ReduceMax: + return "reduce-max" + case ReduceMin: + return "reduce-min" + } + return "" +} + +func (c SortFlags) String() string { + switch c { + case SortEveryRow: + return "sort-every-row" + case SortEveryColumn: + return "sort-every-column" + case SortDescending: + return "sort-descending" + } + return "" +} diff --git a/vendor/gocv.io/x/gocv/dnn.cpp b/vendor/gocv.io/x/gocv/dnn.cpp new file mode 100644 index 00000000..3cfde57a --- /dev/null +++ b/vendor/gocv.io/x/gocv/dnn.cpp @@ -0,0 +1,266 @@ +#include "dnn.h" + +Net Net_ReadNet(const char* model, const char* config) { + Net n = new cv::dnn::Net(cv::dnn::readNet(model, config)); + return n; +} + +Net Net_ReadNetBytes(const char* framework, struct ByteArray model, struct ByteArray config) { + std::vector modelv(model.data, model.data + model.length); + std::vector configv(config.data, config.data + config.length); + Net n = new cv::dnn::Net(cv::dnn::readNet(framework, modelv, configv)); + return n; +} + +Net Net_ReadNetFromCaffe(const char* prototxt, const char* caffeModel) { + Net n = new cv::dnn::Net(cv::dnn::readNetFromCaffe(prototxt, caffeModel)); + return n; +} + +Net Net_ReadNetFromCaffeBytes(struct ByteArray prototxt, struct ByteArray caffeModel) { + Net n = new cv::dnn::Net(cv::dnn::readNetFromCaffe(prototxt.data, prototxt.length, + caffeModel.data, caffeModel.length)); + return n; +} + +Net Net_ReadNetFromTensorflow(const char* model) { + Net n = new cv::dnn::Net(cv::dnn::readNetFromTensorflow(model)); + return n; +} + +Net Net_ReadNetFromTensorflowBytes(struct ByteArray model) { + Net n = new cv::dnn::Net(cv::dnn::readNetFromTensorflow(model.data, model.length)); + return n; +} + +Net Net_ReadNetFromTorch(const char* model) { + Net n = new cv::dnn::Net(cv::dnn::readNetFromTorch(model)); + return n; +} + +Net Net_ReadNetFromONNX(const char* model) { + Net n = new cv::dnn::Net(cv::dnn::readNetFromONNX(model)); + return n; +} + +Net Net_ReadNetFromONNXBytes(struct ByteArray model) { + Net n = new cv::dnn::Net(cv::dnn::readNetFromONNX(model.data, model.length)); + return n; +} + +void Net_Close(Net net) { + delete net; +} + +bool Net_Empty(Net net) { + return net->empty(); +} + +void Net_SetInput(Net net, Mat blob, const char* name) { + net->setInput(*blob, name); +} + +Mat Net_Forward(Net net, const char* outputName) { + return new cv::Mat(net->forward(outputName)); +} + +void Net_ForwardLayers(Net net, struct Mats* outputBlobs, struct CStrings outBlobNames) { + std::vector< cv::Mat > blobs; + + std::vector< cv::String > names; + for (int i = 0; i < outBlobNames.length; ++i) { + names.push_back(cv::String(outBlobNames.strs[i])); + } + net->forward(blobs, names); + + // copy blobs into outputBlobs + outputBlobs->mats = new Mat[blobs.size()]; + + for (size_t i = 0; i < blobs.size(); ++i) { + outputBlobs->mats[i] = new cv::Mat(blobs[i]); + } + + outputBlobs->length = (int)blobs.size(); +} + +void Net_SetPreferableBackend(Net net, int backend) { + net->setPreferableBackend(backend); +} + +void Net_SetPreferableTarget(Net net, int target) { + net->setPreferableTarget(target); +} + +int64_t Net_GetPerfProfile(Net net) { + std::vector layersTimes; + return net->getPerfProfile(layersTimes); +} + +void Net_GetUnconnectedOutLayers(Net net, IntVector* res) { + std::vector< int > cids(net->getUnconnectedOutLayers()); + int* ids = new int[cids.size()]; + + for (size_t i = 0; i < cids.size(); ++i) { + ids[i] = cids[i]; + } + + res->length = cids.size(); + res->val = ids; + return; +} + +void Net_GetLayerNames(Net net, CStrings* names) { + std::vector< cv::String > cstrs(net->getLayerNames()); + const char **strs = new const char*[cstrs.size()]; + + for (size_t i = 0; i < cstrs.size(); ++i) { + strs[i] = cstrs[i].c_str(); + } + + names->length = cstrs.size(); + names->strs = strs; + return; +} + +Mat Net_BlobFromImage(Mat image, double scalefactor, Size size, Scalar mean, bool swapRB, + bool crop) { + cv::Size sz(size.width, size.height); + cv::Scalar cm(mean.val1, mean.val2, mean.val3, mean.val4); + // use the default target ddepth here. + return new cv::Mat(cv::dnn::blobFromImage(*image, scalefactor, sz, cm, swapRB, crop)); +} + +void Net_BlobFromImages(struct Mats images, Mat blob, double scalefactor, Size size, + Scalar mean, bool swapRB, bool crop, int ddepth) { + std::vector imgs; + + for (int i = 0; i < images.length; ++i) { + imgs.push_back(*images.mats[i]); + } + + cv::Size sz(size.width, size.height); + cv::Scalar cm = cv::Scalar(mean.val1, mean.val2, mean.val3, mean.val4); + + // ignore the passed in ddepth, just use default. + cv::dnn::blobFromImages(imgs, *blob, scalefactor, sz, cm, swapRB, crop); +} + +void Net_ImagesFromBlob(Mat blob_, struct Mats* images_) { + std::vector imgs; + cv::dnn::imagesFromBlob(*blob_, imgs); + images_->mats = new Mat[imgs.size()]; + + for (size_t i = 0; i < imgs.size(); ++i) { + images_->mats[i] = new cv::Mat(imgs[i]); + } + images_->length = (int) imgs.size(); +} + +Mat Net_GetBlobChannel(Mat blob, int imgidx, int chnidx) { + size_t w = blob->size[3]; + size_t h = blob->size[2]; + return new cv::Mat(h, w, CV_32F, blob->ptr(imgidx, chnidx)); +} + +Scalar Net_GetBlobSize(Mat blob) { + Scalar scal = Scalar(); + scal.val1 = blob->size[0]; + scal.val2 = blob->size[1]; + scal.val3 = blob->size[2]; + scal.val4 = blob->size[3]; + return scal; +} + +Layer Net_GetLayer(Net net, int layerid) { + return new cv::Ptr(net->getLayer(layerid)); +} + +void Layer_Close(Layer layer) { + delete layer; +} + +int Layer_InputNameToIndex(Layer layer, const char* name) { + return (*layer)->inputNameToIndex(name); +} + +int Layer_OutputNameToIndex(Layer layer, const char* name) { + return (*layer)->outputNameToIndex(name); +} + +const char* Layer_GetName(Layer layer) { + return (*layer)->name.c_str(); +} + +const char* Layer_GetType(Layer layer) { + return (*layer)->type.c_str(); +} + +void NMSBoxes(struct Rects bboxes, FloatVector scores, float score_threshold, float nms_threshold, IntVector* indices) { + std::vector _bboxes; + + for (int i = 0; i < bboxes.length; ++i) { + _bboxes.push_back(cv::Rect( + bboxes.rects[i].x, + bboxes.rects[i].y, + bboxes.rects[i].width, + bboxes.rects[i].height + )); + } + + std::vector _scores; + + float* f; + int i; + for (i = 0, f = scores.val; i < scores.length; ++f, ++i) { + _scores.push_back(*f); + } + + std::vector _indices(indices->length); + + cv::dnn::NMSBoxes(_bboxes, _scores, score_threshold, nms_threshold, _indices, 1.f, 0); + + int* ptr = new int[_indices.size()]; + + for (size_t i=0; i<_indices.size(); ++i) { + ptr[i] = _indices[i]; + } + + indices->length = _indices.size(); + indices->val = ptr; + return; +} + +void NMSBoxesWithParams(struct Rects bboxes, FloatVector scores, const float score_threshold, const float nms_threshold, IntVector* indices, const float eta, const int top_k) { + std::vector _bboxes; + + for (int i = 0; i < bboxes.length; ++i) { + _bboxes.push_back(cv::Rect( + bboxes.rects[i].x, + bboxes.rects[i].y, + bboxes.rects[i].width, + bboxes.rects[i].height + )); + } + + std::vector _scores; + + float* f; + int i; + for (i = 0, f = scores.val; i < scores.length; ++f, ++i) { + _scores.push_back(*f); + } + + std::vector _indices(indices->length); + + cv::dnn::NMSBoxes(_bboxes, _scores, score_threshold, nms_threshold, _indices, eta, top_k); + + int* ptr = new int[_indices.size()]; + + for (size_t i=0; i<_indices.size(); ++i) { + ptr[i] = _indices[i]; + } + + indices->length = _indices.size(); + indices->val = ptr; + return; +} \ No newline at end of file diff --git a/vendor/gocv.io/x/gocv/dnn.go b/vendor/gocv.io/x/gocv/dnn.go new file mode 100644 index 00000000..0dc46e2e --- /dev/null +++ b/vendor/gocv.io/x/gocv/dnn.go @@ -0,0 +1,618 @@ +package gocv + +/* +#include +#include "dnn.h" +*/ +import "C" +import ( + "image" + "reflect" + "unsafe" +) + +// Net allows you to create and manipulate comprehensive artificial neural networks. +// +// For further details, please see: +// https://docs.opencv.org/master/db/d30/classcv_1_1dnn_1_1Net.html +// +type Net struct { + // C.Net + p unsafe.Pointer +} + +// NetBackendType is the type for the various different kinds of DNN backends. +type NetBackendType int + +const ( + // NetBackendDefault is the default backend. + NetBackendDefault NetBackendType = 0 + + // NetBackendHalide is the Halide backend. + NetBackendHalide NetBackendType = 1 + + // NetBackendOpenVINO is the OpenVINO backend. + NetBackendOpenVINO NetBackendType = 2 + + // NetBackendOpenCV is the OpenCV backend. + NetBackendOpenCV NetBackendType = 3 + + // NetBackendVKCOM is the Vulkan backend. + NetBackendVKCOM NetBackendType = 4 + + // NetBackendCUDA is the Cuda backend. + NetBackendCUDA NetBackendType = 5 +) + +// ParseNetBackend returns a valid NetBackendType given a string. Valid values are: +// - halide +// - openvino +// - opencv +// - vulkan +// - cuda +// - default +func ParseNetBackend(backend string) NetBackendType { + switch backend { + case "halide": + return NetBackendHalide + case "openvino": + return NetBackendOpenVINO + case "opencv": + return NetBackendOpenCV + case "vulkan": + return NetBackendVKCOM + case "cuda": + return NetBackendCUDA + default: + return NetBackendDefault + } +} + +// NetTargetType is the type for the various different kinds of DNN device targets. +type NetTargetType int + +const ( + // NetTargetCPU is the default CPU device target. + NetTargetCPU NetTargetType = 0 + + // NetTargetFP32 is the 32-bit OpenCL target. + NetTargetFP32 NetTargetType = 1 + + // NetTargetFP16 is the 16-bit OpenCL target. + NetTargetFP16 NetTargetType = 2 + + // NetTargetVPU is the Movidius VPU target. + NetTargetVPU NetTargetType = 3 + + // NetTargetVulkan is the NVIDIA Vulkan target. + NetTargetVulkan NetTargetType = 4 + + // NetTargetFPGA is the FPGA target. + NetTargetFPGA NetTargetType = 5 + + // NetTargetCUDA is the CUDA target. + NetTargetCUDA NetTargetType = 6 + + // NetTargetCUDAFP16 is the CUDA target. + NetTargetCUDAFP16 NetTargetType = 7 +) + +// ParseNetTarget returns a valid NetTargetType given a string. Valid values are: +// - cpu +// - fp32 +// - fp16 +// - vpu +// - vulkan +// - fpga +// - cuda +// - cudafp16 +func ParseNetTarget(target string) NetTargetType { + switch target { + case "cpu": + return NetTargetCPU + case "fp32": + return NetTargetFP32 + case "fp16": + return NetTargetFP16 + case "vpu": + return NetTargetVPU + case "vulkan": + return NetTargetVulkan + case "fpga": + return NetTargetFPGA + case "cuda": + return NetTargetCUDA + case "cudafp16": + return NetTargetCUDAFP16 + default: + return NetTargetCPU + } +} + +// Close Net +func (net *Net) Close() error { + C.Net_Close((C.Net)(net.p)) + net.p = nil + return nil +} + +// Empty returns true if there are no layers in the network. +// +// For further details, please see: +// https://docs.opencv.org/master/db/d30/classcv_1_1dnn_1_1Net.html#a6a5778787d5b8770deab5eda6968e66c +// +func (net *Net) Empty() bool { + return bool(C.Net_Empty((C.Net)(net.p))) +} + +// SetInput sets the new value for the layer output blob. +// +// For further details, please see: +// https://docs.opencv.org/trunk/db/d30/classcv_1_1dnn_1_1Net.html#a672a08ae76444d75d05d7bfea3e4a328 +// +func (net *Net) SetInput(blob Mat, name string) { + cName := C.CString(name) + defer C.free(unsafe.Pointer(cName)) + + C.Net_SetInput((C.Net)(net.p), blob.p, cName) +} + +// Forward runs forward pass to compute output of layer with name outputName. +// +// For further details, please see: +// https://docs.opencv.org/trunk/db/d30/classcv_1_1dnn_1_1Net.html#a98ed94cb6ef7063d3697259566da310b +// +func (net *Net) Forward(outputName string) Mat { + cName := C.CString(outputName) + defer C.free(unsafe.Pointer(cName)) + + return newMat(C.Net_Forward((C.Net)(net.p), cName)) +} + +// ForwardLayers forward pass to compute outputs of layers listed in outBlobNames. +// +// For further details, please see: +// https://docs.opencv.org/3.4.1/db/d30/classcv_1_1dnn_1_1Net.html#adb34d7650e555264c7da3b47d967311b +// +func (net *Net) ForwardLayers(outBlobNames []string) (blobs []Mat) { + cMats := C.struct_Mats{} + C.Net_ForwardLayers((C.Net)(net.p), &(cMats), toCStrings(outBlobNames)) + blobs = make([]Mat, cMats.length) + for i := C.int(0); i < cMats.length; i++ { + blobs[i].p = C.Mats_get(cMats, i) + addMatToProfile(blobs[i].p) + } + return +} + +// SetPreferableBackend ask network to use specific computation backend. +// +// For further details, please see: +// https://docs.opencv.org/3.4/db/d30/classcv_1_1dnn_1_1Net.html#a7f767df11386d39374db49cd8df8f59e +// +func (net *Net) SetPreferableBackend(backend NetBackendType) error { + C.Net_SetPreferableBackend((C.Net)(net.p), C.int(backend)) + return nil +} + +// SetPreferableTarget ask network to make computations on specific target device. +// +// For further details, please see: +// https://docs.opencv.org/3.4/db/d30/classcv_1_1dnn_1_1Net.html#a9dddbefbc7f3defbe3eeb5dc3d3483f4 +// +func (net *Net) SetPreferableTarget(target NetTargetType) error { + C.Net_SetPreferableTarget((C.Net)(net.p), C.int(target)) + return nil +} + +// ReadNet reads a deep learning network represented in one of the supported formats. +// +// For further details, please see: +// https://docs.opencv.org/3.4/d6/d0f/group__dnn.html#ga3b34fe7a29494a6a4295c169a7d32422 +// +func ReadNet(model string, config string) Net { + cModel := C.CString(model) + defer C.free(unsafe.Pointer(cModel)) + + cConfig := C.CString(config) + defer C.free(unsafe.Pointer(cConfig)) + return Net{p: unsafe.Pointer(C.Net_ReadNet(cModel, cConfig))} +} + +// ReadNetBytes reads a deep learning network represented in one of the supported formats. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d0f/group__dnn.html#ga138439da76f26266fdefec9723f6c5cd +// +func ReadNetBytes(framework string, model []byte, config []byte) (Net, error) { + cFramework := C.CString(framework) + defer C.free(unsafe.Pointer(cFramework)) + bModel, err := toByteArray(model) + if err != nil { + return Net{}, err + } + bConfig, err := toByteArray(config) + if err != nil { + return Net{}, err + } + return Net{p: unsafe.Pointer(C.Net_ReadNetBytes(cFramework, *bModel, *bConfig))}, nil +} + +// ReadNetFromCaffe reads a network model stored in Caffe framework's format. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d0f/group__dnn.html#ga29d0ea5e52b1d1a6c2681e3f7d68473a +// +func ReadNetFromCaffe(prototxt string, caffeModel string) Net { + cprototxt := C.CString(prototxt) + defer C.free(unsafe.Pointer(cprototxt)) + + cmodel := C.CString(caffeModel) + defer C.free(unsafe.Pointer(cmodel)) + return Net{p: unsafe.Pointer(C.Net_ReadNetFromCaffe(cprototxt, cmodel))} +} + +// ReadNetFromCaffeBytes reads a network model stored in Caffe model in memory. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d0f/group__dnn.html#ga946b342af1355185a7107640f868b64a +// +func ReadNetFromCaffeBytes(prototxt []byte, caffeModel []byte) (Net, error) { + bPrototxt, err := toByteArray(prototxt) + if err != nil { + return Net{}, err + } + bCaffeModel, err := toByteArray(caffeModel) + if err != nil { + return Net{}, err + } + return Net{p: unsafe.Pointer(C.Net_ReadNetFromCaffeBytes(*bPrototxt, *bCaffeModel))}, nil +} + +// ReadNetFromTensorflow reads a network model stored in Tensorflow framework's format. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d0f/group__dnn.html#gad820b280978d06773234ba6841e77e8d +// +func ReadNetFromTensorflow(model string) Net { + cmodel := C.CString(model) + defer C.free(unsafe.Pointer(cmodel)) + return Net{p: unsafe.Pointer(C.Net_ReadNetFromTensorflow(cmodel))} +} + +// ReadNetFromTensorflowBytes reads a network model stored in Tensorflow framework's format. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d0f/group__dnn.html#gacdba30a7c20db2788efbf5bb16a7884d +// +func ReadNetFromTensorflowBytes(model []byte) (Net, error) { + bModel, err := toByteArray(model) + if err != nil { + return Net{}, err + } + return Net{p: unsafe.Pointer(C.Net_ReadNetFromTensorflowBytes(*bModel))}, nil +} + +// ReadNetFromTorch reads a network model stored in Torch framework's format (t7). +// check net.Empty() for read failure +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d0f/group__dnn.html#gaaaed8c8530e9e92fe6647700c13d961e +// +func ReadNetFromTorch(model string) Net { + cmodel := C.CString(model) + defer C.free(unsafe.Pointer(cmodel)) + return Net{p: unsafe.Pointer(C.Net_ReadNetFromTorch(cmodel))} +} + +// ReadNetFromONNX reads a network model stored in ONNX framework's format. +// check net.Empty() for read failure +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d0f/group__dnn.html#ga7faea56041d10c71dbbd6746ca854197 +// +func ReadNetFromONNX(model string) Net { + cmodel := C.CString(model) + defer C.free(unsafe.Pointer(cmodel)) + return Net{p: unsafe.Pointer(C.Net_ReadNetFromONNX(cmodel))} +} + +// ReadNetFromONNXBytes reads a network model stored in ONNX framework's format. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d0f/group__dnn.html#ga9198ecaac7c32ddf0aa7a1bcbd359567 +// +func ReadNetFromONNXBytes(model []byte) (Net, error) { + bModel, err := toByteArray(model) + if err != nil { + return Net{}, err + } + return Net{p: unsafe.Pointer(C.Net_ReadNetFromONNXBytes(*bModel))}, nil +} + +// BlobFromImage creates 4-dimensional blob from image. Optionally resizes and crops +// image from center, subtract mean values, scales values by scalefactor, +// swap Blue and Red channels. +// +// For further details, please see: +// https://docs.opencv.org/trunk/d6/d0f/group__dnn.html#ga152367f253c81b53fe6862b299f5c5cd +// +func BlobFromImage(img Mat, scaleFactor float64, size image.Point, mean Scalar, + swapRB bool, crop bool) Mat { + + sz := C.struct_Size{ + width: C.int(size.X), + height: C.int(size.Y), + } + + sMean := C.struct_Scalar{ + val1: C.double(mean.Val1), + val2: C.double(mean.Val2), + val3: C.double(mean.Val3), + val4: C.double(mean.Val4), + } + + return newMat(C.Net_BlobFromImage(img.p, C.double(scaleFactor), sz, sMean, C.bool(swapRB), C.bool(crop))) +} + +// BlobFromImages Creates 4-dimensional blob from series of images. +// Optionally resizes and crops images from center, subtract mean values, +// scales values by scalefactor, swap Blue and Red channels. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d0f/group__dnn.html#ga2b89ed84432e4395f5a1412c2926293c +// +func BlobFromImages(imgs []Mat, blob *Mat, scaleFactor float64, size image.Point, mean Scalar, + swapRB bool, crop bool, ddepth MatType) { + + cMatArray := make([]C.Mat, len(imgs)) + for i, r := range imgs { + cMatArray[i] = r.p + } + + cMats := C.struct_Mats{ + mats: (*C.Mat)(&cMatArray[0]), + length: C.int(len(imgs)), + } + + sz := C.struct_Size{ + width: C.int(size.X), + height: C.int(size.Y), + } + + sMean := C.struct_Scalar{ + val1: C.double(mean.Val1), + val2: C.double(mean.Val2), + val3: C.double(mean.Val3), + val4: C.double(mean.Val4), + } + + C.Net_BlobFromImages(cMats, blob.p, C.double(scaleFactor), sz, sMean, C.bool(swapRB), C.bool(crop), C.int(ddepth)) +} + +// ImagesFromBlob Parse a 4D blob and output the images it contains as +// 2D arrays through a simpler data structure (std::vector). +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d0f/group__dnn.html#ga4051b5fa2ed5f54b76c059a8625df9f5 +// +func ImagesFromBlob(blob Mat, imgs []Mat) { + cMats := C.struct_Mats{} + C.Net_ImagesFromBlob(blob.p, &(cMats)) + // mv = make([]Mat, cMats.length) + for i := C.int(0); i < cMats.length; i++ { + imgs[i].p = C.Mats_get(cMats, i) + } +} + +// GetBlobChannel extracts a single (2d)channel from a 4 dimensional blob structure +// (this might e.g. contain the results of a SSD or YOLO detection, +// a bones structure from pose detection, or a color plane from Colorization) +// +func GetBlobChannel(blob Mat, imgidx int, chnidx int) Mat { + return newMat(C.Net_GetBlobChannel(blob.p, C.int(imgidx), C.int(chnidx))) +} + +// GetBlobSize retrieves the 4 dimensional size information in (N,C,H,W) order +// +func GetBlobSize(blob Mat) Scalar { + s := C.Net_GetBlobSize(blob.p) + return NewScalar(float64(s.val1), float64(s.val2), float64(s.val3), float64(s.val4)) +} + +// Layer is a wrapper around the cv::dnn::Layer algorithm. +type Layer struct { + // C.Layer + p unsafe.Pointer +} + +// GetLayer returns pointer to layer with specified id from the network. +// +// For further details, please see: +// https://docs.opencv.org/master/db/d30/classcv_1_1dnn_1_1Net.html#a70aec7f768f38c32b1ee25f3a56526df +// +func (net *Net) GetLayer(layer int) Layer { + return Layer{p: unsafe.Pointer(C.Net_GetLayer((C.Net)(net.p), C.int(layer)))} +} + +// GetPerfProfile returns overall time for inference and timings (in ticks) for layers +// +// For further details, please see: +// https://docs.opencv.org/master/db/d30/classcv_1_1dnn_1_1Net.html#a06ce946f675f75d1c020c5ddbc78aedc +// +func (net *Net) GetPerfProfile() float64 { + return float64(C.Net_GetPerfProfile((C.Net)(net.p))) +} + +// GetUnconnectedOutLayers returns indexes of layers with unconnected outputs. +// +// For further details, please see: +// https://docs.opencv.org/master/db/d30/classcv_1_1dnn_1_1Net.html#ae62a73984f62c49fd3e8e689405b056a +// +func (net *Net) GetUnconnectedOutLayers() (ids []int) { + cids := C.IntVector{} + C.Net_GetUnconnectedOutLayers((C.Net)(net.p), &cids) + defer C.free(unsafe.Pointer(cids.val)) + + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(cids.val)), + Len: int(cids.length), + Cap: int(cids.length), + } + pcids := *(*[]C.int)(unsafe.Pointer(h)) + + for i := 0; i < int(cids.length); i++ { + ids = append(ids, int(pcids[i])) + } + return +} + +// GetLayerNames returns all layer names. +// +// For furtherdetails, please see: +// https://docs.opencv.org/master/db/d30/classcv_1_1dnn_1_1Net.html#ae8be9806024a0d1d41aba687cce99e6b +// +func (net *Net) GetLayerNames() (names []string) { + cstrs := C.CStrings{} + defer C.CStrings_Close(cstrs) + C.Net_GetLayerNames((C.Net)(net.p), &cstrs) + return toGoStrings(cstrs) +} + +// Close Layer +func (l *Layer) Close() error { + C.Layer_Close((C.Layer)(l.p)) + l.p = nil + return nil +} + +// GetName returns name for this layer. +func (l *Layer) GetName() string { + return C.GoString(C.Layer_GetName((C.Layer)(l.p))) +} + +// GetType returns type for this layer. +func (l *Layer) GetType() string { + return C.GoString(C.Layer_GetType((C.Layer)(l.p))) +} + +// InputNameToIndex returns index of input blob in input array. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d6c/classcv_1_1dnn_1_1Layer.html#a60ffc8238f3fa26cd3f49daa7ac0884b +// +func (l *Layer) InputNameToIndex(name string) int { + cName := C.CString(name) + defer C.free(unsafe.Pointer(cName)) + return int(C.Layer_InputNameToIndex((C.Layer)(l.p), cName)) +} + +// OutputNameToIndex returns index of output blob in output array. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d6c/classcv_1_1dnn_1_1Layer.html#a60ffc8238f3fa26cd3f49daa7ac0884b +// +func (l *Layer) OutputNameToIndex(name string) int { + cName := C.CString(name) + defer C.free(unsafe.Pointer(cName)) + return int(C.Layer_OutputNameToIndex((C.Layer)(l.p), cName)) +} + +// NMSBoxes performs non maximum suppression given boxes and corresponding scores. +// +// For futher details, please see: +// https://docs.opencv.org/4.4.0/d6/d0f/group__dnn.html#ga9d118d70a1659af729d01b10233213ee +func NMSBoxes(bboxes []image.Rectangle, scores []float32, scoreThreshold float32, nmsThreshold float32) (indices []int) { + bboxesRectArr := []C.struct_Rect{} + for _, v := range bboxes { + bbox := C.struct_Rect{ + x: C.int(v.Min.X), + y: C.int(v.Min.Y), + width: C.int(v.Size().X), + height: C.int(v.Size().Y), + } + bboxesRectArr = append(bboxesRectArr, bbox) + } + + bboxesRects := C.Rects{ + rects: (*C.Rect)(&bboxesRectArr[0]), + length: C.int(len(bboxes)), + } + + scoresFloats := []C.float{} + for _, v := range scores { + scoresFloats = append(scoresFloats, C.float(v)) + } + scoresVector := C.struct_FloatVector{} + scoresVector.val = (*C.float)(&scoresFloats[0]) + scoresVector.length = (C.int)(len(scoresFloats)) + + indicesVector := C.IntVector{} + + C.NMSBoxes(bboxesRects, scoresVector, C.float(scoreThreshold), C.float(nmsThreshold), &indicesVector) + defer C.free(unsafe.Pointer(indicesVector.val)) + + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(indicesVector.val)), + Len: int(indicesVector.length), + Cap: int(indicesVector.length), + } + + ptr := *(*[]C.int)(unsafe.Pointer(h)) + + + indices = make([]int,indicesVector.length) + for i := 0; i < int(indicesVector.length); i++ { + indices[i] = int(ptr[i]) + } + return +} + +// NMSBoxesWithParams performs non maximum suppression given boxes and corresponding scores. +// +// For futher details, please see: +// https://docs.opencv.org/4.4.0/d6/d0f/group__dnn.html#ga9d118d70a1659af729d01b10233213ee +func NMSBoxesWithParams(bboxes []image.Rectangle, scores []float32, scoreThreshold float32, nmsThreshold float32, eta float32, topK int) (indices []int) { + bboxesRectArr := []C.struct_Rect{} + for _, v := range bboxes { + bbox := C.struct_Rect{ + x: C.int(v.Min.X), + y: C.int(v.Min.Y), + width: C.int(v.Size().X), + height: C.int(v.Size().Y), + } + bboxesRectArr = append(bboxesRectArr, bbox) + } + + bboxesRects := C.Rects{ + rects: (*C.Rect)(&bboxesRectArr[0]), + length: C.int(len(bboxes)), + } + + scoresFloats := []C.float{} + for _, v := range scores { + scoresFloats = append(scoresFloats, C.float(v)) + } + scoresVector := C.struct_FloatVector{} + scoresVector.val = (*C.float)(&scoresFloats[0]) + scoresVector.length = (C.int)(len(scoresFloats)) + + indicesVector := C.IntVector{} + + C.NMSBoxesWithParams(bboxesRects, scoresVector, C.float(scoreThreshold), C.float(nmsThreshold), &indicesVector, C.float(eta), C.int(topK)) + defer C.free(unsafe.Pointer(indicesVector.val)) + + h := &reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(indicesVector.val)), + Len: int(indicesVector.length), + Cap: int(indicesVector.length), + } + + ptr := *(*[]C.int)(unsafe.Pointer(h)) + + indices = make([]int,indicesVector.length) + for i := 0; i < int(indicesVector.length); i++ { + indices[i] = int(ptr[i]) + } + return +} diff --git a/vendor/gocv.io/x/gocv/dnn.h b/vendor/gocv.io/x/gocv/dnn.h new file mode 100644 index 00000000..e1f00bb2 --- /dev/null +++ b/vendor/gocv.io/x/gocv/dnn.h @@ -0,0 +1,64 @@ +#ifndef _OPENCV3_DNN_H_ +#define _OPENCV3_DNN_H_ + +#include + +#ifdef __cplusplus +#include +#include +extern "C" { +#endif + +#include "core.h" + +#ifdef __cplusplus +typedef cv::dnn::Net* Net; +typedef cv::Ptr* Layer; +#else +typedef void* Net; +typedef void* Layer; +#endif + +Net Net_ReadNet(const char* model, const char* config); +Net Net_ReadNetBytes(const char* framework, struct ByteArray model, struct ByteArray config); +Net Net_ReadNetFromCaffe(const char* prototxt, const char* caffeModel); +Net Net_ReadNetFromCaffeBytes(struct ByteArray prototxt, struct ByteArray caffeModel); +Net Net_ReadNetFromTensorflow(const char* model); +Net Net_ReadNetFromTensorflowBytes(struct ByteArray model); +Net Net_ReadNetFromTorch(const char* model); +Net Net_ReadNetFromONNX(const char* model); +Net Net_ReadNetFromONNXBytes(struct ByteArray model); +Mat Net_BlobFromImage(Mat image, double scalefactor, Size size, Scalar mean, bool swapRB, + bool crop); +void Net_BlobFromImages(struct Mats images, Mat blob, double scalefactor, Size size, + Scalar mean, bool swapRB, bool crop, int ddepth); +void Net_ImagesFromBlob(Mat blob_, struct Mats* images_); +void Net_Close(Net net); +bool Net_Empty(Net net); +void Net_SetInput(Net net, Mat blob, const char* name); +Mat Net_Forward(Net net, const char* outputName); +void Net_ForwardLayers(Net net, struct Mats* outputBlobs, struct CStrings outBlobNames); +void Net_SetPreferableBackend(Net net, int backend); +void Net_SetPreferableTarget(Net net, int target); +int64_t Net_GetPerfProfile(Net net); +void Net_GetUnconnectedOutLayers(Net net, IntVector* res); +void Net_GetLayerNames(Net net, CStrings* names); + +Mat Net_GetBlobChannel(Mat blob, int imgidx, int chnidx); +Scalar Net_GetBlobSize(Mat blob); + +Layer Net_GetLayer(Net net, int layerid); +void Layer_Close(Layer layer); +int Layer_InputNameToIndex(Layer layer, const char* name); +int Layer_OutputNameToIndex(Layer layer, const char* name); +const char* Layer_GetName(Layer layer); +const char* Layer_GetType(Layer layer); + +void NMSBoxes(struct Rects bboxes, FloatVector scores, float score_threshold, float nms_threshold, IntVector* indices); +void NMSBoxesWithParams(struct Rects bboxes, FloatVector scores, const float score_threshold, const float nms_threshold, IntVector* indices, const float eta, const int top_k); + +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_DNN_H_ diff --git a/vendor/gocv.io/x/gocv/dnn_async_openvino.go b/vendor/gocv.io/x/gocv/dnn_async_openvino.go new file mode 100644 index 00000000..0425d999 --- /dev/null +++ b/vendor/gocv.io/x/gocv/dnn_async_openvino.go @@ -0,0 +1,26 @@ +// +build openvino + +package gocv + +import ( + "unsafe" +) + +/* +#include +#include "dnn.h" +#include "asyncarray.h" +*/ +import "C" + +// ForwardAsync runs forward pass to compute output of layer with name outputName. +// +// For further details, please see: +// https://docs.opencv.org/trunk/db/d30/classcv_1_1dnn_1_1Net.html#a814890154ea9e10b132fec00b6f6ba30 +// +func (net *Net) ForwardAsync(outputName string) AsyncArray { + cName := C.CString(outputName) + defer C.free(unsafe.Pointer(cName)) + + return newAsyncArray(C.Net_forwardAsync((C.Net)(net.p), cName)) +} diff --git a/vendor/gocv.io/x/gocv/dnn_ext.go b/vendor/gocv.io/x/gocv/dnn_ext.go new file mode 100644 index 00000000..9ac25174 --- /dev/null +++ b/vendor/gocv.io/x/gocv/dnn_ext.go @@ -0,0 +1,67 @@ +package gocv + +import ( + "image" +) + +// FP16BlobFromImage is an extended helper function to convert an Image to a half-float blob, as used by +// the Movidius Neural Compute Stick. +func FP16BlobFromImage(img Mat, scaleFactor float32, size image.Point, mean float32, + swapRB bool, crop bool) []byte { + + // resizes image so it maintains aspect ratio + width := float32(img.Cols()) + height := float32(img.Rows()) + + square := NewMatWithSize(size.Y, size.X, img.Type()) + defer square.Close() + + maxDim := height + var scale float32 = 1.0 + if width > height { + maxDim = width + scale = float32(size.X) / float32(maxDim) + } + if width < height { + scale = float32(size.Y) / float32(maxDim) + } + + var roi image.Rectangle + if width >= height { + roi.Min.X = 0 + roi.Min.Y = int(float32(size.Y)-height*scale) / 2 + roi.Max.X = size.X + roi.Max.Y = int(height * scale) + } else { + roi.Min.X = int(float32(size.X)-width*scale) / 2 + roi.Min.Y = 0 + roi.Max.X = int(width * scale) + roi.Max.Y = size.Y + } + + Resize(img, &square, roi.Max, 0, 0, InterpolationDefault) + + if swapRB { + CvtColor(square, &square, ColorBGRToRGB) + } + + fp32Image := NewMat() + defer fp32Image.Close() + + square.ConvertTo(&fp32Image, MatTypeCV32F) + + if mean != 0 { + // subtract mean + fp32Image.SubtractFloat(mean) + } + + if scaleFactor != 1.0 { + // multiply by scale factor + fp32Image.MultiplyFloat(scaleFactor) + } + + fp16Blob := fp32Image.ConvertFp16() + defer fp16Blob.Close() + + return fp16Blob.ToBytes() +} diff --git a/vendor/gocv.io/x/gocv/dnn_string.go b/vendor/gocv.io/x/gocv/dnn_string.go new file mode 100644 index 00000000..1615181b --- /dev/null +++ b/vendor/gocv.io/x/gocv/dnn_string.go @@ -0,0 +1,41 @@ +package gocv + +func (c NetBackendType) String() string { + switch c { + case NetBackendDefault: + return "" + case NetBackendHalide: + return "halide" + case NetBackendOpenVINO: + return "openvino" + case NetBackendOpenCV: + return "opencv" + case NetBackendVKCOM: + return "vulkan" + case NetBackendCUDA: + return "cuda" + } + return "" +} + +func (c NetTargetType) String() string { + switch c { + case NetTargetCPU: + return "cpu" + case NetTargetFP32: + return "fp32" + case NetTargetFP16: + return "fp16" + case NetTargetVPU: + return "vpu" + case NetTargetVulkan: + return "vulkan" + case NetTargetFPGA: + return "fpga" + case NetTargetCUDA: + return "cuda" + case NetTargetCUDAFP16: + return "cudafp16" + } + return "" +} diff --git a/vendor/gocv.io/x/gocv/env.cmd b/vendor/gocv.io/x/gocv/env.cmd new file mode 100644 index 00000000..02babfdb --- /dev/null +++ b/vendor/gocv.io/x/gocv/env.cmd @@ -0,0 +1,2 @@ +ECHO This script is no longer necessary and has been deprecated. +ECHO See the Custom Environment section of the README if you need to customize your environment. diff --git a/vendor/gocv.io/x/gocv/env.sh b/vendor/gocv.io/x/gocv/env.sh new file mode 100644 index 00000000..343148f7 --- /dev/null +++ b/vendor/gocv.io/x/gocv/env.sh @@ -0,0 +1,2 @@ +echo "This script is no longer necessary and has been deprecated." +echo "See the Custom Environment section of the README if you need to customize your environment." diff --git a/vendor/gocv.io/x/gocv/features2d.cpp b/vendor/gocv.io/x/gocv/features2d.cpp new file mode 100644 index 00000000..f7b18e30 --- /dev/null +++ b/vendor/gocv.io/x/gocv/features2d.cpp @@ -0,0 +1,559 @@ +#include "features2d.h" + +AKAZE AKAZE_Create() { + // TODO: params + return new cv::Ptr(cv::AKAZE::create()); +} + +void AKAZE_Close(AKAZE a) { + delete a; +} + +struct KeyPoints AKAZE_Detect(AKAZE a, Mat src) { + std::vector detected; + (*a)->detect(*src, detected); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +struct KeyPoints AKAZE_DetectAndCompute(AKAZE a, Mat src, Mat mask, Mat desc) { + std::vector detected; + (*a)->detectAndCompute(*src, *mask, detected, *desc); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +AgastFeatureDetector AgastFeatureDetector_Create() { + // TODO: params + return new cv::Ptr(cv::AgastFeatureDetector::create()); +} + +void AgastFeatureDetector_Close(AgastFeatureDetector a) { + delete a; +} + +struct KeyPoints AgastFeatureDetector_Detect(AgastFeatureDetector a, Mat src) { + std::vector detected; + (*a)->detect(*src, detected); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +BRISK BRISK_Create() { + // TODO: params + return new cv::Ptr(cv::BRISK::create()); +} + +void BRISK_Close(BRISK b) { + delete b; +} + +struct KeyPoints BRISK_Detect(BRISK b, Mat src) { + std::vector detected; + (*b)->detect(*src, detected); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +struct KeyPoints BRISK_DetectAndCompute(BRISK b, Mat src, Mat mask, Mat desc) { + std::vector detected; + (*b)->detectAndCompute(*src, *mask, detected, *desc); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +GFTTDetector GFTTDetector_Create() { + // TODO: params + return new cv::Ptr(cv::GFTTDetector::create()); +} + +void GFTTDetector_Close(GFTTDetector a) { + delete a; +} + +struct KeyPoints GFTTDetector_Detect(GFTTDetector a, Mat src) { + std::vector detected; + (*a)->detect(*src, detected); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +KAZE KAZE_Create() { + // TODO: params + return new cv::Ptr(cv::KAZE::create()); +} + +void KAZE_Close(KAZE a) { + delete a; +} + +struct KeyPoints KAZE_Detect(KAZE a, Mat src) { + std::vector detected; + (*a)->detect(*src, detected); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +struct KeyPoints KAZE_DetectAndCompute(KAZE a, Mat src, Mat mask, Mat desc) { + std::vector detected; + (*a)->detectAndCompute(*src, *mask, detected, *desc); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +MSER MSER_Create() { + // TODO: params + return new cv::Ptr(cv::MSER::create()); +} + +void MSER_Close(MSER a) { + delete a; +} + +struct KeyPoints MSER_Detect(MSER a, Mat src) { + std::vector detected; + (*a)->detect(*src, detected); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +FastFeatureDetector FastFeatureDetector_Create() { + return new cv::Ptr(cv::FastFeatureDetector::create()); +} + +void FastFeatureDetector_Close(FastFeatureDetector f) { + delete f; +} + +FastFeatureDetector FastFeatureDetector_CreateWithParams(int threshold, bool nonmaxSuppression, int type) { + return new cv::Ptr(cv::FastFeatureDetector::create(threshold,nonmaxSuppression,static_cast(type))); +} + +struct KeyPoints FastFeatureDetector_Detect(FastFeatureDetector f, Mat src) { + std::vector detected; + (*f)->detect(*src, detected); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +ORB ORB_Create() { + return new cv::Ptr(cv::ORB::create()); +} + +ORB ORB_CreateWithParams(int nfeatures, float scaleFactor, int nlevels, int edgeThreshold, int firstLevel, int WTA_K, int scoreType, int patchSize, int fastThreshold) { + return new cv::Ptr(cv::ORB::create(nfeatures, scaleFactor, nlevels, edgeThreshold, firstLevel, WTA_K, static_cast(scoreType), patchSize, fastThreshold)); +} + +void ORB_Close(ORB o) { + delete o; +} + +struct KeyPoints ORB_Detect(ORB o, Mat src) { + std::vector detected; + (*o)->detect(*src, detected); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +struct KeyPoints ORB_DetectAndCompute(ORB o, Mat src, Mat mask, Mat desc) { + std::vector detected; + (*o)->detectAndCompute(*src, *mask, detected, *desc); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +cv::SimpleBlobDetector::Params ConvertCParamsToCPPParams(SimpleBlobDetectorParams params) { + cv::SimpleBlobDetector::Params converted; + + converted.blobColor = params.blobColor; + converted.filterByArea = params.filterByArea; + converted.filterByCircularity = params.filterByCircularity; + converted.filterByColor = params.filterByColor; + converted.filterByConvexity = params.filterByConvexity; + converted.filterByInertia = params.filterByInertia; + converted.maxArea = params.maxArea; + converted.maxCircularity = params.maxCircularity; + converted.maxConvexity = params.maxConvexity; + converted.maxInertiaRatio = params.maxInertiaRatio; + converted.maxThreshold = params.maxThreshold; + converted.minArea = params.minArea; + converted.minCircularity = params.minCircularity; + converted.minConvexity = params.minConvexity; + converted.minDistBetweenBlobs = params.minDistBetweenBlobs; + converted.minInertiaRatio = params.minInertiaRatio; + converted.minRepeatability = params.minRepeatability; + converted.minThreshold = params.minThreshold; + converted.thresholdStep = params.thresholdStep; + + return converted; +} + +SimpleBlobDetectorParams ConvertCPPParamsToCParams(cv::SimpleBlobDetector::Params params) { + SimpleBlobDetectorParams converted; + + converted.blobColor = params.blobColor; + converted.filterByArea = params.filterByArea; + converted.filterByCircularity = params.filterByCircularity; + converted.filterByColor = params.filterByColor; + converted.filterByConvexity = params.filterByConvexity; + converted.filterByInertia = params.filterByInertia; + converted.maxArea = params.maxArea; + converted.maxCircularity = params.maxCircularity; + converted.maxConvexity = params.maxConvexity; + converted.maxInertiaRatio = params.maxInertiaRatio; + converted.maxThreshold = params.maxThreshold; + converted.minArea = params.minArea; + converted.minCircularity = params.minCircularity; + converted.minConvexity = params.minConvexity; + converted.minDistBetweenBlobs = params.minDistBetweenBlobs; + converted.minInertiaRatio = params.minInertiaRatio; + converted.minRepeatability = params.minRepeatability; + converted.minThreshold = params.minThreshold; + converted.thresholdStep = params.thresholdStep; + + return converted; +} + +SimpleBlobDetector SimpleBlobDetector_Create_WithParams(SimpleBlobDetectorParams params){ + cv::SimpleBlobDetector::Params actualParams; + return new cv::Ptr(cv::SimpleBlobDetector::create(ConvertCParamsToCPPParams(params))); +} + +SimpleBlobDetector SimpleBlobDetector_Create() { + return new cv::Ptr(cv::SimpleBlobDetector::create()); +} + +SimpleBlobDetectorParams SimpleBlobDetectorParams_Create() { + return ConvertCPPParamsToCParams(cv::SimpleBlobDetector::Params()); +} + +void SimpleBlobDetector_Close(SimpleBlobDetector b) { + delete b; +} + +struct KeyPoints SimpleBlobDetector_Detect(SimpleBlobDetector b, Mat src) { + std::vector detected; + (*b)->detect(*src, detected); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +BFMatcher BFMatcher_Create() { + return new cv::Ptr(cv::BFMatcher::create()); +} + +BFMatcher BFMatcher_CreateWithParams(int normType, bool crossCheck) { + return new cv::Ptr(cv::BFMatcher::create(normType, crossCheck)); +} + +void BFMatcher_Close(BFMatcher b) { + delete b; +} + +struct MultiDMatches BFMatcher_KnnMatch(BFMatcher b, Mat query, Mat train, int k) { + std::vector< std::vector > matches; + (*b)->knnMatch(*query, *train, matches, k); + + DMatches *dms = new DMatches[matches.size()]; + for (size_t i = 0; i < matches.size(); ++i) { + DMatch *dmatches = new DMatch[matches[i].size()]; + for (size_t j = 0; j < matches[i].size(); ++j) { + DMatch dmatch = {matches[i][j].queryIdx, matches[i][j].trainIdx, matches[i][j].imgIdx, + matches[i][j].distance}; + dmatches[j] = dmatch; + } + dms[i] = {dmatches, (int) matches[i].size()}; + } + MultiDMatches ret = {dms, (int) matches.size()}; + return ret; +} + +struct MultiDMatches BFMatcher_KnnMatchWithParams(BFMatcher b, Mat query, Mat train, int k, Mat mask, bool compactResult) { + std::vector< std::vector > matches; + (*b)->knnMatch(*query, *train, matches, k, *mask, compactResult); + + DMatches *dms = new DMatches[matches.size()]; + for (size_t i = 0; i < matches.size(); ++i) { + DMatch *dmatches = new DMatch[matches[i].size()]; + for (size_t j = 0; j < matches[i].size(); ++j) { + DMatch dmatch = {matches[i][j].queryIdx, matches[i][j].trainIdx, matches[i][j].imgIdx, + matches[i][j].distance}; + dmatches[j] = dmatch; + } + dms[i] = {dmatches, (int) matches[i].size()}; + } + MultiDMatches ret = {dms, (int) matches.size()}; + return ret; +} + +FlannBasedMatcher FlannBasedMatcher_Create() { + return new cv::Ptr(cv::FlannBasedMatcher::create()); +} + +void FlannBasedMatcher_Close(FlannBasedMatcher f) { + delete f; +} + +struct MultiDMatches FlannBasedMatcher_KnnMatch(FlannBasedMatcher f, Mat query, Mat train, int k) { + std::vector< std::vector > matches; + (*f)->knnMatch(*query, *train, matches, k); + + DMatches *dms = new DMatches[matches.size()]; + for (size_t i = 0; i < matches.size(); ++i) { + DMatch *dmatches = new DMatch[matches[i].size()]; + for (size_t j = 0; j < matches[i].size(); ++j) { + DMatch dmatch = {matches[i][j].queryIdx, matches[i][j].trainIdx, matches[i][j].imgIdx, + matches[i][j].distance}; + dmatches[j] = dmatch; + } + dms[i] = {dmatches, (int) matches[i].size()}; + } + MultiDMatches ret = {dms, (int) matches.size()}; + return ret; +} + +struct MultiDMatches FlannBasedMatcher_KnnMatchWithParams(FlannBasedMatcher f, Mat query, Mat train, int k, Mat mask, bool compactResult) { + std::vector< std::vector > matches; + (*f)->knnMatch(*query, *train, matches, k, *mask, compactResult); + + DMatches *dms = new DMatches[matches.size()]; + for (size_t i = 0; i < matches.size(); ++i) { + DMatch *dmatches = new DMatch[matches[i].size()]; + for (size_t j = 0; j < matches[i].size(); ++j) { + DMatch dmatch = {matches[i][j].queryIdx, matches[i][j].trainIdx, matches[i][j].imgIdx, + matches[i][j].distance}; + dmatches[j] = dmatch; + } + dms[i] = {dmatches, (int) matches[i].size()}; + } + MultiDMatches ret = {dms, (int) matches.size()}; + return ret; +} + +void DrawKeyPoints(Mat src, struct KeyPoints kp, Mat dst, Scalar s, int flags) { + std::vector keypts; + cv::KeyPoint keypt; + + for (int i = 0; i < kp.length; ++i) { + keypt = cv::KeyPoint(kp.keypoints[i].x, kp.keypoints[i].y, + kp.keypoints[i].size, kp.keypoints[i].angle, kp.keypoints[i].response, + kp.keypoints[i].octave, kp.keypoints[i].classID); + keypts.push_back(keypt); + } + + cv::Scalar color = cv::Scalar(s.val1, s.val2, s.val3, s.val4); + + cv::drawKeypoints(*src, keypts, *dst, color, static_cast(flags)); +} + +SIFT SIFT_Create() { + // TODO: params + return new cv::Ptr(cv::SIFT::create()); +} + +void SIFT_Close(SIFT d) { + delete d; +} + +struct KeyPoints SIFT_Detect(SIFT d, Mat src) { + std::vector detected; + (*d)->detect(*src, detected); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +struct KeyPoints SIFT_DetectAndCompute(SIFT d, Mat src, Mat mask, Mat desc) { + std::vector detected; + (*d)->detectAndCompute(*src, *mask, detected, *desc); + + KeyPoint* kps = new KeyPoint[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; + } + + KeyPoints ret = {kps, (int)detected.size()}; + return ret; +} + +void DrawMatches(Mat img1, struct KeyPoints kp1, Mat img2, struct KeyPoints kp2, struct DMatches matches1to2, Mat outImg, const Scalar matchesColor, const Scalar pointColor, struct ByteArray matchesMask, int flags) { + std::vector kp1vec, kp2vec; + cv::KeyPoint keypt; + + for (int i = 0; i < kp1.length; ++i) { + keypt = cv::KeyPoint(kp1.keypoints[i].x, kp1.keypoints[i].y, + kp1.keypoints[i].size, kp1.keypoints[i].angle, kp1.keypoints[i].response, + kp1.keypoints[i].octave, kp1.keypoints[i].classID); + kp1vec.push_back(keypt); + } + + for (int i = 0; i < kp2.length; ++i) { + keypt = cv::KeyPoint(kp2.keypoints[i].x, kp2.keypoints[i].y, + kp2.keypoints[i].size, kp2.keypoints[i].angle, kp2.keypoints[i].response, + kp2.keypoints[i].octave, kp2.keypoints[i].classID); + kp2vec.push_back(keypt); + } + + cv::Scalar cvmatchescolor = cv::Scalar(matchesColor.val1, matchesColor.val2, matchesColor.val3, matchesColor.val4); + cv::Scalar cvpointcolor = cv::Scalar(pointColor.val1, pointColor.val2, pointColor.val3, pointColor.val4); + + std::vector dmatchvec; + cv::DMatch dm; + + for (int i = 0; i < matches1to2.length; i++) { + dm = cv::DMatch(matches1to2.dmatches[i].queryIdx, matches1to2.dmatches[i].trainIdx, + matches1to2.dmatches[i].imgIdx, matches1to2.dmatches[i].distance); + dmatchvec.push_back(dm); + } + + std::vector maskvec; + + for (int i = 0; i < matchesMask.length; i++) { + maskvec.push_back(matchesMask.data[i]); + } + + cv::drawMatches(*img1, kp1vec, *img2, kp2vec, dmatchvec, *outImg, cvmatchescolor, cvpointcolor, maskvec, static_cast(flags)); +} diff --git a/vendor/gocv.io/x/gocv/features2d.go b/vendor/gocv.io/x/gocv/features2d.go new file mode 100644 index 00000000..162b604f --- /dev/null +++ b/vendor/gocv.io/x/gocv/features2d.go @@ -0,0 +1,941 @@ +package gocv + +/* +#include +#include "features2d.h" +*/ +import "C" +import ( + "image/color" + "reflect" + "unsafe" +) + +// AKAZE is a wrapper around the cv::AKAZE algorithm. +type AKAZE struct { + // C.AKAZE + p unsafe.Pointer +} + +// NewAKAZE returns a new AKAZE algorithm +// +// For further details, please see: +// https://docs.opencv.org/master/d8/d30/classcv_1_1AKAZE.html +// +func NewAKAZE() AKAZE { + return AKAZE{p: unsafe.Pointer(C.AKAZE_Create())} +} + +// Close AKAZE. +func (a *AKAZE) Close() error { + C.AKAZE_Close((C.AKAZE)(a.p)) + a.p = nil + return nil +} + +// Detect keypoints in an image using AKAZE. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887 +// +func (a *AKAZE) Detect(src Mat) []KeyPoint { + ret := C.AKAZE_Detect((C.AKAZE)(a.p), src.p) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret) +} + +// DetectAndCompute keypoints and compute in an image using AKAZE. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#a8be0d1c20b08eb867184b8d74c15a677 +// +func (a *AKAZE) DetectAndCompute(src Mat, mask Mat) ([]KeyPoint, Mat) { + desc := NewMat() + ret := C.AKAZE_DetectAndCompute((C.AKAZE)(a.p), src.p, mask.p, desc.p) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret), desc +} + +// AgastFeatureDetector is a wrapper around the cv::AgastFeatureDetector. +type AgastFeatureDetector struct { + // C.AgastFeatureDetector + p unsafe.Pointer +} + +// NewAgastFeatureDetector returns a new AgastFeatureDetector algorithm +// +// For further details, please see: +// https://docs.opencv.org/master/d7/d19/classcv_1_1AgastFeatureDetector.html +// +func NewAgastFeatureDetector() AgastFeatureDetector { + return AgastFeatureDetector{p: unsafe.Pointer(C.AgastFeatureDetector_Create())} +} + +// Close AgastFeatureDetector. +func (a *AgastFeatureDetector) Close() error { + C.AgastFeatureDetector_Close((C.AgastFeatureDetector)(a.p)) + a.p = nil + return nil +} + +// Detect keypoints in an image using AgastFeatureDetector. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887 +// +func (a *AgastFeatureDetector) Detect(src Mat) []KeyPoint { + ret := C.AgastFeatureDetector_Detect((C.AgastFeatureDetector)(a.p), src.p) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret) +} + +// BRISK is a wrapper around the cv::BRISK algorithm. +type BRISK struct { + // C.BRISK + p unsafe.Pointer +} + +// NewBRISK returns a new BRISK algorithm +// +// For further details, please see: +// https://docs.opencv.org/master/d8/d30/classcv_1_1AKAZE.html +// +func NewBRISK() BRISK { + return BRISK{p: unsafe.Pointer(C.BRISK_Create())} +} + +// Close BRISK. +func (b *BRISK) Close() error { + C.BRISK_Close((C.BRISK)(b.p)) + b.p = nil + return nil +} + +// Detect keypoints in an image using BRISK. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887 +// +func (b *BRISK) Detect(src Mat) []KeyPoint { + ret := C.BRISK_Detect((C.BRISK)(b.p), src.p) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret) +} + +// DetectAndCompute keypoints and compute in an image using BRISK. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#a8be0d1c20b08eb867184b8d74c15a677 +// +func (b *BRISK) DetectAndCompute(src Mat, mask Mat) ([]KeyPoint, Mat) { + desc := NewMat() + ret := C.BRISK_DetectAndCompute((C.BRISK)(b.p), src.p, mask.p, desc.p) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret), desc +} + +// FastFeatureDetectorType defines the detector type +// +// For further details, please see: +// https://docs.opencv.org/master/df/d74/classcv_1_1FastFeatureDetector.html#a4654f6fb0aa4b8e9123b223bfa0e2a08 +type FastFeatureDetectorType int + +const ( + //FastFeatureDetectorType58 is an alias of FastFeatureDetector::TYPE_5_8 + FastFeatureDetectorType58 FastFeatureDetectorType = 0 + //FastFeatureDetectorType712 is an alias of FastFeatureDetector::TYPE_7_12 + FastFeatureDetectorType712 FastFeatureDetectorType = 1 + //FastFeatureDetectorType916 is an alias of FastFeatureDetector::TYPE_9_16 + FastFeatureDetectorType916 FastFeatureDetectorType = 2 +) + +// FastFeatureDetector is a wrapper around the cv::FastFeatureDetector. +type FastFeatureDetector struct { + // C.FastFeatureDetector + p unsafe.Pointer +} + +// NewFastFeatureDetector returns a new FastFeatureDetector algorithm +// +// For further details, please see: +// https://docs.opencv.org/master/df/d74/classcv_1_1FastFeatureDetector.html +// +func NewFastFeatureDetector() FastFeatureDetector { + return FastFeatureDetector{p: unsafe.Pointer(C.FastFeatureDetector_Create())} +} + +// NewFastFeatureDetectorWithParams returns a new FastFeatureDetector algorithm with parameters +// +// For further details, please see: +// https://docs.opencv.org/master/df/d74/classcv_1_1FastFeatureDetector.html#ab986f2ff8f8778aab1707e2642bc7f8e +// +func NewFastFeatureDetectorWithParams(threshold int, nonmaxSuppression bool, typ FastFeatureDetectorType) FastFeatureDetector { + return FastFeatureDetector{p: unsafe.Pointer(C.FastFeatureDetector_CreateWithParams(C.int(threshold), C.bool(nonmaxSuppression), C.int(typ)))} +} + +// Close FastFeatureDetector. +func (f *FastFeatureDetector) Close() error { + C.FastFeatureDetector_Close((C.FastFeatureDetector)(f.p)) + f.p = nil + return nil +} + +// Detect keypoints in an image using FastFeatureDetector. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887 +// +func (f *FastFeatureDetector) Detect(src Mat) []KeyPoint { + ret := C.FastFeatureDetector_Detect((C.FastFeatureDetector)(f.p), src.p) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret) +} + +// GFTTDetector is a wrapper around the cv::GFTTDetector algorithm. +type GFTTDetector struct { + // C.GFTTDetector + p unsafe.Pointer +} + +// NewGFTTDetector returns a new GFTTDetector algorithm +// +// For further details, please see: +// https://docs.opencv.org/master/df/d21/classcv_1_1GFTTDetector.html +// +func NewGFTTDetector() GFTTDetector { + return GFTTDetector{p: unsafe.Pointer(C.GFTTDetector_Create())} +} + +// Close GFTTDetector. +func (a *GFTTDetector) Close() error { + C.GFTTDetector_Close((C.GFTTDetector)(a.p)) + a.p = nil + return nil +} + +// Detect keypoints in an image using GFTTDetector. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887 +// +func (a *GFTTDetector) Detect(src Mat) []KeyPoint { + ret := C.GFTTDetector_Detect((C.GFTTDetector)(a.p), src.p) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret) +} + +// KAZE is a wrapper around the cv::KAZE algorithm. +type KAZE struct { + // C.KAZE + p unsafe.Pointer +} + +// NewKAZE returns a new KAZE algorithm +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d61/classcv_1_1KAZE.html +// +func NewKAZE() KAZE { + return KAZE{p: unsafe.Pointer(C.KAZE_Create())} +} + +// Close KAZE. +func (a *KAZE) Close() error { + C.KAZE_Close((C.KAZE)(a.p)) + a.p = nil + return nil +} + +// Detect keypoints in an image using KAZE. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887 +// +func (a *KAZE) Detect(src Mat) []KeyPoint { + ret := C.KAZE_Detect((C.KAZE)(a.p), src.p) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret) +} + +// DetectAndCompute keypoints and compute in an image using KAZE. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#a8be0d1c20b08eb867184b8d74c15a677 +// +func (a *KAZE) DetectAndCompute(src Mat, mask Mat) ([]KeyPoint, Mat) { + desc := NewMat() + ret := C.KAZE_DetectAndCompute((C.KAZE)(a.p), src.p, mask.p, desc.p) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret), desc +} + +// MSER is a wrapper around the cv::MSER algorithm. +type MSER struct { + // C.MSER + p unsafe.Pointer +} + +// NewMSER returns a new MSER algorithm +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d28/classcv_1_1MSER.html +// +func NewMSER() MSER { + return MSER{p: unsafe.Pointer(C.MSER_Create())} +} + +// Close MSER. +func (a *MSER) Close() error { + C.MSER_Close((C.MSER)(a.p)) + a.p = nil + return nil +} + +// Detect keypoints in an image using MSER. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887 +// +func (a *MSER) Detect(src Mat) []KeyPoint { + ret := C.MSER_Detect((C.MSER)(a.p), src.p) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret) +} + +// ORB is a wrapper around the cv::ORB. +type ORB struct { + // C.ORB + p unsafe.Pointer +} + +// NewORB returns a new ORB algorithm +// +// For further details, please see: +// https://docs.opencv.org/master/db/d95/classcv_1_1ORB.html +// +func NewORB() ORB { + return ORB{p: unsafe.Pointer(C.ORB_Create())} +} + +// NewORBWithParams returns a new ORB algorithm with parameters +// +// For further details, please see: +// https://docs.opencv.org/master/db/d95/classcv_1_1ORB.html#aeff0cbe668659b7ca14bb85ff1c4073b +// +func NewORBWithParams(nFeatures int, scaleFactor float32, nLevels int, edgeThreshold int, firstLevel int, WTAK int, scoreType ORBScoreType, patchSize int, fastThreshold int) ORB { + return ORB{p: unsafe.Pointer(C.ORB_CreateWithParams( + C.int(nFeatures), + C.float(scaleFactor), + C.int(nLevels), + C.int(edgeThreshold), + C.int(firstLevel), + C.int(WTAK), + C.int(scoreType), + C.int(patchSize), + C.int(fastThreshold), + ))} +} + +type ORBScoreType int + +const ( + ORBScoreTypeHarris ORBScoreType = 0 + ORBScoreTypeFAST ORBScoreType = 1 +) + +// Close ORB. +func (o *ORB) Close() error { + C.ORB_Close((C.ORB)(o.p)) + o.p = nil + return nil +} + +// Detect keypoints in an image using ORB. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887 +// +func (o *ORB) Detect(src Mat) []KeyPoint { + ret := C.ORB_Detect((C.ORB)(o.p), src.p) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret) +} + +// DetectAndCompute detects keypoints and computes from an image using ORB. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#a8be0d1c20b08eb867184b8d74c15a677 +// +func (o *ORB) DetectAndCompute(src Mat, mask Mat) ([]KeyPoint, Mat) { + desc := NewMat() + ret := C.ORB_DetectAndCompute((C.ORB)(o.p), src.p, mask.p, desc.p) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret), desc +} + +// SimpleBlobDetector is a wrapper around the cv::SimpleBlobDetector. +type SimpleBlobDetector struct { + // C.SimpleBlobDetector + p unsafe.Pointer +} + +// SimpleBlobDetector_Params is a wrapper around the cv::SimpleBlobdetector::Params +type SimpleBlobDetectorParams struct { + p C.SimpleBlobDetectorParams +} + +// NewSimpleBlobDetector returns a new SimpleBlobDetector algorithm +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d7a/classcv_1_1SimpleBlobDetector.html +// +func NewSimpleBlobDetector() SimpleBlobDetector { + return SimpleBlobDetector{p: unsafe.Pointer(C.SimpleBlobDetector_Create())} +} + +// NewSimpleBlobDetectorWithParams returns a new SimpleBlobDetector with custom parameters +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d7a/classcv_1_1SimpleBlobDetector.html +// +func NewSimpleBlobDetectorWithParams(params SimpleBlobDetectorParams) SimpleBlobDetector { + return SimpleBlobDetector{p: unsafe.Pointer(C.SimpleBlobDetector_Create_WithParams(params.p))} +} + +// Close SimpleBlobDetector. +func (b *SimpleBlobDetector) Close() error { + C.SimpleBlobDetector_Close((C.SimpleBlobDetector)(b.p)) + b.p = nil + return nil +} + +// NewSimpleBlobDetectorParams returns the default parameters for the SimpleBobDetector +func NewSimpleBlobDetectorParams() SimpleBlobDetectorParams { + return SimpleBlobDetectorParams{p: C.SimpleBlobDetectorParams_Create()} +} + +// SetBlobColor sets the blobColor field +func (p *SimpleBlobDetectorParams) SetBlobColor(blobColor int) { + p.p.blobColor = C.uchar(blobColor) +} + +// GetBlobColor gets the blobColor field +func (p *SimpleBlobDetectorParams) GetBlobColor() int { + return int(p.p.blobColor) +} + +// SetFilterByArea sets the filterByArea field +func (p *SimpleBlobDetectorParams) SetFilterByArea(filterByArea bool) { + p.p.filterByArea = C.bool(filterByArea) +} + +// GetFilterByArea gets the filterByArea field +func (p *SimpleBlobDetectorParams) GetFilterByArea() bool { + return bool(p.p.filterByArea) +} + +// SetFilterByCircularity sets the filterByCircularity field +func (p *SimpleBlobDetectorParams) SetFilterByCircularity(filterByCircularity bool) { + p.p.filterByCircularity = C.bool(filterByCircularity) +} + +// GetFilterByCircularity gets the filterByCircularity field +func (p *SimpleBlobDetectorParams) GetFilterByCircularity() bool { + return bool(p.p.filterByCircularity) +} + +// SetFilterByColor sets the filterByColor field +func (p *SimpleBlobDetectorParams) SetFilterByColor(filterByColor bool) { + p.p.filterByColor = C.bool(filterByColor) +} + +// GetFilterByColor gets the filterByColor field +func (p *SimpleBlobDetectorParams) GetFilterByColor() bool { + return bool(p.p.filterByColor) +} + +// SetFilterByConvexity sets the filterByConvexity field +func (p *SimpleBlobDetectorParams) SetFilterByConvexity(filterByConvexity bool) { + p.p.filterByConvexity = C.bool(filterByConvexity) +} + +// GetFilterByConvexity gets the filterByConvexity field +func (p *SimpleBlobDetectorParams) GetFilterByConvexity() bool { + return bool(p.p.filterByConvexity) +} + +// SetFilterByInertia sets the filterByInertia field +func (p *SimpleBlobDetectorParams) SetFilterByInertia(filterByInertia bool) { + p.p.filterByInertia = C.bool(filterByInertia) +} + +// GetFilterByInertia gets the filterByInertia field +func (p *SimpleBlobDetectorParams) GetFilterByInertia() bool { + return bool(p.p.filterByInertia) +} + +// SetMaxArea sets the maxArea parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) SetMaxArea(maxArea float64) { + p.p.maxArea = C.float(maxArea) +} + +// GetMaxArea sets the maxArea parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) GetMaxArea() float64 { + return float64(p.p.maxArea) +} + +// SetMaxCircularity sets the maxCircularity parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) SetMaxCircularity(maxCircularity float64) { + p.p.maxCircularity = C.float(maxCircularity) +} + +// GetMaxCircularity sets the maxCircularity parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) GetMaxCircularity() float64 { + return float64(p.p.maxCircularity) +} + +// SetMaxConvexity sets the maxConvexity parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) SetMaxConvexity(maxConvexity float64) { + p.p.maxConvexity = C.float(maxConvexity) +} + +// GetMaxConvexity sets the maxConvexity parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) GetMaxConvexity() float64 { + return float64(p.p.maxConvexity) +} + +// SetMaxInertiaRatio sets the maxInertiaRatio parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) SetMaxInertiaRatio(maxInertiaRatio float64) { + p.p.maxInertiaRatio = C.float(maxInertiaRatio) +} + +// GetMaxInertiaRatio sets the maxCConvexity parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) GetMaxInertiaRatio() float64 { + return float64(p.p.maxInertiaRatio) +} + +// SetMaxThreshold sets the maxThreshold parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) SetMaxThreshold(maxThreshold float64) { + p.p.maxThreshold = C.float(maxThreshold) +} + +// GetMaxThreshold sets the maxCConvexity parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) GetMaxThreshold() float64 { + return float64(p.p.maxThreshold) +} + +// SetMinArea sets the minArea parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) SetMinArea(minArea float64) { + p.p.minArea = C.float(minArea) +} + +// GetMinArea sets theinArea parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) GetMinArea() float64 { + return float64(p.p.minArea) +} + +// SetMinCircularity sets the minCircularity parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) SetMinCircularity(minCircularity float64) { + p.p.minCircularity = C.float(minCircularity) +} + +// GetMinCircularity sets the minCircularity parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) GetMinCircularity() float64 { + return float64(p.p.minCircularity) +} + +// SetMinConvexity sets the minConvexity parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) SetMinConvexity(minConvexity float64) { + p.p.minConvexity = C.float(minConvexity) +} + +// GetMinConvexity sets the minConvexity parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) GetMinConvexity() float64 { + return float64(p.p.minConvexity) +} + +// SetMinDistBetweenBlobs sets the minDistBetweenBlobs parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) SetMinDistBetweenBlobs(minDistBetweenBlobs float64) { + p.p.minDistBetweenBlobs = C.float(minDistBetweenBlobs) +} + +// GetMinDistBetweenBlobs sets the minDistBetweenBlobs parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) GetMinDistBetweenBlobs() float64 { + return float64(p.p.minDistBetweenBlobs) +} + +// SetMinInertiaRatio sets the minInertiaRatio parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) SetMinInertiaRatio(minInertiaRatio float64) { + p.p.minInertiaRatio = C.float(minInertiaRatio) +} + +// GetMinInertiaRatio sets the minInertiaRatio parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) GetMinInertiaRatio() float64 { + return float64(p.p.minInertiaRatio) +} + +// SetMinRepeatability sets the minRepeatability parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) SetMinRepeatability(minRepeatability int) { + p.p.minRepeatability = C.size_t(minRepeatability) +} + +// GetMinInertiaRatio sets the minRepeatability parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) GetMinRepeatability() int { + return int(p.p.minRepeatability) +} + +// SetMinThreshold sets the minThreshold parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) SetMinThreshold(minThreshold float64) { + p.p.minThreshold = C.float(minThreshold) +} + +// GetMinThreshold sets the minInertiaRatio parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) GetMinThreshold() float64 { + return float64(p.p.minThreshold) +} + +// SetMinThreshold sets the minThreshold parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) SetThresholdStep(thresholdStep float64) { + p.p.thresholdStep = C.float(thresholdStep) +} + +// GetMinThreshold sets the minInertiaRatio parameter for SimpleBlobDetector_Params +func (p *SimpleBlobDetectorParams) GetThresholdStep() float64 { + return float64(p.p.thresholdStep) +} + +// Detect keypoints in an image using SimpleBlobDetector. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887 +// +func (b *SimpleBlobDetector) Detect(src Mat) []KeyPoint { + ret := C.SimpleBlobDetector_Detect((C.SimpleBlobDetector)(b.p), src.p) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret) +} + +// getKeyPoints returns a slice of KeyPoint given a pointer to a C.KeyPoints +func getKeyPoints(ret C.KeyPoints) []KeyPoint { + cArray := ret.keypoints + length := int(ret.length) + hdr := reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(cArray)), + Len: length, + Cap: length, + } + s := *(*[]C.KeyPoint)(unsafe.Pointer(&hdr)) + + keys := make([]KeyPoint, length) + for i, r := range s { + keys[i] = KeyPoint{float64(r.x), float64(r.y), float64(r.size), float64(r.angle), float64(r.response), + int(r.octave), int(r.classID)} + } + return keys +} + +// BFMatcher is a wrapper around the the cv::BFMatcher algorithm +type BFMatcher struct { + // C.BFMatcher + p unsafe.Pointer +} + +// NewBFMatcher returns a new BFMatcher +// +// For further details, please see: +// https://docs.opencv.org/master/d3/da1/classcv_1_1BFMatcher.html#abe0bb11749b30d97f60d6ade665617bd +// +func NewBFMatcher() BFMatcher { + return BFMatcher{p: unsafe.Pointer(C.BFMatcher_Create())} +} + +// NewBFMatcherWithParams creates a new BFMatchers but allows setting parameters +// to values other than just the defaults. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/da1/classcv_1_1BFMatcher.html#abe0bb11749b30d97f60d6ade665617bd +// +func NewBFMatcherWithParams(normType NormType, crossCheck bool) BFMatcher { + return BFMatcher{p: unsafe.Pointer(C.BFMatcher_CreateWithParams(C.int(normType), C.bool(crossCheck)))} +} + +// Close BFMatcher +func (b *BFMatcher) Close() error { + C.BFMatcher_Close((C.BFMatcher)(b.p)) + b.p = nil + return nil +} + +// KnnMatch Finds the k best matches for each descriptor from a query set. +// +// For further details, please see: +// https://docs.opencv.org/master/db/d39/classcv_1_1DescriptorMatcher.html#aa880f9353cdf185ccf3013e08210483a +// +func (b *BFMatcher) KnnMatch(query, train Mat, k int) [][]DMatch { + ret := C.BFMatcher_KnnMatch((C.BFMatcher)(b.p), query.p, train.p, C.int(k)) + defer C.MultiDMatches_Close(ret) + + return getMultiDMatches(ret) +} + +// FlannBasedMatcher is a wrapper around the the cv::FlannBasedMatcher algorithm +type FlannBasedMatcher struct { + // C.FlannBasedMatcher + p unsafe.Pointer +} + +// NewFlannBasedMatcher returns a new FlannBasedMatcher +// +// For further details, please see: +// https://docs.opencv.org/master/dc/de2/classcv_1_1FlannBasedMatcher.html#ab9114a6471e364ad221f89068ca21382 +// +func NewFlannBasedMatcher() FlannBasedMatcher { + return FlannBasedMatcher{p: unsafe.Pointer(C.FlannBasedMatcher_Create())} +} + +// Close FlannBasedMatcher +func (f *FlannBasedMatcher) Close() error { + C.FlannBasedMatcher_Close((C.FlannBasedMatcher)(f.p)) + f.p = nil + return nil +} + +// KnnMatch Finds the k best matches for each descriptor from a query set. +// +// For further details, please see: +// https://docs.opencv.org/master/db/d39/classcv_1_1DescriptorMatcher.html#aa880f9353cdf185ccf3013e08210483a +// +func (f *FlannBasedMatcher) KnnMatch(query, train Mat, k int) [][]DMatch { + ret := C.FlannBasedMatcher_KnnMatch((C.FlannBasedMatcher)(f.p), query.p, train.p, C.int(k)) + defer C.MultiDMatches_Close(ret) + + return getMultiDMatches(ret) +} + +func getMultiDMatches(ret C.MultiDMatches) [][]DMatch { + cArray := ret.dmatches + length := int(ret.length) + hdr := reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(cArray)), + Len: length, + Cap: length, + } + s := *(*[]C.DMatches)(unsafe.Pointer(&hdr)) + + keys := make([][]DMatch, length) + for i := range s { + keys[i] = getDMatches(C.MultiDMatches_get(ret, C.int(i))) + } + return keys +} + +func getDMatches(ret C.DMatches) []DMatch { + cArray := ret.dmatches + length := int(ret.length) + hdr := reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(cArray)), + Len: length, + Cap: length, + } + s := *(*[]C.DMatch)(unsafe.Pointer(&hdr)) + + keys := make([]DMatch, length) + for i, r := range s { + keys[i] = DMatch{int(r.queryIdx), int(r.trainIdx), int(r.imgIdx), + float64(r.distance)} + } + return keys +} + +// DrawMatchesFlag are the flags setting drawing feature +// +// For further details please see: +// https://docs.opencv.org/master/de/d30/structcv_1_1DrawMatchesFlags.html +type DrawMatchesFlag int + +const ( + // DrawDefault creates new image and for each keypoint only the center point will be drawn + DrawDefault DrawMatchesFlag = 0 + // DrawOverOutImg draws matches on existing content of image + DrawOverOutImg DrawMatchesFlag = 1 + // NotDrawSinglePoints will not draw single points + NotDrawSinglePoints DrawMatchesFlag = 2 + // DrawRichKeyPoints draws the circle around each keypoint with keypoint size and orientation + DrawRichKeyPoints DrawMatchesFlag = 3 +) + +// DrawKeyPoints draws keypoints +// +// For further details please see: +// https://docs.opencv.org/master/d4/d5d/group__features2d__draw.html#gab958f8900dd10f14316521c149a60433 +func DrawKeyPoints(src Mat, keyPoints []KeyPoint, dst *Mat, color color.RGBA, flag DrawMatchesFlag) { + cKeyPointArray := make([]C.struct_KeyPoint, len(keyPoints)) + + for i, kp := range keyPoints { + cKeyPointArray[i].x = C.double(kp.X) + cKeyPointArray[i].y = C.double(kp.Y) + cKeyPointArray[i].size = C.double(kp.Size) + cKeyPointArray[i].angle = C.double(kp.Angle) + cKeyPointArray[i].response = C.double(kp.Response) + cKeyPointArray[i].octave = C.int(kp.Octave) + cKeyPointArray[i].classID = C.int(kp.ClassID) + } + + cKeyPoints := C.struct_KeyPoints{ + keypoints: (*C.struct_KeyPoint)(&cKeyPointArray[0]), + length: (C.int)(len(keyPoints)), + } + + scalar := C.struct_Scalar{ + val1: C.double(color.B), + val2: C.double(color.G), + val3: C.double(color.R), + val4: C.double(color.A), + } + + C.DrawKeyPoints(src.p, cKeyPoints, dst.p, scalar, C.int(flag)) +} + +// SIFT is a wrapper around the cv::SIFT algorithm. +// Due to the patent having expired, this is now in the main OpenCV code modules. +type SIFT struct { + // C.SIFT + p unsafe.Pointer +} + +// NewSIFT returns a new SIFT algorithm. +// +// For further details, please see: +// https://docs.opencv.org/master/d5/d3c/classcv_1_1xfeatures2d_1_1SIFT.html +// +func NewSIFT() SIFT { + return SIFT{p: unsafe.Pointer(C.SIFT_Create())} +} + +// Close SIFT. +func (d *SIFT) Close() error { + C.SIFT_Close((C.SIFT)(d.p)) + d.p = nil + return nil +} + +// Detect keypoints in an image using SIFT. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#aa4e9a7082ec61ebc108806704fbd7887 +// +func (d *SIFT) Detect(src Mat) []KeyPoint { + ret := C.SIFT_Detect((C.SIFT)(d.p), C.Mat(src.Ptr())) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret) +} + +// DetectAndCompute detects and computes keypoints in an image using SIFT. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d13/classcv_1_1Feature2D.html#a8be0d1c20b08eb867184b8d74c15a677 +// +func (d *SIFT) DetectAndCompute(src Mat, mask Mat) ([]KeyPoint, Mat) { + desc := NewMat() + ret := C.SIFT_DetectAndCompute((C.SIFT)(d.p), C.Mat(src.Ptr()), C.Mat(mask.Ptr()), + C.Mat(desc.Ptr())) + defer C.KeyPoints_Close(ret) + + return getKeyPoints(ret), desc +} + +// DrawMatches draws matches on combined train and querry images. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d5d/group__features2d__draw.html#gad8f463ccaf0dc6f61083abd8717c261a +func DrawMatches(img1 Mat, kp1 []KeyPoint, img2 Mat, kp2 []KeyPoint, matches1to2 []DMatch, outImg *Mat, matchColor color.RGBA, singlePointColor color.RGBA, matchesMask []byte, flags DrawMatchesFlag) { + kp1arr := make([]C.struct_KeyPoint, len(kp1)) + kp2arr := make([]C.struct_KeyPoint, len(kp2)) + + for i, kp := range kp1 { + kp1arr[i].x = C.double(kp.X) + kp1arr[i].y = C.double(kp.Y) + kp1arr[i].size = C.double(kp.Size) + kp1arr[i].angle = C.double(kp.Angle) + kp1arr[i].response = C.double(kp.Response) + kp1arr[i].octave = C.int(kp.Octave) + kp1arr[i].classID = C.int(kp.ClassID) + } + + for i, kp := range kp2 { + kp2arr[i].x = C.double(kp.X) + kp2arr[i].y = C.double(kp.Y) + kp2arr[i].size = C.double(kp.Size) + kp2arr[i].angle = C.double(kp.Angle) + kp2arr[i].response = C.double(kp.Response) + kp2arr[i].octave = C.int(kp.Octave) + kp2arr[i].classID = C.int(kp.ClassID) + } + + cKeyPoints1 := C.struct_KeyPoints{ + keypoints: (*C.struct_KeyPoint)(&kp1arr[0]), + length: (C.int)(len(kp1)), + } + + cKeyPoints2 := C.struct_KeyPoints{ + keypoints: (*C.struct_KeyPoint)(&kp2arr[0]), + length: (C.int)(len(kp2)), + } + + dMatchArr := make([]C.struct_DMatch, len(matches1to2)) + + for i, dm := range matches1to2 { + dMatchArr[i].queryIdx = C.int(dm.QueryIdx) + dMatchArr[i].trainIdx = C.int(dm.TrainIdx) + dMatchArr[i].imgIdx = C.int(dm.ImgIdx) + dMatchArr[i].distance = C.float(dm.Distance) + } + + cDMatches := C.struct_DMatches{ + dmatches: (*C.struct_DMatch)(&dMatchArr[0]), + length: (C.int)(len(matches1to2)), + } + + scalarMatchColor := C.struct_Scalar{ + val1: C.double(matchColor.R), + val2: C.double(matchColor.G), + val3: C.double(matchColor.B), + val4: C.double(matchColor.A), + } + + scalarPointColor := C.struct_Scalar{ + val1: C.double(singlePointColor.B), + val2: C.double(singlePointColor.G), + val3: C.double(singlePointColor.R), + val4: C.double(singlePointColor.A), + } + + mask := make([]C.char, len(matchesMask)) + + cByteArray := C.struct_ByteArray{ + length: (C.int)(len(matchesMask)), + } + + if len(matchesMask) > 0 { + cByteArray = C.struct_ByteArray{ + data: (*C.char)(&mask[0]), + length: (C.int)(len(matchesMask)), + } + } + + C.DrawMatches(img1.p, cKeyPoints1, img2.p, cKeyPoints2, cDMatches, outImg.p, scalarMatchColor, scalarPointColor, cByteArray, C.int(flags)) +} diff --git a/vendor/gocv.io/x/gocv/features2d.h b/vendor/gocv.io/x/gocv/features2d.h new file mode 100644 index 00000000..b6a9c4fc --- /dev/null +++ b/vendor/gocv.io/x/gocv/features2d.h @@ -0,0 +1,105 @@ +#ifndef _OPENCV3_FEATURES2D_H_ +#define _OPENCV3_FEATURES2D_H_ + +#ifdef __cplusplus +#include +extern "C" { +#endif + +#include "core.h" + +#ifdef __cplusplus +typedef cv::Ptr* AKAZE; +typedef cv::Ptr* AgastFeatureDetector; +typedef cv::Ptr* BRISK; +typedef cv::Ptr* FastFeatureDetector; +typedef cv::Ptr* GFTTDetector; +typedef cv::Ptr* KAZE; +typedef cv::Ptr* MSER; +typedef cv::Ptr* ORB; +typedef cv::Ptr* SimpleBlobDetector; +typedef cv::Ptr* BFMatcher; +typedef cv::Ptr* FlannBasedMatcher; +typedef cv::Ptr* SIFT; +#else +typedef void* AKAZE; +typedef void* AgastFeatureDetector; +typedef void* BRISK; +typedef void* FastFeatureDetector; +typedef void* GFTTDetector; +typedef void* KAZE; +typedef void* MSER; +typedef void* ORB; +typedef void* SimpleBlobDetector; +typedef void* BFMatcher; +typedef void* FlannBasedMatcher; +typedef void* SIFT; +#endif + +AKAZE AKAZE_Create(); +void AKAZE_Close(AKAZE a); +struct KeyPoints AKAZE_Detect(AKAZE a, Mat src); +struct KeyPoints AKAZE_DetectAndCompute(AKAZE a, Mat src, Mat mask, Mat desc); + +AgastFeatureDetector AgastFeatureDetector_Create(); +void AgastFeatureDetector_Close(AgastFeatureDetector a); +struct KeyPoints AgastFeatureDetector_Detect(AgastFeatureDetector a, Mat src); + +BRISK BRISK_Create(); +void BRISK_Close(BRISK b); +struct KeyPoints BRISK_Detect(BRISK b, Mat src); +struct KeyPoints BRISK_DetectAndCompute(BRISK b, Mat src, Mat mask, Mat desc); + +FastFeatureDetector FastFeatureDetector_Create(); +FastFeatureDetector FastFeatureDetector_CreateWithParams(int threshold, bool nonmaxSuppression, int type); +void FastFeatureDetector_Close(FastFeatureDetector f); +struct KeyPoints FastFeatureDetector_Detect(FastFeatureDetector f, Mat src); + +GFTTDetector GFTTDetector_Create(); +void GFTTDetector_Close(GFTTDetector a); +struct KeyPoints GFTTDetector_Detect(GFTTDetector a, Mat src); + +KAZE KAZE_Create(); +void KAZE_Close(KAZE a); +struct KeyPoints KAZE_Detect(KAZE a, Mat src); +struct KeyPoints KAZE_DetectAndCompute(KAZE a, Mat src, Mat mask, Mat desc); + +MSER MSER_Create(); +void MSER_Close(MSER a); +struct KeyPoints MSER_Detect(MSER a, Mat src); + +ORB ORB_Create(); +ORB ORB_CreateWithParams(int nfeatures, float scaleFactor, int nlevels, int edgeThreshold, int firstLevel, int WTA_K, int scoreType, int patchSize, int fastThreshold); +void ORB_Close(ORB o); +struct KeyPoints ORB_Detect(ORB o, Mat src); +struct KeyPoints ORB_DetectAndCompute(ORB o, Mat src, Mat mask, Mat desc); + +SimpleBlobDetector SimpleBlobDetector_Create(); +SimpleBlobDetector SimpleBlobDetector_Create_WithParams(SimpleBlobDetectorParams params); +void SimpleBlobDetector_Close(SimpleBlobDetector b); +struct KeyPoints SimpleBlobDetector_Detect(SimpleBlobDetector b, Mat src); +SimpleBlobDetectorParams SimpleBlobDetectorParams_Create(); + +BFMatcher BFMatcher_Create(); +BFMatcher BFMatcher_CreateWithParams(int normType, bool crossCheck); +void BFMatcher_Close(BFMatcher b); +struct MultiDMatches BFMatcher_KnnMatch(BFMatcher b, Mat query, Mat train, int k); + +FlannBasedMatcher FlannBasedMatcher_Create(); +void FlannBasedMatcher_Close(FlannBasedMatcher f); +struct MultiDMatches FlannBasedMatcher_KnnMatch(FlannBasedMatcher f, Mat query, Mat train, int k); + +void DrawKeyPoints(Mat src, struct KeyPoints kp, Mat dst, const Scalar s, int flags); + +SIFT SIFT_Create(); +void SIFT_Close(SIFT f); +struct KeyPoints SIFT_Detect(SIFT f, Mat src); +struct KeyPoints SIFT_DetectAndCompute(SIFT f, Mat src, Mat mask, Mat desc); + +void DrawMatches(Mat img1, struct KeyPoints kp1, Mat img2, struct KeyPoints kp2, struct DMatches matches1to2, Mat outImg, const Scalar matchesColor, const Scalar pointColor, struct ByteArray matchesMask, int flags); + +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_FEATURES2D_H_ diff --git a/vendor/gocv.io/x/gocv/features2d_string.go b/vendor/gocv.io/x/gocv/features2d_string.go new file mode 100644 index 00000000..21637c6e --- /dev/null +++ b/vendor/gocv.io/x/gocv/features2d_string.go @@ -0,0 +1,33 @@ +package gocv + +/* +#include +#include "features2d.h" +*/ +import "C" + +func (c FastFeatureDetectorType) String() string { + switch c { + case FastFeatureDetectorType58: + return "fast-feature-detector-type-58" + case FastFeatureDetectorType712: + return "fast-feature-detector-type-712" + case FastFeatureDetectorType916: + return "fast-feature-detector-type-916" + } + return "" +} + +func (c DrawMatchesFlag) String() string { + switch c { + case DrawDefault: + return "draw-default" + case DrawOverOutImg: + return "draw-over-out-imt" + case NotDrawSinglePoints: + return "draw-single-points" + case DrawRichKeyPoints: + return "draw-rich-key-points" + } + return "" +} diff --git a/vendor/gocv.io/x/gocv/gocv.go b/vendor/gocv.io/x/gocv/gocv.go new file mode 100644 index 00000000..c3b01260 --- /dev/null +++ b/vendor/gocv.io/x/gocv/gocv.go @@ -0,0 +1,11 @@ +// Package gocv is a wrapper around the OpenCV 4.x computer vision library. +// It provides a Go language interface to the latest version of OpenCV. +// +// OpenCV (Open Source Computer Vision Library: http://opencv.org) is an +// open-source BSD-licensed library that includes several hundreds of +// computer vision algorithms. +// +// For further details, please see: +// http://docs.opencv.org/master/d1/dfb/intro.html +// +package gocv // import "gocv.io/x/gocv" diff --git a/vendor/gocv.io/x/gocv/highgui.cpp b/vendor/gocv.io/x/gocv/highgui.cpp new file mode 100644 index 00000000..87177131 --- /dev/null +++ b/vendor/gocv.io/x/gocv/highgui.cpp @@ -0,0 +1,83 @@ +#include "highgui_gocv.h" + +// Window +void Window_New(const char* winname, int flags) { + cv::namedWindow(winname, flags); +} + +void Window_Close(const char* winname) { + cv::destroyWindow(winname); +} + +void Window_IMShow(const char* winname, Mat mat) { + cv::imshow(winname, *mat); +} + +double Window_GetProperty(const char* winname, int flag) { + return cv::getWindowProperty(winname, flag); +} + +void Window_SetProperty(const char* winname, int flag, double value) { + cv::setWindowProperty(winname, flag, value); +} + +void Window_SetTitle(const char* winname, const char* title) { + cv::setWindowTitle(winname, title); +} + +int Window_WaitKey(int delay = 0) { + return cv::waitKey(delay); +} + +void Window_Move(const char* winname, int x, int y) { + cv::moveWindow(winname, x, y); +} + +void Window_Resize(const char* winname, int width, int height) { + cv::resizeWindow(winname, width, height); +} + +struct Rect Window_SelectROI(const char* winname, Mat img) { + cv::Rect bRect = cv::selectROI(winname, *img); + Rect r = {bRect.x, bRect.y, bRect.width, bRect.height}; + return r; +} + +struct Rects Window_SelectROIs(const char* winname, Mat img) { + std::vector rois; + cv::selectROIs(winname, *img, rois); + Rect* rects = new Rect[rois.size()]; + + for (size_t i = 0; i < rois.size(); ++i) { + Rect r = {rois[i].x, rois[i].y, rois[i].width, rois[i].height}; + rects[i] = r; + } + + Rects ret = {rects, (int)rois.size()}; + return ret; +} + +// Trackbar +void Trackbar_Create(const char* winname, const char* trackname, int max) { + cv::createTrackbar(trackname, winname, NULL, max); +} + +void Trackbar_CreateWithValue(const char* winname, const char* trackname, int* value, int max) { + cv::createTrackbar(trackname, winname, value, max); +} + +int Trackbar_GetPos(const char* winname, const char* trackname) { + return cv::getTrackbarPos(trackname, winname); +} + +void Trackbar_SetPos(const char* winname, const char* trackname, int pos) { + cv::setTrackbarPos(trackname, winname, pos); +} + +void Trackbar_SetMin(const char* winname, const char* trackname, int pos) { + cv::setTrackbarMin(trackname, winname, pos); +} + +void Trackbar_SetMax(const char* winname, const char* trackname, int pos) { + cv::setTrackbarMax(trackname, winname, pos); +} diff --git a/vendor/gocv.io/x/gocv/highgui.go b/vendor/gocv.io/x/gocv/highgui.go new file mode 100644 index 00000000..6ebf917f --- /dev/null +++ b/vendor/gocv.io/x/gocv/highgui.go @@ -0,0 +1,361 @@ +package gocv + +/* +#include +#include "highgui_gocv.h" +*/ +import "C" +import ( + "image" + "runtime" + "unsafe" +) + +// Window is a wrapper around OpenCV's "HighGUI" named windows. +// While OpenCV was designed for use in full-scale applications and can be used +// within functionally rich UI frameworks (such as Qt*, WinForms*, or Cocoa*) +// or without any UI at all, sometimes there it is required to try functionality +// quickly and visualize the results. This is what the HighGUI module has been designed for. +// +// For further details, please see: +// http://docs.opencv.org/master/d7/dfc/group__highgui.html +// +type Window struct { + name string + open bool +} + +// NewWindow creates a new named OpenCV window +// +// For further details, please see: +// http://docs.opencv.org/master/d7/dfc/group__highgui.html#ga5afdf8410934fd099df85c75b2e0888b +// +func NewWindow(name string) *Window { + runtime.LockOSThread() + + cName := C.CString(name) + defer C.free(unsafe.Pointer(cName)) + + C.Window_New(cName, 0) + + return &Window{name: name, open: true} +} + +// Close closes and deletes a named OpenCV Window. +// +// For further details, please see: +// http://docs.opencv.org/master/d7/dfc/group__highgui.html#ga851ccdd6961022d1d5b4c4f255dbab34 +// +func (w *Window) Close() error { + cName := C.CString(w.name) + defer C.free(unsafe.Pointer(cName)) + + C.Window_Close(cName) + w.open = false + + runtime.UnlockOSThread() + return nil +} + +// IsOpen checks to see if the Window seems to be open. +func (w *Window) IsOpen() bool { + return w.open +} + +// WindowFlag value for SetWindowProperty / GetWindowProperty. +type WindowFlag float32 + +const ( + // WindowNormal indicates a normal window. + WindowNormal WindowFlag = 0x00000000 + + // WindowAutosize indicates a window sized based on the contents. + WindowAutosize WindowFlag = 0x00000001 + + // WindowFullscreen indicates a full-screen window. + WindowFullscreen WindowFlag = 1 + + // WindowFreeRatio indicates allow the user to resize without maintaining aspect ratio. + WindowFreeRatio WindowFlag = 0x00000100 + + // WindowKeepRatio indicates always maintain an aspect ratio that matches the contents. + WindowKeepRatio WindowFlag = 0x00000000 +) + +// WindowPropertyFlag flags for SetWindowProperty / GetWindowProperty. +type WindowPropertyFlag int + +const ( + // WindowPropertyFullscreen fullscreen property + // (can be WINDOW_NORMAL or WINDOW_FULLSCREEN). + WindowPropertyFullscreen WindowPropertyFlag = 0 + + // WindowPropertyAutosize is autosize property + // (can be WINDOW_NORMAL or WINDOW_AUTOSIZE). + WindowPropertyAutosize WindowPropertyFlag = 1 + + // WindowPropertyAspectRatio window's aspect ration + // (can be set to WINDOW_FREERATIO or WINDOW_KEEPRATIO). + WindowPropertyAspectRatio WindowPropertyFlag = 2 + + // WindowPropertyOpenGL opengl support. + WindowPropertyOpenGL WindowPropertyFlag = 3 + + // WindowPropertyVisible or not. + WindowPropertyVisible WindowPropertyFlag = 4 +) + +// GetWindowProperty returns properties of a window. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/dfc/group__highgui.html#gaaf9504b8f9cf19024d9d44a14e461656 +// +func (w *Window) GetWindowProperty(flag WindowPropertyFlag) float64 { + cName := C.CString(w.name) + defer C.free(unsafe.Pointer(cName)) + + return float64(C.Window_GetProperty(cName, C.int(flag))) +} + +// SetWindowProperty changes parameters of a window dynamically. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/dfc/group__highgui.html#ga66e4a6db4d4e06148bcdfe0d70a5df27 +// +func (w *Window) SetWindowProperty(flag WindowPropertyFlag, value WindowFlag) { + cName := C.CString(w.name) + defer C.free(unsafe.Pointer(cName)) + + C.Window_SetProperty(cName, C.int(flag), C.double(value)) +} + +// SetWindowTitle updates window title. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/dfc/group__highgui.html#ga56f8849295fd10d0c319724ddb773d96 +// +func (w *Window) SetWindowTitle(title string) { + cName := C.CString(w.name) + defer C.free(unsafe.Pointer(cName)) + + cTitle := C.CString(title) + defer C.free(unsafe.Pointer(cTitle)) + + C.Window_SetTitle(cName, cTitle) +} + +// IMShow displays an image Mat in the specified window. +// This function should be followed by the WaitKey function which displays +// the image for specified milliseconds. Otherwise, it won't display the image. +// +// For further details, please see: +// http://docs.opencv.org/master/d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563 +// +func (w *Window) IMShow(img Mat) { + cName := C.CString(w.name) + defer C.free(unsafe.Pointer(cName)) + + C.Window_IMShow(cName, img.p) +} + +// WaitKey waits for a pressed key. +// This function is the only method in OpenCV's HighGUI that can fetch +// and handle events, so it needs to be called periodically +// for normal event processing +// +// For further details, please see: +// http://docs.opencv.org/master/d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7 +// +func (w *Window) WaitKey(delay int) int { + return int(C.Window_WaitKey(C.int(delay))) +} + +// MoveWindow moves window to the specified position. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/dfc/group__highgui.html#ga8d86b207f7211250dbe6e28f76307ffb +// +func (w *Window) MoveWindow(x, y int) { + cName := C.CString(w.name) + defer C.free(unsafe.Pointer(cName)) + + C.Window_Move(cName, C.int(x), C.int(y)) +} + +// ResizeWindow resizes window to the specified size. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/dfc/group__highgui.html#ga9e80e080f7ef33f897e415358aee7f7e +// +func (w *Window) ResizeWindow(width, height int) { + cName := C.CString(w.name) + defer C.free(unsafe.Pointer(cName)) + + C.Window_Resize(cName, C.int(width), C.int(height)) +} + +// SelectROI selects a Region Of Interest (ROI) on the given image. +// It creates a window and allows user to select a ROI using mouse. +// +// Controls: +// use space or enter to finish selection, +// use key c to cancel selection (function will return a zero Rect). +// +// For further details, please see: +// https://docs.opencv.org/master/d7/dfc/group__highgui.html#ga8daf4730d3adf7035b6de9be4c469af5 +// +func (w *Window) SelectROI(img Mat) image.Rectangle { + cName := C.CString(w.name) + defer C.free(unsafe.Pointer(cName)) + + r := C.Window_SelectROI(cName, img.p) + rect := image.Rect(int(r.x), int(r.y), int(r.x+r.width), int(r.y+r.height)) + return rect +} + +// SelectROIs selects multiple Regions Of Interest (ROI) on the given image. +// It creates a window and allows user to select ROIs using mouse. +// +// Controls: +// use space or enter to finish current selection and start a new one +// use esc to terminate multiple ROI selection process +// +// For further details, please see: +// https://docs.opencv.org/master/d7/dfc/group__highgui.html#ga0f11fad74a6432b8055fb21621a0f893 +// +func (w *Window) SelectROIs(img Mat) []image.Rectangle { + cName := C.CString(w.name) + defer C.free(unsafe.Pointer(cName)) + + ret := C.Window_SelectROIs(cName, img.p) + defer C.Rects_Close(ret) + + return toRectangles(ret) +} + +// Deprecated: use Window.SelectROI instead +func SelectROI(name string, img Mat) image.Rectangle { + cName := C.CString(name) + defer C.free(unsafe.Pointer(cName)) + + r := C.Window_SelectROI(cName, img.p) + rect := image.Rect(int(r.x), int(r.y), int(r.x+r.width), int(r.y+r.height)) + return rect +} + +// Deprecated: use Window.SelectROIs instead +func SelectROIs(name string, img Mat) []image.Rectangle { + cName := C.CString(name) + defer C.free(unsafe.Pointer(cName)) + + ret := C.Window_SelectROIs(cName, img.p) + defer C.Rects_Close(ret) + + return toRectangles(ret) +} + +// WaitKey that is not attached to a specific Window. +// Only use when no Window exists in your application, e.g. command line app. +// +func WaitKey(delay int) int { + return int(C.Window_WaitKey(C.int(delay))) +} + +// Trackbar is a wrapper around OpenCV's "HighGUI" window Trackbars. +type Trackbar struct { + name string + parent *Window +} + +// CreateTrackbar creates a trackbar and attaches it to the specified window. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/dfc/group__highgui.html#gaf78d2155d30b728fc413803745b67a9b +// +func (w *Window) CreateTrackbar(name string, max int) *Trackbar { + cName := C.CString(w.name) + defer C.free(unsafe.Pointer(cName)) + + tName := C.CString(name) + defer C.free(unsafe.Pointer(tName)) + + C.Trackbar_Create(cName, tName, C.int(max)) + return &Trackbar{name: name, parent: w} +} + +// CreateTrackbarWithValue works like CreateTrackbar but also assigns a +// variable value to be a position synchronized with the trackbar. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/dfc/group__highgui.html#gaf78d2155d30b728fc413803745b67a9b +// +func (w *Window) CreateTrackbarWithValue(name string, value *int, max int) *Trackbar { + cName := C.CString(w.name) + defer C.free(unsafe.Pointer(cName)) + + tName := C.CString(name) + defer C.free(unsafe.Pointer(tName)) + + C.Trackbar_CreateWithValue(cName, tName, (*C.int)(unsafe.Pointer(value)), C.int(max)) + return &Trackbar{name: name, parent: w} +} + +// GetPos returns the trackbar position. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/dfc/group__highgui.html#ga122632e9e91b9ec06943472c55d9cda8 +// +func (t *Trackbar) GetPos() int { + cName := C.CString(t.parent.name) + defer C.free(unsafe.Pointer(cName)) + + tName := C.CString(t.name) + defer C.free(unsafe.Pointer(tName)) + + return int(C.Trackbar_GetPos(cName, tName)) +} + +// SetPos sets the trackbar position. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/dfc/group__highgui.html#ga67d73c4c9430f13481fd58410d01bd8d +// +func (t *Trackbar) SetPos(pos int) { + cName := C.CString(t.parent.name) + defer C.free(unsafe.Pointer(cName)) + + tName := C.CString(t.name) + defer C.free(unsafe.Pointer(tName)) + + C.Trackbar_SetPos(cName, tName, C.int(pos)) +} + +// SetMin sets the trackbar minimum position. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/dfc/group__highgui.html#gabe26ffe8d2b60cc678895595a581b7aa +// +func (t *Trackbar) SetMin(pos int) { + cName := C.CString(t.parent.name) + defer C.free(unsafe.Pointer(cName)) + + tName := C.CString(t.name) + defer C.free(unsafe.Pointer(tName)) + + C.Trackbar_SetMin(cName, tName, C.int(pos)) +} + +// SetMax sets the trackbar maximum position. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/dfc/group__highgui.html#ga7e5437ccba37f1154b65210902fc4480 +// +func (t *Trackbar) SetMax(pos int) { + cName := C.CString(t.parent.name) + defer C.free(unsafe.Pointer(cName)) + + tName := C.CString(t.name) + defer C.free(unsafe.Pointer(tName)) + + C.Trackbar_SetMax(cName, tName, C.int(pos)) +} diff --git a/vendor/gocv.io/x/gocv/highgui_gocv.h b/vendor/gocv.io/x/gocv/highgui_gocv.h new file mode 100644 index 00000000..d1bd33b5 --- /dev/null +++ b/vendor/gocv.io/x/gocv/highgui_gocv.h @@ -0,0 +1,36 @@ +#ifndef _OPENCV3_HIGHGUI_H_ +#define _OPENCV3_HIGHGUI_H_ + +#ifdef __cplusplus +#include +extern "C" { +#endif + +#include "core.h" + +// Window +void Window_New(const char* winname, int flags); +void Window_Close(const char* winname); +void Window_IMShow(const char* winname, Mat mat); +double Window_GetProperty(const char* winname, int flag); +void Window_SetProperty(const char* winname, int flag, double value); +void Window_SetTitle(const char* winname, const char* title); +int Window_WaitKey(int); +void Window_Move(const char* winname, int x, int y); +void Window_Resize(const char* winname, int width, int height); +struct Rect Window_SelectROI(const char* winname, Mat img); +struct Rects Window_SelectROIs(const char* winname, Mat img); + +// Trackbar +void Trackbar_Create(const char* winname, const char* trackname, int max); +void Trackbar_CreateWithValue(const char* winname, const char* trackname, int* value, int max); +int Trackbar_GetPos(const char* winname, const char* trackname); +void Trackbar_SetPos(const char* winname, const char* trackname, int pos); +void Trackbar_SetMin(const char* winname, const char* trackname, int pos); +void Trackbar_SetMax(const char* winname, const char* trackname, int pos); + +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_HIGHGUI_H_ diff --git a/vendor/gocv.io/x/gocv/highgui_string.go b/vendor/gocv.io/x/gocv/highgui_string.go new file mode 100644 index 00000000..d073bbe2 --- /dev/null +++ b/vendor/gocv.io/x/gocv/highgui_string.go @@ -0,0 +1,35 @@ +package gocv + +/* +#include +#include "highgui_gocv.h" +*/ +import "C" + +func (c WindowFlag) String() string { + switch c { + case WindowNormal: + return "window-normal" + case WindowFullscreen: + return "window-fullscreen" + case WindowFreeRatio: + return "window-free-ratio" + } + return "" +} + +func (c WindowPropertyFlag) String() string { + switch c { + case WindowPropertyFullscreen: + return "window-property-fullscreen" + case WindowPropertyAutosize: + return "window-property-autosize" + case WindowPropertyAspectRatio: + return "window-property-aspect-ratio" + case WindowPropertyOpenGL: + return "window-property-opengl" + case WindowPropertyVisible: + return "window-property-visible" + } + return "" +} diff --git a/vendor/gocv.io/x/gocv/imgcodecs.cpp b/vendor/gocv.io/x/gocv/imgcodecs.cpp new file mode 100644 index 00000000..af107cd8 --- /dev/null +++ b/vendor/gocv.io/x/gocv/imgcodecs.cpp @@ -0,0 +1,49 @@ +#include "imgcodecs.h" + +// Image +Mat Image_IMRead(const char* filename, int flags) { + cv::Mat img = cv::imread(filename, flags); + return new cv::Mat(img); +} + + +bool Image_IMWrite(const char* filename, Mat img) { + return cv::imwrite(filename, *img); +} + +bool Image_IMWrite_WithParams(const char* filename, Mat img, IntVector params) { + std::vector compression_params; + + for (int i = 0, *v = params.val; i < params.length; ++v, ++i) { + compression_params.push_back(*v); + } + + return cv::imwrite(filename, *img, compression_params); +} + +void Image_IMEncode(const char* fileExt, Mat img, void* vector) { + auto vectorPtr = reinterpret_cast *>(vector); + cv::imencode(fileExt, *img, *vectorPtr); +} + +void Image_IMEncode_WithParams(const char* fileExt, Mat img, IntVector params, void* vector) { + auto vectorPtr = reinterpret_cast *>(vector); + std::vector compression_params; + + for (int i = 0, *v = params.val; i < params.length; ++v, ++i) { + compression_params.push_back(*v); + } + + cv::imencode(fileExt, *img, *vectorPtr, compression_params); +} + +Mat Image_IMDecode(ByteArray buf, int flags) { + std::vector data(buf.data, buf.data + buf.length); + cv::Mat img = cv::imdecode(data, flags); + return new cv::Mat(img); +} + +void Image_IMDecodeIntoMat(ByteArray buf, int flags, Mat dest) { + std::vector data(buf.data, buf.data + buf.length); + cv::imdecode(data, flags, dest); +} diff --git a/vendor/gocv.io/x/gocv/imgcodecs.go b/vendor/gocv.io/x/gocv/imgcodecs.go new file mode 100644 index 00000000..0a676ad7 --- /dev/null +++ b/vendor/gocv.io/x/gocv/imgcodecs.go @@ -0,0 +1,263 @@ +package gocv + +/* +#include +#include "imgcodecs.h" +*/ +import "C" +import ( + "unsafe" +) + +// IMReadFlag is one of the valid flags to use for the IMRead function. +type IMReadFlag int + +const ( + // IMReadUnchanged return the loaded image as is (with alpha channel, + // otherwise it gets cropped). + IMReadUnchanged IMReadFlag = -1 + + // IMReadGrayScale always convert image to the single channel + // grayscale image. + IMReadGrayScale IMReadFlag = 0 + + // IMReadColor always converts image to the 3 channel BGR color image. + IMReadColor IMReadFlag = 1 + + // IMReadAnyDepth returns 16-bit/32-bit image when the input has the corresponding + // depth, otherwise convert it to 8-bit. + IMReadAnyDepth IMReadFlag = 2 + + // IMReadAnyColor the image is read in any possible color format. + IMReadAnyColor IMReadFlag = 4 + + // IMReadLoadGDAL uses the gdal driver for loading the image. + IMReadLoadGDAL IMReadFlag = 8 + + // IMReadReducedGrayscale2 always converts image to the single channel grayscale image + // and the image size reduced 1/2. + IMReadReducedGrayscale2 IMReadFlag = 16 + + // IMReadReducedColor2 always converts image to the 3 channel BGR color image and the + // image size reduced 1/2. + IMReadReducedColor2 IMReadFlag = 17 + + // IMReadReducedGrayscale4 always converts image to the single channel grayscale image and + // the image size reduced 1/4. + IMReadReducedGrayscale4 IMReadFlag = 32 + + // IMReadReducedColor4 always converts image to the 3 channel BGR color image and + // the image size reduced 1/4. + IMReadReducedColor4 IMReadFlag = 33 + + // IMReadReducedGrayscale8 always convert image to the single channel grayscale image and + // the image size reduced 1/8. + IMReadReducedGrayscale8 IMReadFlag = 64 + + // IMReadReducedColor8 always convert image to the 3 channel BGR color image and the + // image size reduced 1/8. + IMReadReducedColor8 IMReadFlag = 65 + + // IMReadIgnoreOrientation do not rotate the image according to EXIF's orientation flag. + IMReadIgnoreOrientation IMReadFlag = 128 +) + +// TODO: Define IMWriteFlag type? + +const ( + //IMWriteJpegQuality is the quality from 0 to 100 for JPEG (the higher is the better). Default value is 95. + IMWriteJpegQuality = 1 + + // IMWriteJpegProgressive enables JPEG progressive feature, 0 or 1, default is False. + IMWriteJpegProgressive = 2 + + // IMWriteJpegOptimize enables JPEG optimization, 0 or 1, default is False. + IMWriteJpegOptimize = 3 + + // IMWriteJpegRstInterval is the JPEG restart interval, 0 - 65535, default is 0 - no restart. + IMWriteJpegRstInterval = 4 + + // IMWriteJpegLumaQuality separates luma quality level, 0 - 100, default is 0 - don't use. + IMWriteJpegLumaQuality = 5 + + // IMWriteJpegChromaQuality separates chroma quality level, 0 - 100, default is 0 - don't use. + IMWriteJpegChromaQuality = 6 + + // IMWritePngCompression is the compression level from 0 to 9 for PNG. A + // higher value means a smaller size and longer compression time. + // If specified, strategy is changed to IMWRITE_PNG_STRATEGY_DEFAULT (Z_DEFAULT_STRATEGY). + // Default value is 1 (best speed setting). + IMWritePngCompression = 16 + + // IMWritePngStrategy is one of cv::IMWritePNGFlags, default is IMWRITE_PNG_STRATEGY_RLE. + IMWritePngStrategy = 17 + + // IMWritePngBilevel is the binary level PNG, 0 or 1, default is 0. + IMWritePngBilevel = 18 + + // IMWritePxmBinary for PPM, PGM, or PBM can be a binary format flag, 0 or 1. Default value is 1. + IMWritePxmBinary = 32 + + // IMWriteWebpQuality is the quality from 1 to 100 for WEBP (the higher is + // the better). By default (without any parameter) and for quality above + // 100 the lossless compression is used. + IMWriteWebpQuality = 64 + + // IMWritePamTupletype sets the TUPLETYPE field to the corresponding string + // value that is defined for the format. + IMWritePamTupletype = 128 + + // IMWritePngStrategyDefault is the value to use for normal data. + IMWritePngStrategyDefault = 0 + + // IMWritePngStrategyFiltered is the value to use for data produced by a + // filter (or predictor). Filtered data consists mostly of small values + // with a somewhat random distribution. In this case, the compression + // algorithm is tuned to compress them better. + IMWritePngStrategyFiltered = 1 + + // IMWritePngStrategyHuffmanOnly forces Huffman encoding only (no string match). + IMWritePngStrategyHuffmanOnly = 2 + + // IMWritePngStrategyRle is the value to use to limit match distances to + // one (run-length encoding). + IMWritePngStrategyRle = 3 + + // IMWritePngStrategyFixed is the value to prevent the use of dynamic + // Huffman codes, allowing for a simpler decoder for special applications. + IMWritePngStrategyFixed = 4 +) + +// IMRead reads an image from a file into a Mat. +// The flags param is one of the IMReadFlag flags. +// If the image cannot be read (because of missing file, improper permissions, +// unsupported or invalid format), the function returns an empty Mat. +// +// For further details, please see: +// http://docs.opencv.org/master/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56 +func IMRead(name string, flags IMReadFlag) Mat { + cName := C.CString(name) + defer C.free(unsafe.Pointer(cName)) + + return newMat(C.Image_IMRead(cName, C.int(flags))) +} + +// IMWrite writes a Mat to an image file. +// +// For further details, please see: +// http://docs.opencv.org/master/d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce +func IMWrite(name string, img Mat) bool { + cName := C.CString(name) + defer C.free(unsafe.Pointer(cName)) + + return bool(C.Image_IMWrite(cName, img.p)) +} + +// IMWriteWithParams writes a Mat to an image file. With that func you can +// pass compression parameters. +// +// For further details, please see: +// http://docs.opencv.org/master/d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce +func IMWriteWithParams(name string, img Mat, params []int) bool { + cName := C.CString(name) + defer C.free(unsafe.Pointer(cName)) + + cparams := []C.int{} + + for _, v := range params { + cparams = append(cparams, C.int(v)) + } + + paramsVector := C.struct_IntVector{} + paramsVector.val = (*C.int)(&cparams[0]) + paramsVector.length = (C.int)(len(cparams)) + + return bool(C.Image_IMWrite_WithParams(cName, img.p, paramsVector)) +} + +// FileExt represents a file extension. +type FileExt string + +const ( + // PNGFileExt is the file extension for PNG. + PNGFileExt FileExt = ".png" + // JPEGFileExt is the file extension for JPEG. + JPEGFileExt FileExt = ".jpg" + // GIFFileExt is the file extension for GIF. + GIFFileExt FileExt = ".gif" +) + +// IMEncode encodes an image Mat into a memory buffer. +// This function compresses the image and stores it in the returned memory buffer, +// using the image format passed in in the form of a file extension string. +// +// For further details, please see: +// http://docs.opencv.org/master/d4/da8/group__imgcodecs.html#ga461f9ac09887e47797a54567df3b8b63 +func IMEncode(fileExt FileExt, img Mat) (buf *NativeByteBuffer, err error) { + cfileExt := C.CString(string(fileExt)) + defer C.free(unsafe.Pointer(cfileExt)) + + buffer := newNativeByteBuffer() + C.Image_IMEncode(cfileExt, img.Ptr(), buffer.nativePointer()) + return buffer, nil +} + +// IMEncodeWithParams encodes an image Mat into a memory buffer. +// This function compresses the image and stores it in the returned memory buffer, +// using the image format passed in in the form of a file extension string. +// +// Usage example: +// +// buffer, err := gocv.IMEncodeWithParams(gocv.JPEGFileExt, img, []int{gocv.IMWriteJpegQuality, quality}) +// +// For further details, please see: +// http://docs.opencv.org/master/d4/da8/group__imgcodecs.html#ga461f9ac09887e47797a54567df3b8b63 +func IMEncodeWithParams(fileExt FileExt, img Mat, params []int) (buf *NativeByteBuffer, err error) { + cfileExt := C.CString(string(fileExt)) + defer C.free(unsafe.Pointer(cfileExt)) + + cparams := []C.int{} + + for _, v := range params { + cparams = append(cparams, C.int(v)) + } + + paramsVector := C.struct_IntVector{} + paramsVector.val = (*C.int)(&cparams[0]) + paramsVector.length = (C.int)(len(cparams)) + + b := newNativeByteBuffer() + C.Image_IMEncode_WithParams(cfileExt, img.Ptr(), paramsVector, b.nativePointer()) + return b, nil +} + +// IMDecode reads an image from a buffer in memory. +// The function IMDecode reads an image from the specified buffer in memory. +// If the buffer is too short or contains invalid data, the function +// returns an empty matrix. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/da8/group__imgcodecs.html#ga26a67788faa58ade337f8d28ba0eb19e +func IMDecode(buf []byte, flags IMReadFlag) (Mat, error) { + data, err := toByteArray(buf) + if err != nil { + return Mat{}, err + } + return newMat(C.Image_IMDecode(*data, C.int(flags))), nil +} + +// IMDecodeIntoMat reads an image from a buffer in memory into a matrix. +// The function IMDecodeIntoMat reads an image from the specified buffer in memory. +// If the buffer is too short or contains invalid data, the function +// returns an error +// +// For further details, please see: +// https://docs.opencv.org/4.x/d4/da8/group__imgcodecs.html#ga5a0acefe5cbe0a81e904e452ec7ca733 +func IMDecodeIntoMat(buf []byte, flags IMReadFlag, dest *Mat) error { + data, err := toByteArray(buf) + if err != nil { + return err + } + C.Image_IMDecodeIntoMat(*data, C.int(flags), dest.p) + return nil +} diff --git a/vendor/gocv.io/x/gocv/imgcodecs.h b/vendor/gocv.io/x/gocv/imgcodecs.h new file mode 100644 index 00000000..eb7b205a --- /dev/null +++ b/vendor/gocv.io/x/gocv/imgcodecs.h @@ -0,0 +1,26 @@ +#ifndef _OPENCV3_IMGCODECS_H_ +#define _OPENCV3_IMGCODECS_H_ + +#include + +#ifdef __cplusplus +#include +extern "C" { +#endif + +#include "core.h" + +Mat Image_IMRead(const char* filename, int flags); +bool Image_IMWrite(const char* filename, Mat img); +bool Image_IMWrite_WithParams(const char* filename, Mat img, IntVector params); +void Image_IMEncode(const char* fileExt, Mat img, void* vector); + +void Image_IMEncode_WithParams(const char* fileExt, Mat img, IntVector params, void* vector); +Mat Image_IMDecode(ByteArray buf, int flags); +void Image_IMDecodeIntoMat(ByteArray buf, int flag, Mat dest); + +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_IMGCODECS_H_ diff --git a/vendor/gocv.io/x/gocv/imgproc.cpp b/vendor/gocv.io/x/gocv/imgproc.cpp new file mode 100644 index 00000000..dd65eac1 --- /dev/null +++ b/vendor/gocv.io/x/gocv/imgproc.cpp @@ -0,0 +1,675 @@ +#include "imgproc.h" + +double ArcLength(PointVector curve, bool is_closed) { + return cv::arcLength(*curve, is_closed); +} + +PointVector ApproxPolyDP(PointVector curve, double epsilon, bool closed) { + PointVector approxCurvePts = new std::vector; + cv::approxPolyDP(*curve, *approxCurvePts, epsilon, closed); + + return approxCurvePts; +} + +void CvtColor(Mat src, Mat dst, int code) { + cv::cvtColor(*src, *dst, code); +} + +void EqualizeHist(Mat src, Mat dst) { + cv::equalizeHist(*src, *dst); +} + +void CalcHist(struct Mats mats, IntVector chans, Mat mask, Mat hist, IntVector sz, FloatVector rng, bool acc) { + std::vector images; + + for (int i = 0; i < mats.length; ++i) { + images.push_back(*mats.mats[i]); + } + + std::vector channels; + + for (int i = 0, *v = chans.val; i < chans.length; ++v, ++i) { + channels.push_back(*v); + } + + std::vector histSize; + + for (int i = 0, *v = sz.val; i < sz.length; ++v, ++i) { + histSize.push_back(*v); + } + + std::vector ranges; + + float* f; + int i; + for (i = 0, f = rng.val; i < rng.length; ++f, ++i) { + ranges.push_back(*f); + } + + cv::calcHist(images, channels, *mask, *hist, histSize, ranges, acc); +} + +void CalcBackProject(struct Mats mats, IntVector chans, Mat hist, Mat backProject, FloatVector rng, bool uniform){ + std::vector images; + + for (int i = 0; i < mats.length; ++i) { + images.push_back(*mats.mats[i]); + } + + std::vector channels; + for (int i = 0, *v = chans.val; i < chans.length; ++v, ++i) { + channels.push_back(*v); + } + + std::vector ranges; + + float* f; + int i; + for (i = 0, f = rng.val; i < rng.length; ++f, ++i) { + ranges.push_back(*f); + } + + cv::calcBackProject(images, channels, *hist, *backProject, ranges, uniform); +} + +double CompareHist(Mat hist1, Mat hist2, int method) { + return cv::compareHist(*hist1, *hist2, method); +} + +struct RotatedRect FitEllipse(PointVector pts) +{ + cv::RotatedRect bRect = cv::fitEllipse(*pts); + + Rect r = {bRect.boundingRect().x, bRect.boundingRect().y, bRect.boundingRect().width, bRect.boundingRect().height}; + Point centrpt = {int(lroundf(bRect.center.x)), int(lroundf(bRect.center.y))}; + Size szsz = {int(lroundf(bRect.size.width)), int(lroundf(bRect.size.height))}; + + cv::Point2f* pts4 = new cv::Point2f[4]; + bRect.points(pts4); + Point* rpts = new Point[4]; + for (size_t j = 0; j < 4; j++) { + Point pt = {int(lroundf(pts4[j].x)), int(lroundf(pts4[j].y))}; + rpts[j] = pt; + } + + delete[] pts4; + + RotatedRect rotRect = {Points{rpts, 4}, r, centrpt, szsz, bRect.angle}; + return rotRect; +} + +void ConvexHull(PointVector points, Mat hull, bool clockwise, bool returnPoints) { + cv::convexHull(*points, *hull, clockwise, returnPoints); +} + +void ConvexityDefects(PointVector points, Mat hull, Mat result) { + cv::convexityDefects(*points, *hull, *result); +} + +void BilateralFilter(Mat src, Mat dst, int d, double sc, double ss) { + cv::bilateralFilter(*src, *dst, d, sc, ss); +} + +void Blur(Mat src, Mat dst, Size ps) { + cv::Size sz(ps.width, ps.height); + cv::blur(*src, *dst, sz); +} + +void BoxFilter(Mat src, Mat dst, int ddepth, Size ps) { + cv::Size sz(ps.width, ps.height); + cv::boxFilter(*src, *dst, ddepth, sz); +} + +void SqBoxFilter(Mat src, Mat dst, int ddepth, Size ps) { + cv::Size sz(ps.width, ps.height); + cv::sqrBoxFilter(*src, *dst, ddepth, sz); +} + +void Dilate(Mat src, Mat dst, Mat kernel) { + cv::dilate(*src, *dst, *kernel); +} + +void DilateWithParams(Mat src, Mat dst, Mat kernel, Point anchor, int iterations, int borderType, Scalar borderValue) { + cv::Point pt1(anchor.x, anchor.y); + cv::Scalar c = cv::Scalar(borderValue.val1, borderValue.val2, borderValue.val3, borderValue.val4); + + cv::dilate(*src, *dst, *kernel, pt1, iterations, borderType, c); +} + +void DistanceTransform(Mat src, Mat dst, Mat labels, int distanceType, int maskSize, int labelType) { + cv::distanceTransform(*src, *dst, *labels, distanceType, maskSize, labelType); +} + +void Erode(Mat src, Mat dst, Mat kernel) { + cv::erode(*src, *dst, *kernel); +} + +void ErodeWithParams(Mat src, Mat dst, Mat kernel, Point anchor, int iterations, int borderType) { + cv::Point pt1(anchor.x, anchor.y); + + cv::erode(*src, *dst, *kernel, pt1, iterations, borderType, cv::morphologyDefaultBorderValue()); +} + +void MatchTemplate(Mat image, Mat templ, Mat result, int method, Mat mask) { + cv::matchTemplate(*image, *templ, *result, method, *mask); +} + +struct Moment Moments(Mat src, bool binaryImage) { + cv::Moments m = cv::moments(*src, binaryImage); + Moment mom = {m.m00, m.m10, m.m01, m.m20, m.m11, m.m02, m.m30, m.m21, m.m12, m.m03, + m.mu20, m.mu11, m.mu02, m.mu30, m.mu21, m.mu12, m.mu03, + m.nu20, m.nu11, m.nu02, m.nu30, m.nu21, m.nu12, m.nu03 + }; + return mom; +} + +void PyrDown(Mat src, Mat dst, Size size, int borderType) { + cv::Size cvSize(size.width, size.height); + cv::pyrDown(*src, *dst, cvSize, borderType); +} + +void PyrUp(Mat src, Mat dst, Size size, int borderType) { + cv::Size cvSize(size.width, size.height); + cv::pyrUp(*src, *dst, cvSize, borderType); +} + +struct Rect BoundingRect(PointVector pts) { + cv::Rect bRect = cv::boundingRect(*pts); + Rect r = {bRect.x, bRect.y, bRect.width, bRect.height}; + return r; +} + +void BoxPoints(RotatedRect rect, Mat boxPts){ + cv::Point2f centerPt(rect.center.x , rect.center.y); + cv::Size2f rSize(rect.size.width, rect.size.height); + cv::RotatedRect rotatedRectangle(centerPt, rSize, rect.angle); + cv::boxPoints(rotatedRectangle, *boxPts); +} + +double ContourArea(PointVector pts) { + return cv::contourArea(*pts); +} + +struct RotatedRect MinAreaRect(PointVector pts){ + cv::RotatedRect cvrect = cv::minAreaRect(*pts); + + Point* rpts = new Point[4]; + cv::Point2f* pts4 = new cv::Point2f[4]; + cvrect.points(pts4); + + for (size_t j = 0; j < 4; j++) { + Point pt = {int(lroundf(pts4[j].x)), int(lroundf(pts4[j].y))}; + rpts[j] = pt; + } + + delete[] pts4; + + cv::Rect bRect = cvrect.boundingRect(); + Rect r = {bRect.x, bRect.y, bRect.width, bRect.height}; + Point centrpt = {int(lroundf(cvrect.center.x)), int(lroundf(cvrect.center.y))}; + Size szsz = {int(lroundf(cvrect.size.width)), int(lroundf(cvrect.size.height))}; + + RotatedRect retrect = {(Contour){rpts, 4}, r, centrpt, szsz, cvrect.angle}; + return retrect; +} + +void MinEnclosingCircle(PointVector pts, Point2f* center, float* radius){ + cv::Point2f center2f; + cv::minEnclosingCircle(*pts, center2f, *radius); + center->x = center2f.x; + center->y = center2f.y; +} + +PointsVector FindContours(Mat src, Mat hierarchy, int mode, int method) { + PointsVector contours = new std::vector >; + cv::findContours(*src, *contours, *hierarchy, mode, method); + + return contours; +} + +double PointPolygonTest(PointVector pts, Point pt, bool measureDist) { + cv::Point2f pt1(pt.x, pt.y); + + return cv::pointPolygonTest(*pts, pt1, measureDist); +} + +int ConnectedComponents(Mat src, Mat labels, int connectivity, int ltype, int ccltype){ + return cv::connectedComponents(*src, *labels, connectivity, ltype, ccltype); +} + + +int ConnectedComponentsWithStats(Mat src, Mat labels, Mat stats, Mat centroids, + int connectivity, int ltype, int ccltype){ + return cv::connectedComponentsWithStats(*src, *labels, *stats, *centroids, connectivity, ltype, ccltype); +} + +Mat GetStructuringElement(int shape, Size ksize) { + cv::Size sz(ksize.width, ksize.height); + return new cv::Mat(cv::getStructuringElement(shape, sz)); +} + +Scalar MorphologyDefaultBorderValue(){ + cv::Scalar cs = cv::morphologyDefaultBorderValue(); + return (Scalar){cs[0],cs[1],cs[2],cs[3]}; +} + +void MorphologyEx(Mat src, Mat dst, int op, Mat kernel) { + cv::morphologyEx(*src, *dst, op, *kernel); +} + +void MorphologyExWithParams(Mat src, Mat dst, int op, Mat kernel, Point pt, int iterations, int borderType) { + cv::Point pt1(pt.x, pt.y); + cv::morphologyEx(*src, *dst, op, *kernel, pt1, iterations, borderType); +} + +void GaussianBlur(Mat src, Mat dst, Size ps, double sX, double sY, int bt) { + cv::Size sz(ps.width, ps.height); + cv::GaussianBlur(*src, *dst, sz, sX, sY, bt); +} + +Mat GetGaussianKernel(int ksize, double sigma, int ktype){ + return new cv::Mat(cv::getGaussianKernel(ksize, sigma, ktype)); +} + +void Laplacian(Mat src, Mat dst, int dDepth, int kSize, double scale, double delta, + int borderType) { + cv::Laplacian(*src, *dst, dDepth, kSize, scale, delta, borderType); +} + +void Scharr(Mat src, Mat dst, int dDepth, int dx, int dy, double scale, double delta, + int borderType) { + cv::Scharr(*src, *dst, dDepth, dx, dy, scale, delta, borderType); +} + +void MedianBlur(Mat src, Mat dst, int ksize) { + cv::medianBlur(*src, *dst, ksize); +} + +void Canny(Mat src, Mat edges, double t1, double t2) { + cv::Canny(*src, *edges, t1, t2); +} + +void CornerSubPix(Mat img, Mat corners, Size winSize, Size zeroZone, TermCriteria criteria) { + cv::Size wsz(winSize.width, winSize.height); + cv::Size zsz(zeroZone.width, zeroZone.height); + cv::cornerSubPix(*img, *corners, wsz, zsz, *criteria); +} + +void GoodFeaturesToTrack(Mat img, Mat corners, int maxCorners, double quality, double minDist) { + cv::goodFeaturesToTrack(*img, *corners, maxCorners, quality, minDist); +} + +void GrabCut(Mat img, Mat mask, Rect r, Mat bgdModel, Mat fgdModel, int iterCount, int mode) { + cv::Rect cvRect = cv::Rect(r.x, r.y, r.width, r.height); + cv::grabCut(*img, *mask, cvRect, *bgdModel, *fgdModel, iterCount, mode); +} + +void HoughCircles(Mat src, Mat circles, int method, double dp, double minDist) { + cv::HoughCircles(*src, *circles, method, dp, minDist); +} + +void HoughCirclesWithParams(Mat src, Mat circles, int method, double dp, double minDist, + double param1, double param2, int minRadius, int maxRadius) { + cv::HoughCircles(*src, *circles, method, dp, minDist, param1, param2, minRadius, maxRadius); +} + +void HoughLines(Mat src, Mat lines, double rho, double theta, int threshold) { + cv::HoughLines(*src, *lines, rho, theta, threshold); +} + +void HoughLinesP(Mat src, Mat lines, double rho, double theta, int threshold) { + cv::HoughLinesP(*src, *lines, rho, theta, threshold); +} + +void HoughLinesPWithParams(Mat src, Mat lines, double rho, double theta, int threshold, double minLineLength, double maxLineGap) { + cv::HoughLinesP(*src, *lines, rho, theta, threshold, minLineLength, maxLineGap); +} + +void HoughLinesPointSet(Mat points, Mat lines, int linesMax, int threshold, + double minRho, double maxRho, double rhoStep, + double minTheta, double maxTheta, double thetaStep) { + cv::HoughLinesPointSet(*points, *lines, linesMax, threshold, + minRho, maxRho, rhoStep, minTheta, maxTheta, thetaStep ); +} + +void Integral(Mat src, Mat sum, Mat sqsum, Mat tilted) { + cv::integral(*src, *sum, *sqsum, *tilted); +} + +double Threshold(Mat src, Mat dst, double thresh, double maxvalue, int typ) { + return cv::threshold(*src, *dst, thresh, maxvalue, typ); +} + +void AdaptiveThreshold(Mat src, Mat dst, double maxValue, int adaptiveMethod, int thresholdType, + int blockSize, double c) { + cv::adaptiveThreshold(*src, *dst, maxValue, adaptiveMethod, thresholdType, blockSize, c); +} + +void ArrowedLine(Mat img, Point pt1, Point pt2, Scalar color, int thickness) { + cv::Point p1(pt1.x, pt1.y); + cv::Point p2(pt2.x, pt2.y); + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + + cv::arrowedLine(*img, p1, p2, c, thickness); +} + +bool ClipLine(Size imgSize, Point pt1, Point pt2) { + cv::Size sz(imgSize.width, imgSize.height); + cv::Point p1(pt1.x, pt1.y); + cv::Point p2(pt2.x, pt2.y); + + return cv::clipLine(sz, p1, p2); +} + +void Circle(Mat img, Point center, int radius, Scalar color, int thickness) { + cv::Point p1(center.x, center.y); + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + + cv::circle(*img, p1, radius, c, thickness); +} + +void CircleWithParams(Mat img, Point center, int radius, Scalar color, int thickness, int lineType, int shift) { + cv::Point p1(center.x, center.y); + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + + cv::circle(*img, p1, radius, c, thickness, lineType, shift); +} + +void Ellipse(Mat img, Point center, Point axes, double angle, double + startAngle, double endAngle, Scalar color, int thickness) { + cv::Point p1(center.x, center.y); + cv::Point p2(axes.x, axes.y); + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + + cv::ellipse(*img, p1, p2, angle, startAngle, endAngle, c, thickness); +} + +void EllipseWithParams(Mat img, Point center, Point axes, double angle, double + startAngle, double endAngle, Scalar color, int thickness, int lineType, int shift) { + cv::Point p1(center.x, center.y); + cv::Point p2(axes.x, axes.y); + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + + cv::ellipse(*img, p1, p2, angle, startAngle, endAngle, c, thickness, lineType, shift); +} + +void Line(Mat img, Point pt1, Point pt2, Scalar color, int thickness) { + cv::Point p1(pt1.x, pt1.y); + cv::Point p2(pt2.x, pt2.y); + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + + cv::line(*img, p1, p2, c, thickness); +} + +void Rectangle(Mat img, Rect r, Scalar color, int thickness) { + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + cv::rectangle( + *img, + cv::Point(r.x, r.y), + cv::Point(r.x + r.width, r.y + r.height), + c, + thickness, + cv::LINE_AA + ); +} + +void RectangleWithParams(Mat img, Rect r, Scalar color, int thickness, int lineType, int shift) { + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + cv::rectangle( + *img, + cv::Point(r.x, r.y), + cv::Point(r.x + r.width, r.y + r.height), + c, + thickness, + lineType, + shift + ); +} + +void FillPoly(Mat img, PointsVector pts, Scalar color) { + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + + cv::fillPoly(*img, *pts, c); +} + +void FillPolyWithParams(Mat img, PointsVector pts, Scalar color, int lineType, int shift, Point offset) { + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + + cv::fillPoly(*img, *pts, c, lineType, shift, cv::Point(offset.x, offset.y)); +} + +void Polylines(Mat img, PointsVector pts, bool isClosed, Scalar color,int thickness) { + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + + cv::polylines(*img, *pts, isClosed, c, thickness); +} + +struct Size GetTextSize(const char* text, int fontFace, double fontScale, int thickness) { + return GetTextSizeWithBaseline(text, fontFace, fontScale, thickness, NULL); +} + +struct Size GetTextSizeWithBaseline(const char* text, int fontFace, double fontScale, int thickness, int* baesline) { + cv::Size sz = cv::getTextSize(text, fontFace, fontScale, thickness, baesline); + Size size = {sz.width, sz.height}; + return size; +} + +void PutText(Mat img, const char* text, Point org, int fontFace, double fontScale, + Scalar color, int thickness) { + cv::Point pt(org.x, org.y); + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + cv::putText(*img, text, pt, fontFace, fontScale, c, thickness); +} + +void PutTextWithParams(Mat img, const char* text, Point org, int fontFace, double fontScale, + Scalar color, int thickness, int lineType, bool bottomLeftOrigin) { + cv::Point pt(org.x, org.y); + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + cv::putText(*img, text, pt, fontFace, fontScale, c, thickness, lineType, bottomLeftOrigin); +} + +void Resize(Mat src, Mat dst, Size dsize, double fx, double fy, int interp) { + cv::Size sz(dsize.width, dsize.height); + cv::resize(*src, *dst, sz, fx, fy, interp); +} + +void GetRectSubPix(Mat src, Size patchSize, Point center, Mat dst) { + cv::Size sz(patchSize.width, patchSize.height); + cv::Point pt(center.x, center.y); + cv::getRectSubPix(*src, sz, pt, *dst); +} + +Mat GetRotationMatrix2D(Point center, double angle, double scale) { + cv::Point pt(center.x, center.y); + return new cv::Mat(cv::getRotationMatrix2D(pt, angle, scale)); +} + +void WarpAffine(Mat src, Mat dst, Mat m, Size dsize) { + cv::Size sz(dsize.width, dsize.height); + cv::warpAffine(*src, *dst, *m, sz); +} + +void WarpAffineWithParams(Mat src, Mat dst, Mat rot_mat, Size dsize, int flags, int borderMode, + Scalar borderValue) { + cv::Size sz(dsize.width, dsize.height); + cv::Scalar c = cv::Scalar(borderValue.val1, borderValue.val2, borderValue.val3, borderValue.val4); + cv::warpAffine(*src, *dst, *rot_mat, sz, flags, borderMode, c); +} + +void WarpPerspective(Mat src, Mat dst, Mat m, Size dsize) { + cv::Size sz(dsize.width, dsize.height); + cv::warpPerspective(*src, *dst, *m, sz); +} + +void WarpPerspectiveWithParams(Mat src, Mat dst, Mat rot_mat, Size dsize, int flags, int borderMode, + Scalar borderValue) { + cv::Size sz(dsize.width, dsize.height); + cv::Scalar c = cv::Scalar(borderValue.val1, borderValue.val2, borderValue.val3, borderValue.val4); + cv::warpPerspective(*src, *dst, *rot_mat, sz, flags, borderMode, c); +} + +void Watershed(Mat image, Mat markers) { + cv::watershed(*image, *markers); +} + +void ApplyColorMap(Mat src, Mat dst, int colormap) { + cv::applyColorMap(*src, *dst, colormap); +} + +void ApplyCustomColorMap(Mat src, Mat dst, Mat colormap) { + cv::applyColorMap(*src, *dst, *colormap); +} + +Mat GetPerspectiveTransform(PointVector src, PointVector dst) { + std::vector src_pts; + copyPointVectorToPoint2fVector(src, &src_pts); + + std::vector dst_pts; + copyPointVectorToPoint2fVector(dst, &dst_pts); + + return new cv::Mat(cv::getPerspectiveTransform(src_pts, dst_pts)); +} + +Mat GetPerspectiveTransform2f(Point2fVector src, Point2fVector dst) { + return new cv::Mat(cv::getPerspectiveTransform(*src, *dst)); +} + +Mat GetAffineTransform(PointVector src, PointVector dst) { + std::vector src_pts; + copyPointVectorToPoint2fVector(src, &src_pts); + + std::vector dst_pts; + copyPointVectorToPoint2fVector(dst, &dst_pts); + + return new cv::Mat(cv::getAffineTransform(src_pts, dst_pts)); +} + +Mat GetAffineTransform2f(Point2fVector src, Point2fVector dst) { + return new cv::Mat(cv::getAffineTransform(*src, *dst)); +} + +Mat FindHomography(Mat src, Mat dst, int method, double ransacReprojThreshold, Mat mask, const int maxIters, const double confidence) { + return new cv::Mat(cv::findHomography(*src, *dst, method, ransacReprojThreshold, *mask, maxIters, confidence)); +} + +void DrawContours(Mat src, PointsVector contours, int contourIdx, Scalar color, int thickness) { + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + cv::drawContours(*src, *contours, contourIdx, c, thickness); +} + +void DrawContoursWithParams(Mat src, PointsVector contours, int contourIdx, Scalar color, int thickness, int lineType, Mat hierarchy, int maxLevel, Point offset) { + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + cv::Point offsetPt(offset.x, offset.y); + + std::vector vecHierarchy; + if (hierarchy->empty() == 0) { + for (int j = 0; j < hierarchy->cols; ++j) { + vecHierarchy.push_back(hierarchy->at(0, j)); + } + } + cv::drawContours(*src, *contours, contourIdx, c, thickness, lineType, vecHierarchy, maxLevel, offsetPt); +} + +void Sobel(Mat src, Mat dst, int ddepth, int dx, int dy, int ksize, double scale, double delta, int borderType) { + cv::Sobel(*src, *dst, ddepth, dx, dy, ksize, scale, delta, borderType); +} + +void SpatialGradient(Mat src, Mat dx, Mat dy, int ksize, int borderType) { + cv::spatialGradient(*src, *dx, *dy, ksize, borderType); +} + + +void Remap(Mat src, Mat dst, Mat map1, Mat map2, int interpolation, int borderMode, Scalar borderValue) { + cv::Scalar c = cv::Scalar(borderValue.val1, borderValue.val2, borderValue.val3, borderValue.val4); + cv::remap(*src, *dst, *map1, *map2, interpolation, borderMode, c); +} + +void Filter2D(Mat src, Mat dst, int ddepth, Mat kernel, Point anchor, double delta, int borderType) { + cv::Point anchorPt(anchor.x, anchor.y); + cv::filter2D(*src, *dst, ddepth, *kernel, anchorPt, delta, borderType); +} + +void SepFilter2D(Mat src, Mat dst, int ddepth, Mat kernelX, Mat kernelY, Point anchor, double delta, int borderType) { + cv::Point anchorPt(anchor.x, anchor.y); + cv::sepFilter2D(*src, *dst, ddepth, *kernelX, *kernelY, anchorPt, delta, borderType); +} + +void LogPolar(Mat src, Mat dst, Point center, double m, int flags) { + cv::Point2f centerPt(center.x, center.y); + cv::logPolar(*src, *dst, centerPt, m, flags); +} + +void FitLine(PointVector pts, Mat line, int distType, double param, double reps, double aeps) { + cv::fitLine(*pts, *line, distType, param, reps, aeps); +} + +void LinearPolar(Mat src, Mat dst, Point center, double maxRadius, int flags) { + cv::Point2f centerPt(center.x, center.y); + cv::linearPolar(*src, *dst, centerPt, maxRadius, flags); +} + +double MatchShapes(PointVector contour1, PointVector contour2, int method, double parameter) { + return cv::matchShapes(*contour1, *contour2, method, parameter); +} + +CLAHE CLAHE_Create() { + return new cv::Ptr(cv::createCLAHE()); +} + +CLAHE CLAHE_CreateWithParams(double clipLimit, Size tileGridSize) { + cv::Size sz(tileGridSize.width, tileGridSize.height); + return new cv::Ptr(cv::createCLAHE(clipLimit, sz)); +} + +void CLAHE_Close(CLAHE c) { + delete c; +} + +void CLAHE_Apply(CLAHE c, Mat src, Mat dst) { + (*c)->apply(*src, *dst); +} + +void InvertAffineTransform(Mat src, Mat dst) { + cv::invertAffineTransform(*src, *dst); +} + +Point2f PhaseCorrelate(Mat src1, Mat src2, Mat window, double* response) { + cv::Point2d result = cv::phaseCorrelate(*src1, *src2, *window, response); + + Point2f result2f = { + .x = float(result.x), + .y = float(result.y), + }; + return result2f; +} + +void Mat_Accumulate(Mat src, Mat dst) { + cv::accumulate(*src, *dst); +} +void Mat_AccumulateWithMask(Mat src, Mat dst, Mat mask) { + cv::accumulate(*src, *dst, *mask); +} + +void Mat_AccumulateSquare(Mat src, Mat dst) { + cv::accumulateSquare(*src, *dst); +} + +void Mat_AccumulateSquareWithMask(Mat src, Mat dst, Mat mask) { + cv::accumulateSquare(*src, *dst, *mask); +} + +void Mat_AccumulateProduct(Mat src1, Mat src2, Mat dst) { + cv::accumulateProduct(*src1, *src2, *dst); +} + +void Mat_AccumulateProductWithMask(Mat src1, Mat src2, Mat dst, Mat mask) { + cv::accumulateProduct(*src1, *src2, *dst, *mask); +} + +void Mat_AccumulatedWeighted(Mat src, Mat dst, double alpha) { + cv::accumulateWeighted(*src, *dst, alpha); +} + +void Mat_AccumulatedWeightedWithMask(Mat src, Mat dst, double alpha, Mat mask) { + cv::accumulateWeighted(*src, *dst, alpha, *mask); +} diff --git a/vendor/gocv.io/x/gocv/imgproc.go b/vendor/gocv.io/x/gocv/imgproc.go new file mode 100644 index 00000000..80fb091a --- /dev/null +++ b/vendor/gocv.io/x/gocv/imgproc.go @@ -0,0 +1,2179 @@ +package gocv + +/* +#include +#include "imgproc.h" +*/ +import "C" +import ( + "errors" + "image" + "image/color" + "reflect" + "unsafe" +) + +// ArcLength calculates a contour perimeter or a curve length. +// +// For further details, please see: +// +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga8d26483c636be6b35c3ec6335798a47c +func ArcLength(curve PointVector, isClosed bool) float64 { + return float64(C.ArcLength(curve.p, C.bool(isClosed))) +} + +// ApproxPolyDP approximates a polygonal curve(s) with the specified precision. +// +// For further details, please see: +// +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga0012a5fdaea70b8a9970165d98722b4c +func ApproxPolyDP(curve PointVector, epsilon float64, closed bool) PointVector { + return PointVector{p: C.ApproxPolyDP(curve.p, C.double(epsilon), C.bool(closed))} +} + +// ConvexHull finds the convex hull of a point set. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga014b28e56cb8854c0de4a211cb2be656 +func ConvexHull(points PointVector, hull *Mat, clockwise bool, returnPoints bool) { + C.ConvexHull(points.p, hull.p, C.bool(clockwise), C.bool(returnPoints)) +} + +// ConvexityDefects finds the convexity defects of a contour. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#gada4437098113fd8683c932e0567f47ba +func ConvexityDefects(contour PointVector, hull Mat, result *Mat) { + C.ConvexityDefects(contour.p, hull.p, result.p) +} + +// CvtColor converts an image from one color space to another. +// It converts the src Mat image to the dst Mat using the +// code param containing the desired ColorConversionCode color space. +// +// For further details, please see: +// http://docs.opencv.org/master/d7/d1b/group__imgproc__misc.html#ga4e0972be5de079fed4e3a10e24ef5ef0 +func CvtColor(src Mat, dst *Mat, code ColorConversionCode) { + C.CvtColor(src.p, dst.p, C.int(code)) +} + +// EqualizeHist normalizes the brightness and increases the contrast of the image. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/dc7/group__imgproc__hist.html#ga7e54091f0c937d49bf84152a16f76d6e +func EqualizeHist(src Mat, dst *Mat) { + C.EqualizeHist(src.p, dst.p) +} + +// CalcHist Calculates a histogram of a set of images +// +// For futher details, please see: +// https://docs.opencv.org/master/d6/dc7/group__imgproc__hist.html#ga6ca1876785483836f72a77ced8ea759a +func CalcHist(src []Mat, channels []int, mask Mat, hist *Mat, size []int, ranges []float64, acc bool) { + cMatArray := make([]C.Mat, len(src)) + for i, r := range src { + cMatArray[i] = r.p + } + + cMats := C.struct_Mats{ + mats: (*C.Mat)(&cMatArray[0]), + length: C.int(len(src)), + } + + chansInts := []C.int{} + for _, v := range channels { + chansInts = append(chansInts, C.int(v)) + } + chansVector := C.struct_IntVector{} + chansVector.val = (*C.int)(&chansInts[0]) + chansVector.length = (C.int)(len(chansInts)) + + sizeInts := []C.int{} + for _, v := range size { + sizeInts = append(sizeInts, C.int(v)) + } + sizeVector := C.struct_IntVector{} + sizeVector.val = (*C.int)(&sizeInts[0]) + sizeVector.length = (C.int)(len(sizeInts)) + + rangeFloats := []C.float{} + for _, v := range ranges { + rangeFloats = append(rangeFloats, C.float(v)) + } + rangeVector := C.struct_FloatVector{} + rangeVector.val = (*C.float)(&rangeFloats[0]) + rangeVector.length = (C.int)(len(rangeFloats)) + + C.CalcHist(cMats, chansVector, mask.p, hist.p, sizeVector, rangeVector, C.bool(acc)) +} + +// CalcBackProject calculates the back projection of a histogram. +// +// For futher details, please see: +// https://docs.opencv.org/3.4/d6/dc7/group__imgproc__hist.html#ga3a0af640716b456c3d14af8aee12e3ca +func CalcBackProject(src []Mat, channels []int, hist Mat, backProject *Mat, ranges []float64, uniform bool) { + cMatArray := make([]C.Mat, len(src)) + for i, r := range src { + cMatArray[i] = r.p + } + + cMats := C.struct_Mats{ + mats: (*C.Mat)(&cMatArray[0]), + length: C.int(len(src)), + } + + chansInts := []C.int{} + for _, v := range channels { + chansInts = append(chansInts, C.int(v)) + } + chansVector := C.struct_IntVector{} + chansVector.val = (*C.int)(&chansInts[0]) + chansVector.length = (C.int)(len(chansInts)) + + rangeFloats := []C.float{} + for _, v := range ranges { + rangeFloats = append(rangeFloats, C.float(v)) + } + rangeVector := C.struct_FloatVector{} + rangeVector.val = (*C.float)(&rangeFloats[0]) + rangeVector.length = (C.int)(len(rangeFloats)) + + C.CalcBackProject(cMats, chansVector, hist.p, backProject.p, rangeVector, C.bool(uniform)) +} + +// HistCompMethod is the method for Histogram comparison +// For more information, see https://docs.opencv.org/master/d6/dc7/group__imgproc__hist.html#ga994f53817d621e2e4228fc646342d386 +type HistCompMethod int + +const ( + // HistCmpCorrel calculates the Correlation + HistCmpCorrel HistCompMethod = 0 + + // HistCmpChiSqr calculates the Chi-Square + HistCmpChiSqr HistCompMethod = 1 + + // HistCmpIntersect calculates the Intersection + HistCmpIntersect HistCompMethod = 2 + + // HistCmpBhattacharya applies the HistCmpBhattacharya by calculating the Bhattacharya distance. + HistCmpBhattacharya HistCompMethod = 3 + + // HistCmpHellinger applies the HistCmpBhattacharya comparison. It is a synonym to HistCmpBhattacharya. + HistCmpHellinger = HistCmpBhattacharya + + // HistCmpChiSqrAlt applies the Alternative Chi-Square (regularly used for texture comparsion). + HistCmpChiSqrAlt HistCompMethod = 4 + + // HistCmpKlDiv applies the Kullback-Liebler divergence comparison. + HistCmpKlDiv HistCompMethod = 5 +) + +// CompareHist Compares two histograms. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/dc7/group__imgproc__hist.html#gaf4190090efa5c47cb367cf97a9a519bd +func CompareHist(hist1 Mat, hist2 Mat, method HistCompMethod) float32 { + return float32(C.CompareHist(hist1.p, hist2.p, C.int(method))) +} + +// ClipLine clips the line against the image rectangle. +// For further details, please see: +// https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#gaf483cb46ad6b049bc35ec67052ef1c2c +func ClipLine(imgSize image.Point, pt1 image.Point, pt2 image.Point) bool { + pSize := C.struct_Size{ + width: C.int(imgSize.X), + height: C.int(imgSize.Y), + } + + rPt1 := C.struct_Point{ + x: C.int(pt1.X), + y: C.int(pt1.Y), + } + + rPt2 := C.struct_Point{ + x: C.int(pt2.X), + y: C.int(pt2.Y), + } + + return bool(C.ClipLine(pSize, rPt1, rPt2)) +} + +// BilateralFilter applies a bilateral filter to an image. +// +// Bilateral filtering is described here: +// http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html +// +// BilateralFilter can reduce unwanted noise very well while keeping edges +// fairly sharp. However, it is very slow compared to most filters. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga9d7064d478c95d60003cf839430737ed +func BilateralFilter(src Mat, dst *Mat, diameter int, sigmaColor float64, sigmaSpace float64) { + C.BilateralFilter(src.p, dst.p, C.int(diameter), C.double(sigmaColor), C.double(sigmaSpace)) +} + +// Blur blurs an image Mat using a normalized box filter. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga8c45db9afe636703801b0b2e440fce37 +func Blur(src Mat, dst *Mat, ksize image.Point) { + pSize := C.struct_Size{ + width: C.int(ksize.X), + height: C.int(ksize.Y), + } + + C.Blur(src.p, dst.p, pSize) +} + +// BoxFilter blurs an image using the box filter. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gad533230ebf2d42509547d514f7d3fbc3 +func BoxFilter(src Mat, dst *Mat, depth int, ksize image.Point) { + pSize := C.struct_Size{ + height: C.int(ksize.X), + width: C.int(ksize.Y), + } + C.BoxFilter(src.p, dst.p, C.int(depth), pSize) +} + +// SqBoxFilter calculates the normalized sum of squares of the pixel values overlapping the filter. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga045028184a9ef65d7d2579e5c4bff6c0 +func SqBoxFilter(src Mat, dst *Mat, depth int, ksize image.Point) { + pSize := C.struct_Size{ + height: C.int(ksize.X), + width: C.int(ksize.Y), + } + C.SqBoxFilter(src.p, dst.p, C.int(depth), pSize) +} + +// Dilate dilates an image by using a specific structuring element. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga4ff0f3318642c4f469d0e11f242f3b6c +func Dilate(src Mat, dst *Mat, kernel Mat) { + C.Dilate(src.p, dst.p, kernel.p) +} + +// DilateWithParams dilates an image by using a specific structuring element. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga4ff0f3318642c4f469d0e11f242f3b6c +func DilateWithParams(src Mat, dst *Mat, kernel Mat, anchor image.Point, iterations, borderType BorderType, borderValue color.RGBA) { + cAnchor := C.struct_Point{ + x: C.int(anchor.X), + y: C.int(anchor.Y), + } + + bv := C.struct_Scalar{ + val1: C.double(borderValue.B), + val2: C.double(borderValue.G), + val3: C.double(borderValue.R), + val4: C.double(borderValue.A), + } + + C.DilateWithParams(src.p, dst.p, kernel.p, cAnchor, C.int(iterations), C.int(borderType), bv) +} + +// DistanceTransformLabelTypes are the types of the DistanceTransform algorithm flag +type DistanceTransformLabelTypes int + +const ( + // DistanceLabelCComp assigns the same label to each connected component of zeros in the source image + // (as well as all the non-zero pixels closest to the connected component). + DistanceLabelCComp DistanceTransformLabelTypes = 0 + + // DistanceLabelPixel assigns its own label to each zero pixel (and all the non-zero pixels closest to it). + DistanceLabelPixel +) + +// DistanceTransformMasks are the marsk sizes for distance transform +type DistanceTransformMasks int + +const ( + // DistanceMask3 is a mask of size 3 + DistanceMask3 DistanceTransformMasks = 0 + + // DistanceMask5 is a mask of size 3 + DistanceMask5 + + // DistanceMaskPrecise is not currently supported + DistanceMaskPrecise +) + +// DistanceTransform Calculates the distance to the closest zero pixel for each pixel of the source image. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/d1b/group__imgproc__misc.html#ga8a0b7fdfcb7a13dde018988ba3a43042 +func DistanceTransform(src Mat, dst *Mat, labels *Mat, distType DistanceTypes, maskSize DistanceTransformMasks, labelType DistanceTransformLabelTypes) { + C.DistanceTransform(src.p, dst.p, labels.p, C.int(distType), C.int(maskSize), C.int(labelType)) +} + +// Erode erodes an image by using a specific structuring element. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gaeb1e0c1033e3f6b891a25d0511362aeb +func Erode(src Mat, dst *Mat, kernel Mat) { + C.Erode(src.p, dst.p, kernel.p) +} + +// ErodeWithParams erodes an image by using a specific structuring element. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gaeb1e0c1033e3f6b891a25d0511362aeb +func ErodeWithParams(src Mat, dst *Mat, kernel Mat, anchor image.Point, iterations, borderType int) { + cAnchor := C.struct_Point{ + x: C.int(anchor.X), + y: C.int(anchor.Y), + } + + C.ErodeWithParams(src.p, dst.p, kernel.p, cAnchor, C.int(iterations), C.int(borderType)) +} + +// RetrievalMode is the mode of the contour retrieval algorithm. +type RetrievalMode int + +const ( + // RetrievalExternal retrieves only the extreme outer contours. + // It sets `hierarchy[i][2]=hierarchy[i][3]=-1` for all the contours. + RetrievalExternal RetrievalMode = 0 + + // RetrievalList retrieves all of the contours without establishing + // any hierarchical relationships. + RetrievalList RetrievalMode = 1 + + // RetrievalCComp retrieves all of the contours and organizes them into + // a two-level hierarchy. At the top level, there are external boundaries + // of the components. At the second level, there are boundaries of the holes. + // If there is another contour inside a hole of a connected component, it + // is still put at the top level. + RetrievalCComp RetrievalMode = 2 + + // RetrievalTree retrieves all of the contours and reconstructs a full + // hierarchy of nested contours. + RetrievalTree RetrievalMode = 3 + + // RetrievalFloodfill lacks a description in the original header. + RetrievalFloodfill RetrievalMode = 4 +) + +// ContourApproximationMode is the mode of the contour approximation algorithm. +type ContourApproximationMode int + +const ( + // ChainApproxNone stores absolutely all the contour points. That is, + // any 2 subsequent points (x1,y1) and (x2,y2) of the contour will be + // either horizontal, vertical or diagonal neighbors, that is, + // max(abs(x1-x2),abs(y2-y1))==1. + ChainApproxNone ContourApproximationMode = 1 + + // ChainApproxSimple compresses horizontal, vertical, and diagonal segments + // and leaves only their end points. + // For example, an up-right rectangular contour is encoded with 4 points. + ChainApproxSimple ContourApproximationMode = 2 + + // ChainApproxTC89L1 applies one of the flavors of the Teh-Chin chain + // approximation algorithms. + ChainApproxTC89L1 ContourApproximationMode = 3 + + // ChainApproxTC89KCOS applies one of the flavors of the Teh-Chin chain + // approximation algorithms. + ChainApproxTC89KCOS ContourApproximationMode = 4 +) + +// BoundingRect calculates the up-right bounding rectangle of a point set. +// +// For further details, please see: +// https://docs.opencv.org/3.3.0/d3/dc0/group__imgproc__shape.html#gacb413ddce8e48ff3ca61ed7cf626a366 +func BoundingRect(contour PointVector) image.Rectangle { + r := C.BoundingRect(contour.p) + rect := image.Rect(int(r.x), int(r.y), int(r.x+r.width), int(r.y+r.height)) + return rect +} + +// BoxPoints finds the four vertices of a rotated rect. Useful to draw the rotated rectangle. +// +// For further Details, please see: +// https://docs.opencv.org/3.3.0/d3/dc0/group__imgproc__shape.html#gaf78d467e024b4d7936cf9397185d2f5c +func BoxPoints(rect RotatedRect, pts *Mat) { + rPoints := toCPoints(rect.Points) + + rRect := C.struct_Rect{ + x: C.int(rect.BoundingRect.Min.X), + y: C.int(rect.BoundingRect.Min.Y), + width: C.int(rect.BoundingRect.Max.X - rect.BoundingRect.Min.X), + height: C.int(rect.BoundingRect.Max.Y - rect.BoundingRect.Min.Y), + } + + rCenter := C.struct_Point{ + x: C.int(rect.Center.X), + y: C.int(rect.Center.Y), + } + + rSize := C.struct_Size{ + width: C.int(rect.Width), + height: C.int(rect.Height), + } + + r := C.struct_RotatedRect{ + pts: rPoints, + boundingRect: rRect, + center: rCenter, + size: rSize, + angle: C.double(rect.Angle), + } + + C.BoxPoints(r, pts.p) +} + +// ContourArea calculates a contour area. +// +// For further details, please see: +// https://docs.opencv.org/3.3.0/d3/dc0/group__imgproc__shape.html#ga2c759ed9f497d4a618048a2f56dc97f1 +func ContourArea(contour PointVector) float64 { + result := C.ContourArea(contour.p) + return float64(result) +} + +type RotatedRect struct { + Points []image.Point + BoundingRect image.Rectangle + Center image.Point + Width int + Height int + Angle float64 +} + +// toPoints converts C.Contour to []image.Points +func toPoints(points C.Contour) []image.Point { + pArray := points.points + pLength := int(points.length) + + pHdr := reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(pArray)), + Len: pLength, + Cap: pLength, + } + sPoints := *(*[]C.Point)(unsafe.Pointer(&pHdr)) + + points4 := make([]image.Point, pLength) + for j, pt := range sPoints { + points4[j] = image.Pt(int(pt.x), int(pt.y)) + } + return points4 +} + +// MinAreaRect finds a rotated rectangle of the minimum area enclosing the input 2D point set. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga3d476a3417130ae5154aea421ca7ead9 +func MinAreaRect(points PointVector) RotatedRect { + result := C.MinAreaRect(points.p) + defer C.Points_Close(result.pts) + + return RotatedRect{ + Points: toPoints(result.pts), + BoundingRect: image.Rect(int(result.boundingRect.x), int(result.boundingRect.y), int(result.boundingRect.x)+int(result.boundingRect.width), int(result.boundingRect.y)+int(result.boundingRect.height)), + Center: image.Pt(int(result.center.x), int(result.center.y)), + Width: int(result.size.width), + Height: int(result.size.height), + Angle: float64(result.angle), + } +} + +// FitEllipse Fits an ellipse around a set of 2D points. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#gaf259efaad93098103d6c27b9e4900ffa +func FitEllipse(pts PointVector) RotatedRect { + cRect := C.FitEllipse(pts.p) + defer C.Points_Close(cRect.pts) + + return RotatedRect{ + Points: toPoints(cRect.pts), + BoundingRect: image.Rect(int(cRect.boundingRect.x), int(cRect.boundingRect.y), int(cRect.boundingRect.x)+int(cRect.boundingRect.width), int(cRect.boundingRect.y)+int(cRect.boundingRect.height)), + Center: image.Pt(int(cRect.center.x), int(cRect.center.y)), + Width: int(cRect.size.width), + Height: int(cRect.size.height), + Angle: float64(cRect.angle), + } + +} + +// MinEnclosingCircle finds a circle of the minimum area enclosing the input 2D point set. +// +// For further details, please see: +// https://docs.opencv.org/3.4/d3/dc0/group__imgproc__shape.html#ga8ce13c24081bbc7151e9326f412190f1 +func MinEnclosingCircle(pts PointVector) (x, y, radius float32) { + cCenterPoint := C.struct_Point2f{} + var cRadius C.float + C.MinEnclosingCircle(pts.p, &cCenterPoint, &cRadius) + x, y = float32(cCenterPoint.x), float32(cCenterPoint.y) + radius = float32(cRadius) + return x, y, radius +} + +// FindContours finds contours in a binary image. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga95f5b48d01abc7c2e0732db24689837b +func FindContours(src Mat, mode RetrievalMode, method ContourApproximationMode) PointsVector { + hierarchy := NewMat() + defer hierarchy.Close() + return FindContoursWithParams(src, &hierarchy, mode, method) +} + +// FindContoursWithParams finds contours in a binary image. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga17ed9f5d79ae97bd4c7cf18403e1689a +func FindContoursWithParams(src Mat, hierarchy *Mat, mode RetrievalMode, method ContourApproximationMode) PointsVector { + return PointsVector{p: C.FindContours(src.p, hierarchy.p, C.int(mode), C.int(method))} +} + +// PointPolygonTest performs a point-in-contour test. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga1a539e8db2135af2566103705d7a5722 +func PointPolygonTest(pts PointVector, pt image.Point, measureDist bool) float64 { + cp := C.struct_Point{ + x: C.int(pt.X), + y: C.int(pt.Y), + } + return float64(C.PointPolygonTest(pts.p, cp, C.bool(measureDist))) +} + +// ConnectedComponentsAlgorithmType specifies the type for ConnectedComponents +type ConnectedComponentsAlgorithmType int + +const ( + // SAUF algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. + CCL_WU ConnectedComponentsAlgorithmType = 0 + + // BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. + CCL_DEFAULT ConnectedComponentsAlgorithmType = 1 + + // BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity + CCL_GRANA ConnectedComponentsAlgorithmType = 2 +) + +// ConnectedComponents computes the connected components labeled image of boolean image. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#gaedef8c7340499ca391d459122e51bef5 +func ConnectedComponents(src Mat, labels *Mat) int { + return int(C.ConnectedComponents(src.p, labels.p, C.int(8), C.int(MatTypeCV32S), C.int(CCL_DEFAULT))) +} + +// ConnectedComponents computes the connected components labeled image of boolean image. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#gaedef8c7340499ca391d459122e51bef5 +func ConnectedComponentsWithParams(src Mat, labels *Mat, conn int, ltype MatType, + ccltype ConnectedComponentsAlgorithmType) int { + return int(C.ConnectedComponents(src.p, labels.p, C.int(conn), C.int(ltype), C.int(ccltype))) +} + +// ConnectedComponentsTypes are the connected components algorithm output formats +type ConnectedComponentsTypes int + +const ( + //The leftmost (x) coordinate which is the inclusive start of the bounding box in the horizontal direction. + CC_STAT_LEFT ConnectedComponentsTypes = 0 + + //The topmost (y) coordinate which is the inclusive start of the bounding box in the vertical direction. + CC_STAT_TOP ConnectedComponentsTypes = 1 + + // The horizontal size of the bounding box. + CC_STAT_WIDTH ConnectedComponentsTypes = 2 + + // The vertical size of the bounding box. + CC_STAT_HEIGHT ConnectedComponentsTypes = 3 + + // The total area (in pixels) of the connected component. + CC_STAT_AREA ConnectedComponentsTypes = 4 + + CC_STAT_MAX ConnectedComponentsTypes = 5 +) + +// ConnectedComponentsWithStats computes the connected components labeled image of boolean +// image and also produces a statistics output for each label. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga107a78bf7cd25dec05fb4dfc5c9e765f +func ConnectedComponentsWithStats(src Mat, labels *Mat, stats *Mat, centroids *Mat) int { + return int(C.ConnectedComponentsWithStats(src.p, labels.p, stats.p, centroids.p, + C.int(8), C.int(MatTypeCV32S), C.int(CCL_DEFAULT))) +} + +// ConnectedComponentsWithStats computes the connected components labeled image of boolean +// image and also produces a statistics output for each label. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga107a78bf7cd25dec05fb4dfc5c9e765f +func ConnectedComponentsWithStatsWithParams(src Mat, labels *Mat, stats *Mat, centroids *Mat, + conn int, ltype MatType, ccltype ConnectedComponentsAlgorithmType) int { + return int(C.ConnectedComponentsWithStats(src.p, labels.p, stats.p, centroids.p, C.int(conn), + C.int(ltype), C.int(ccltype))) +} + +// TemplateMatchMode is the type of the template matching operation. +type TemplateMatchMode int + +const ( + // TmSqdiff maps to TM_SQDIFF + TmSqdiff TemplateMatchMode = 0 + // TmSqdiffNormed maps to TM_SQDIFF_NORMED + TmSqdiffNormed TemplateMatchMode = 1 + // TmCcorr maps to TM_CCORR + TmCcorr TemplateMatchMode = 2 + // TmCcorrNormed maps to TM_CCORR_NORMED + TmCcorrNormed TemplateMatchMode = 3 + // TmCcoeff maps to TM_CCOEFF + TmCcoeff TemplateMatchMode = 4 + // TmCcoeffNormed maps to TM_CCOEFF_NORMED + TmCcoeffNormed TemplateMatchMode = 5 +) + +// MatchTemplate compares a template against overlapped image regions. +// +// For further details, please see: +// https://docs.opencv.org/master/df/dfb/group__imgproc__object.html#ga586ebfb0a7fb604b35a23d85391329be +func MatchTemplate(image Mat, templ Mat, result *Mat, method TemplateMatchMode, mask Mat) { + C.MatchTemplate(image.p, templ.p, result.p, C.int(method), mask.p) +} + +// Moments calculates all of the moments up to the third order of a polygon +// or rasterized shape. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga556a180f43cab22649c23ada36a8a139 +func Moments(src Mat, binaryImage bool) map[string]float64 { + r := C.Moments(src.p, C.bool(binaryImage)) + + result := make(map[string]float64) + result["m00"] = float64(r.m00) + result["m10"] = float64(r.m10) + result["m01"] = float64(r.m01) + result["m20"] = float64(r.m20) + result["m11"] = float64(r.m11) + result["m02"] = float64(r.m02) + result["m30"] = float64(r.m30) + result["m21"] = float64(r.m21) + result["m12"] = float64(r.m12) + result["m03"] = float64(r.m03) + result["mu20"] = float64(r.mu20) + result["mu11"] = float64(r.mu11) + result["mu02"] = float64(r.mu02) + result["mu30"] = float64(r.mu30) + result["mu21"] = float64(r.mu21) + result["mu12"] = float64(r.mu12) + result["mu03"] = float64(r.mu03) + result["nu20"] = float64(r.nu20) + result["nu11"] = float64(r.nu11) + result["nu02"] = float64(r.nu02) + result["nu30"] = float64(r.nu30) + result["nu21"] = float64(r.nu21) + result["nu12"] = float64(r.nu12) + result["nu03"] = float64(r.nu03) + + return result +} + +// PyrDown blurs an image and downsamples it. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gaf9bba239dfca11654cb7f50f889fc2ff +func PyrDown(src Mat, dst *Mat, ksize image.Point, borderType BorderType) { + pSize := C.struct_Size{ + height: C.int(ksize.X), + width: C.int(ksize.Y), + } + C.PyrDown(src.p, dst.p, pSize, C.int(borderType)) +} + +// PyrUp upsamples an image and then blurs it. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gada75b59bdaaca411ed6fee10085eb784 +func PyrUp(src Mat, dst *Mat, ksize image.Point, borderType BorderType) { + pSize := C.struct_Size{ + height: C.int(ksize.X), + width: C.int(ksize.Y), + } + C.PyrUp(src.p, dst.p, pSize, C.int(borderType)) +} + +// MorphologyDefaultBorder returns "magic" border value for erosion and dilation. +// It is automatically transformed to Scalar::all(-DBL_MAX) for dilation. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga94756fad83d9d24d29c9bf478558c40a +func MorphologyDefaultBorderValue() Scalar { + var scalar C.Scalar = C.MorphologyDefaultBorderValue() + return NewScalar(float64(scalar.val1), float64(scalar.val2), float64(scalar.val3), float64(scalar.val4)) +} + +// MorphologyEx performs advanced morphological transformations. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga67493776e3ad1a3df63883829375201f +func MorphologyEx(src Mat, dst *Mat, op MorphType, kernel Mat) { + C.MorphologyEx(src.p, dst.p, C.int(op), kernel.p) +} + +// MorphologyExWithParams performs advanced morphological transformations. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga67493776e3ad1a3df63883829375201f +func MorphologyExWithParams(src Mat, dst *Mat, op MorphType, kernel Mat, iterations int, borderType BorderType) { + pt := C.struct_Point{ + x: C.int(-1), + y: C.int(-1), + } + C.MorphologyExWithParams(src.p, dst.p, C.int(op), kernel.p, pt, C.int(iterations), C.int(borderType)) +} + +// MorphShape is the shape of the structuring element used for Morphing operations. +type MorphShape int + +const ( + // MorphRect is the rectangular morph shape. + MorphRect MorphShape = 0 + + // MorphCross is the cross morph shape. + MorphCross MorphShape = 1 + + // MorphEllipse is the ellipse morph shape. + MorphEllipse MorphShape = 2 +) + +// GetStructuringElement returns a structuring element of the specified size +// and shape for morphological operations. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gac342a1bb6eabf6f55c803b09268e36dc +func GetStructuringElement(shape MorphShape, ksize image.Point) Mat { + sz := C.struct_Size{ + width: C.int(ksize.X), + height: C.int(ksize.Y), + } + + return newMat(C.GetStructuringElement(C.int(shape), sz)) +} + +// MorphType type of morphological operation. +type MorphType int + +const ( + // MorphErode operation + MorphErode MorphType = 0 + + // MorphDilate operation + MorphDilate MorphType = 1 + + // MorphOpen operation + MorphOpen MorphType = 2 + + // MorphClose operation + MorphClose MorphType = 3 + + // MorphGradient operation + MorphGradient MorphType = 4 + + // MorphTophat operation + MorphTophat MorphType = 5 + + // MorphBlackhat operation + MorphBlackhat MorphType = 6 + + // MorphHitmiss operation + MorphHitmiss MorphType = 7 +) + +// BorderType type of border. +type BorderType int + +const ( + // BorderConstant border type + BorderConstant BorderType = 0 + + // BorderReplicate border type + BorderReplicate BorderType = 1 + + // BorderReflect border type + BorderReflect BorderType = 2 + + // BorderWrap border type + BorderWrap BorderType = 3 + + // BorderReflect101 border type + BorderReflect101 BorderType = 4 + + // BorderTransparent border type + BorderTransparent BorderType = 5 + + // BorderDefault border type + BorderDefault = BorderReflect101 + + // BorderIsolated border type + BorderIsolated BorderType = 16 +) + +// GaussianBlur blurs an image Mat using a Gaussian filter. +// The function convolves the src Mat image into the dst Mat using +// the specified Gaussian kernel params. +// +// For further details, please see: +// http://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gaabe8c836e97159a9193fb0b11ac52cf1 +func GaussianBlur(src Mat, dst *Mat, ksize image.Point, sigmaX float64, + sigmaY float64, borderType BorderType) { + pSize := C.struct_Size{ + width: C.int(ksize.X), + height: C.int(ksize.Y), + } + + C.GaussianBlur(src.p, dst.p, pSize, C.double(sigmaX), C.double(sigmaY), C.int(borderType)) +} + +// GetGaussianKernel returns Gaussian filter coefficients. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gac05a120c1ae92a6060dd0db190a61afa +func GetGaussianKernel(ksize int, sigma float64) Mat { + return newMat(C.GetGaussianKernel(C.int(ksize), C.double(sigma), C.int(MatTypeCV64F))) +} + +// GetGaussianKernelWithParams returns Gaussian filter coefficients. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gac05a120c1ae92a6060dd0db190a61afa +func GetGaussianKernelWithParams(ksize int, sigma float64, ktype MatType) Mat { + return newMat(C.GetGaussianKernel(C.int(ksize), C.double(sigma), C.int(ktype))) +} + +// Sobel calculates the first, second, third, or mixed image derivatives using an extended Sobel operator +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gacea54f142e81b6758cb6f375ce782c8d +func Sobel(src Mat, dst *Mat, ddepth MatType, dx, dy, ksize int, scale, delta float64, borderType BorderType) { + C.Sobel(src.p, dst.p, C.int(ddepth), C.int(dx), C.int(dy), C.int(ksize), C.double(scale), C.double(delta), C.int(borderType)) +} + +// SpatialGradient calculates the first order image derivative in both x and y using a Sobel operator. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga405d03b20c782b65a4daf54d233239a2 +func SpatialGradient(src Mat, dx, dy *Mat, ksize MatType, borderType BorderType) { + C.SpatialGradient(src.p, dx.p, dy.p, C.int(ksize), C.int(borderType)) +} + +// Laplacian calculates the Laplacian of an image. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gad78703e4c8fe703d479c1860d76429e6 +func Laplacian(src Mat, dst *Mat, dDepth MatType, size int, scale float64, + delta float64, borderType BorderType) { + C.Laplacian(src.p, dst.p, C.int(dDepth), C.int(size), C.double(scale), C.double(delta), C.int(borderType)) +} + +// Scharr calculates the first x- or y- image derivative using Scharr operator. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gaa13106761eedf14798f37aa2d60404c9 +func Scharr(src Mat, dst *Mat, dDepth MatType, dx int, dy int, scale float64, + delta float64, borderType BorderType) { + C.Scharr(src.p, dst.p, C.int(dDepth), C.int(dx), C.int(dy), C.double(scale), C.double(delta), C.int(borderType)) +} + +// MedianBlur blurs an image using the median filter. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga564869aa33e58769b4469101aac458f9 +func MedianBlur(src Mat, dst *Mat, ksize int) { + C.MedianBlur(src.p, dst.p, C.int(ksize)) +} + +// Canny finds edges in an image using the Canny algorithm. +// The function finds edges in the input image image and marks +// them in the output map edges using the Canny algorithm. +// The smallest value between threshold1 and threshold2 is used +// for edge linking. The largest value is used to +// find initial segments of strong edges. +// See http://en.wikipedia.org/wiki/Canny_edge_detector +// +// For further details, please see: +// http://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#ga04723e007ed888ddf11d9ba04e2232de +func Canny(src Mat, edges *Mat, t1 float32, t2 float32) { + C.Canny(src.p, edges.p, C.double(t1), C.double(t2)) +} + +// CornerSubPix Refines the corner locations. The function iterates to find +// the sub-pixel accurate location of corners or radial saddle points. +// +// For further details, please see: +// https://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#ga354e0d7c86d0d9da75de9b9701a9a87e +func CornerSubPix(img Mat, corners *Mat, winSize image.Point, zeroZone image.Point, criteria TermCriteria) { + winSz := C.struct_Size{ + width: C.int(winSize.X), + height: C.int(winSize.Y), + } + + zeroSz := C.struct_Size{ + width: C.int(zeroZone.X), + height: C.int(zeroZone.Y), + } + + C.CornerSubPix(img.p, corners.p, winSz, zeroSz, criteria.p) + return +} + +// GoodFeaturesToTrack determines strong corners on an image. The function +// finds the most prominent corners in the image or in the specified image region. +// +// For further details, please see: +// https://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#ga1d6bb77486c8f92d79c8793ad995d541 +func GoodFeaturesToTrack(img Mat, corners *Mat, maxCorners int, quality float64, minDist float64) { + C.GoodFeaturesToTrack(img.p, corners.p, C.int(maxCorners), C.double(quality), C.double(minDist)) +} + +// GrabCutMode is the flag for GrabCut algorithm. +type GrabCutMode int + +const ( + // GCInitWithRect makes the function initialize the state and the mask using the provided rectangle. + // After that it runs the itercount iterations of the algorithm. + GCInitWithRect GrabCutMode = 0 + // GCInitWithMask makes the function initialize the state using the provided mask. + // GCInitWithMask and GCInitWithRect can be combined. + // Then all the pixels outside of the ROI are automatically initialized with GC_BGD. + GCInitWithMask GrabCutMode = 1 + // GCEval means that the algorithm should just resume. + GCEval GrabCutMode = 2 + // GCEvalFreezeModel means that the algorithm should just run a single iteration of the GrabCut algorithm + // with the fixed model + GCEvalFreezeModel GrabCutMode = 3 +) + +// Grabcut runs the GrabCut algorithm. +// The function implements the GrabCut image segmentation algorithm. +// For further details, please see: +// https://docs.opencv.org/master/d7/d1b/group__imgproc__misc.html#ga909c1dda50efcbeaa3ce126be862b37f +func GrabCut(img Mat, mask *Mat, r image.Rectangle, bgdModel *Mat, fgdModel *Mat, iterCount int, mode GrabCutMode) { + cRect := C.struct_Rect{ + x: C.int(r.Min.X), + y: C.int(r.Min.Y), + width: C.int(r.Size().X), + height: C.int(r.Size().Y), + } + + C.GrabCut(img.p, mask.p, cRect, bgdModel.p, fgdModel.p, C.int(iterCount), C.int(mode)) +} + +// HoughMode is the type for Hough transform variants. +type HoughMode int + +const ( + // HoughStandard is the classical or standard Hough transform. + HoughStandard HoughMode = 0 + // HoughProbabilistic is the probabilistic Hough transform (more efficient + // in case if the picture contains a few long linear segments). + HoughProbabilistic HoughMode = 1 + // HoughMultiScale is the multi-scale variant of the classical Hough + // transform. + HoughMultiScale HoughMode = 2 + // HoughGradient is basically 21HT, described in: HK Yuen, John Princen, + // John Illingworth, and Josef Kittler. Comparative study of hough + // transform methods for circle finding. Image and Vision Computing, + // 8(1):71–77, 1990. + HoughGradient HoughMode = 3 +) + +// HoughCircles finds circles in a grayscale image using the Hough transform. +// The only "method" currently supported is HoughGradient. If you want to pass +// more parameters, please see `HoughCirclesWithParams`. +// +// For further details, please see: +// https://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#ga47849c3be0d0406ad3ca45db65a25d2d +func HoughCircles(src Mat, circles *Mat, method HoughMode, dp, minDist float64) { + C.HoughCircles(src.p, circles.p, C.int(method), C.double(dp), C.double(minDist)) +} + +// HoughCirclesWithParams finds circles in a grayscale image using the Hough +// transform. The only "method" currently supported is HoughGradient. +// +// For further details, please see: +// https://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#ga47849c3be0d0406ad3ca45db65a25d2d +func HoughCirclesWithParams(src Mat, circles *Mat, method HoughMode, dp, minDist, param1, param2 float64, minRadius, maxRadius int) { + C.HoughCirclesWithParams(src.p, circles.p, C.int(method), C.double(dp), C.double(minDist), C.double(param1), C.double(param2), C.int(minRadius), C.int(maxRadius)) +} + +// HoughLines implements the standard or standard multi-scale Hough transform +// algorithm for line detection. For a good explanation of Hough transform, see: +// http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm +// +// For further details, please see: +// http://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#ga46b4e588934f6c8dfd509cc6e0e4545a +func HoughLines(src Mat, lines *Mat, rho float32, theta float32, threshold int) { + C.HoughLines(src.p, lines.p, C.double(rho), C.double(theta), C.int(threshold)) +} + +// HoughLinesP implements the probabilistic Hough transform +// algorithm for line detection. For a good explanation of Hough transform, see: +// http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm +// +// For further details, please see: +// http://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#ga8618180a5948286384e3b7ca02f6feeb +func HoughLinesP(src Mat, lines *Mat, rho float32, theta float32, threshold int) { + C.HoughLinesP(src.p, lines.p, C.double(rho), C.double(theta), C.int(threshold)) +} +func HoughLinesPWithParams(src Mat, lines *Mat, rho float32, theta float32, threshold int, minLineLength float32, maxLineGap float32) { + C.HoughLinesPWithParams(src.p, lines.p, C.double(rho), C.double(theta), C.int(threshold), C.double(minLineLength), C.double(maxLineGap)) +} + +// HoughLinesPointSet implements the Hough transform algorithm for line +// detection on a set of points. For a good explanation of Hough transform, see: +// http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm +// +// For further details, please see: +// https://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#ga2858ef61b4e47d1919facac2152a160e +func HoughLinesPointSet(points Mat, lines *Mat, linesMax int, threshold int, + minRho float32, maxRho float32, rhoStep float32, + minTheta float32, maxTheta float32, thetaStep float32) { + C.HoughLinesPointSet(points.p, lines.p, C.int(linesMax), C.int(threshold), + C.double(minRho), C.double(maxRho), C.double(rhoStep), + C.double(minTheta), C.double(maxTheta), C.double(thetaStep)) +} + +// Integral calculates one or more integral images for the source image. +// For further details, please see: +// https://docs.opencv.org/master/d7/d1b/group__imgproc__misc.html#ga97b87bec26908237e8ba0f6e96d23e28 +func Integral(src Mat, sum *Mat, sqsum *Mat, tilted *Mat) { + C.Integral(src.p, sum.p, sqsum.p, tilted.p) +} + +// ThresholdType type of threshold operation. +type ThresholdType int + +const ( + // ThresholdBinary threshold type + ThresholdBinary ThresholdType = 0 + + // ThresholdBinaryInv threshold type + ThresholdBinaryInv ThresholdType = 1 + + // ThresholdTrunc threshold type + ThresholdTrunc ThresholdType = 2 + + // ThresholdToZero threshold type + ThresholdToZero ThresholdType = 3 + + // ThresholdToZeroInv threshold type + ThresholdToZeroInv ThresholdType = 4 + + // ThresholdMask threshold type + ThresholdMask ThresholdType = 7 + + // ThresholdOtsu threshold type + ThresholdOtsu ThresholdType = 8 + + // ThresholdTriangle threshold type + ThresholdTriangle ThresholdType = 16 +) + +// Threshold applies a fixed-level threshold to each array element. +// +// For further details, please see: +// https://docs.opencv.org/3.3.0/d7/d1b/group__imgproc__misc.html#gae8a4a146d1ca78c626a53577199e9c57 +func Threshold(src Mat, dst *Mat, thresh float32, maxvalue float32, typ ThresholdType) (threshold float32) { + return float32(C.Threshold(src.p, dst.p, C.double(thresh), C.double(maxvalue), C.int(typ))) +} + +// AdaptiveThresholdType type of adaptive threshold operation. +type AdaptiveThresholdType int + +const ( + // AdaptiveThresholdMean threshold type + AdaptiveThresholdMean AdaptiveThresholdType = 0 + + // AdaptiveThresholdGaussian threshold type + AdaptiveThresholdGaussian AdaptiveThresholdType = 1 +) + +// AdaptiveThreshold applies a fixed-level threshold to each array element. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/d1b/group__imgproc__misc.html#ga72b913f352e4a1b1b397736707afcde3 +func AdaptiveThreshold(src Mat, dst *Mat, maxValue float32, adaptiveTyp AdaptiveThresholdType, typ ThresholdType, blockSize int, c float32) { + C.AdaptiveThreshold(src.p, dst.p, C.double(maxValue), C.int(adaptiveTyp), C.int(typ), C.int(blockSize), C.double(c)) +} + +// ArrowedLine draws a arrow segment pointing from the first point +// to the second one. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga0a165a3ca093fd488ac709fdf10c05b2 +func ArrowedLine(img *Mat, pt1 image.Point, pt2 image.Point, c color.RGBA, thickness int) { + sp1 := C.struct_Point{ + x: C.int(pt1.X), + y: C.int(pt1.Y), + } + + sp2 := C.struct_Point{ + x: C.int(pt2.X), + y: C.int(pt2.Y), + } + + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.ArrowedLine(img.p, sp1, sp2, sColor, C.int(thickness)) +} + +// Circle draws a circle. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#gaf10604b069374903dbd0f0488cb43670 +func Circle(img *Mat, center image.Point, radius int, c color.RGBA, thickness int) { + pc := C.struct_Point{ + x: C.int(center.X), + y: C.int(center.Y), + } + + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.Circle(img.p, pc, C.int(radius), sColor, C.int(thickness)) +} + +// CircleWithParams draws a circle. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#gaf10604b069374903dbd0f0488cb43670 +func CircleWithParams(img *Mat, center image.Point, radius int, c color.RGBA, thickness int, lineType LineType, shift int) { + pc := C.struct_Point{ + x: C.int(center.X), + y: C.int(center.Y), + } + + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.CircleWithParams(img.p, pc, C.int(radius), sColor, C.int(thickness), C.int(lineType), C.int(shift)) +} + +// Ellipse draws a simple or thick elliptic arc or fills an ellipse sector. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga28b2267d35786f5f890ca167236cbc69 +func Ellipse(img *Mat, center, axes image.Point, angle, startAngle, endAngle float64, c color.RGBA, thickness int) { + pc := C.struct_Point{ + x: C.int(center.X), + y: C.int(center.Y), + } + pa := C.struct_Point{ + x: C.int(axes.X), + y: C.int(axes.Y), + } + + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.Ellipse(img.p, pc, pa, C.double(angle), C.double(startAngle), C.double(endAngle), sColor, C.int(thickness)) +} + +// Ellipse draws a simple or thick elliptic arc or fills an ellipse sector. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga28b2267d35786f5f890ca167236cbc69 +func EllipseWithParams(img *Mat, center, axes image.Point, angle, startAngle, endAngle float64, c color.RGBA, thickness int, lineType LineType, shift int) { + pc := C.struct_Point{ + x: C.int(center.X), + y: C.int(center.Y), + } + pa := C.struct_Point{ + x: C.int(axes.X), + y: C.int(axes.Y), + } + + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.EllipseWithParams(img.p, pc, pa, C.double(angle), C.double(startAngle), C.double(endAngle), sColor, C.int(thickness), C.int(lineType), C.int(shift)) +} + +// Line draws a line segment connecting two points. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga7078a9fae8c7e7d13d24dac2520ae4a2 +func Line(img *Mat, pt1 image.Point, pt2 image.Point, c color.RGBA, thickness int) { + sp1 := C.struct_Point{ + x: C.int(pt1.X), + y: C.int(pt1.Y), + } + + sp2 := C.struct_Point{ + x: C.int(pt2.X), + y: C.int(pt2.Y), + } + + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.Line(img.p, sp1, sp2, sColor, C.int(thickness)) +} + +// Rectangle draws a simple, thick, or filled up-right rectangle. +// It renders a rectangle with the desired characteristics to the target Mat image. +// +// For further details, please see: +// http://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga346ac30b5c74e9b5137576c9ee9e0e8c +func Rectangle(img *Mat, r image.Rectangle, c color.RGBA, thickness int) { + cRect := C.struct_Rect{ + x: C.int(r.Min.X), + y: C.int(r.Min.Y), + width: C.int(r.Size().X), + height: C.int(r.Size().Y), + } + + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.Rectangle(img.p, cRect, sColor, C.int(thickness)) +} + +// RectangleWithParams draws a simple, thick, or filled up-right rectangle. +// It renders a rectangle with the desired characteristics to the target Mat image. +// +// For further details, please see: +// http://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga346ac30b5c74e9b5137576c9ee9e0e8c +func RectangleWithParams(img *Mat, r image.Rectangle, c color.RGBA, thickness int, lineType LineType, shift int) { + cRect := C.struct_Rect{ + x: C.int(r.Min.X), + y: C.int(r.Min.Y), + width: C.int(r.Size().X), + height: C.int(r.Size().Y), + } + + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.RectangleWithParams(img.p, cRect, sColor, C.int(thickness), C.int(lineType), C.int(shift)) +} + +// FillPoly fills the area bounded by one or more polygons. +// +// For more information, see: +// https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#gaf30888828337aa4c6b56782b5dfbd4b7 +func FillPoly(img *Mat, pts PointsVector, c color.RGBA) { + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.FillPoly(img.p, pts.p, sColor) +} + +// FillPolyWithParams fills the area bounded by one or more polygons. +// +// For more information, see: +// https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#gaf30888828337aa4c6b56782b5dfbd4b7 +func FillPolyWithParams(img *Mat, pts PointsVector, c color.RGBA, lineType LineType, shift int, offset image.Point) { + offsetP := C.struct_Point{ + x: C.int(offset.X), + y: C.int(offset.Y), + } + + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.FillPolyWithParams(img.p, pts.p, sColor, C.int(lineType), C.int(shift), offsetP) +} + +// Polylines draws several polygonal curves. +// +// For more information, see: +// https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga1ea127ffbbb7e0bfc4fd6fd2eb64263c +func Polylines(img *Mat, pts PointsVector, isClosed bool, c color.RGBA, thickness int) { + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.Polylines(img.p, pts.p, C.bool(isClosed), sColor, C.int(thickness)) +} + +// HersheyFont are the font libraries included in OpenCV. +// Only a subset of the available Hershey fonts are supported by OpenCV. +// +// For more information, see: +// http://sources.isc.org/utils/misc/hershey-font.txt +type HersheyFont int + +const ( + // FontHersheySimplex is normal size sans-serif font. + FontHersheySimplex HersheyFont = 0 + // FontHersheyPlain issmall size sans-serif font. + FontHersheyPlain HersheyFont = 1 + // FontHersheyDuplex normal size sans-serif font + // (more complex than FontHersheySIMPLEX). + FontHersheyDuplex HersheyFont = 2 + // FontHersheyComplex i a normal size serif font. + FontHersheyComplex HersheyFont = 3 + // FontHersheyTriplex is a normal size serif font + // (more complex than FontHersheyCOMPLEX). + FontHersheyTriplex HersheyFont = 4 + // FontHersheyComplexSmall is a smaller version of FontHersheyCOMPLEX. + FontHersheyComplexSmall HersheyFont = 5 + // FontHersheyScriptSimplex is a hand-writing style font. + FontHersheyScriptSimplex HersheyFont = 6 + // FontHersheyScriptComplex is a more complex variant of FontHersheyScriptSimplex. + FontHersheyScriptComplex HersheyFont = 7 + // FontItalic is the flag for italic font. + FontItalic HersheyFont = 16 +) + +// LineType are the line libraries included in OpenCV. +// +// For more information, see: +// https://vovkos.github.io/doxyrest-showcase/opencv/sphinx_rtd_theme/enum_cv_LineTypes.html +type LineType int + +const ( + // Filled line + Filled LineType = -1 + // Line4 4-connected line + Line4 LineType = 4 + // Line8 8-connected line + Line8 LineType = 8 + // LineAA antialiased line + LineAA LineType = 16 +) + +// GetTextSize calculates the width and height of a text string. +// It returns an image.Point with the size required to draw text using +// a specific font face, scale, and thickness. +// +// For further details, please see: +// http://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga3d2abfcb995fd2db908c8288199dba82 +func GetTextSize(text string, fontFace HersheyFont, fontScale float64, thickness int) image.Point { + cText := C.CString(text) + defer C.free(unsafe.Pointer(cText)) + + sz := C.GetTextSize(cText, C.int(fontFace), C.double(fontScale), C.int(thickness)) + return image.Pt(int(sz.width), int(sz.height)) +} + +// GetTextSizeWithBaseline calculates the width and height of a text string including the basline of the text. +// It returns an image.Point with the size required to draw text using +// a specific font face, scale, and thickness as well as its baseline. +// +// For further details, please see: +// http://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga3d2abfcb995fd2db908c8288199dba82 +func GetTextSizeWithBaseline(text string, fontFace HersheyFont, fontScale float64, thickness int) (image.Point, int) { + cText := C.CString(text) + defer C.free(unsafe.Pointer(cText)) + cBaseline := C.int(0) + + sz := C.GetTextSizeWithBaseline(cText, C.int(fontFace), C.double(fontScale), C.int(thickness), &cBaseline) + return image.Pt(int(sz.width), int(sz.height)), int(cBaseline) +} + +// PutText draws a text string. +// It renders the specified text string into the img Mat at the location +// passed in the "org" param, using the desired font face, font scale, +// color, and line thinkness. +// +// For further details, please see: +// http://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576 +func PutText(img *Mat, text string, org image.Point, fontFace HersheyFont, fontScale float64, c color.RGBA, thickness int) { + cText := C.CString(text) + defer C.free(unsafe.Pointer(cText)) + + pOrg := C.struct_Point{ + x: C.int(org.X), + y: C.int(org.Y), + } + + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.PutText(img.p, cText, pOrg, C.int(fontFace), C.double(fontScale), sColor, C.int(thickness)) + return +} + +// PutTextWithParams draws a text string. +// It renders the specified text string into the img Mat at the location +// passed in the "org" param, using the desired font face, font scale, +// color, and line thinkness. +// +// For further details, please see: +// http://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576 +func PutTextWithParams(img *Mat, text string, org image.Point, fontFace HersheyFont, fontScale float64, c color.RGBA, thickness int, lineType LineType, bottomLeftOrigin bool) { + cText := C.CString(text) + defer C.free(unsafe.Pointer(cText)) + + pOrg := C.struct_Point{ + x: C.int(org.X), + y: C.int(org.Y), + } + + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.PutTextWithParams(img.p, cText, pOrg, C.int(fontFace), C.double(fontScale), sColor, C.int(thickness), C.int(lineType), C.bool(bottomLeftOrigin)) + return +} + +// InterpolationFlags are bit flags that control the interpolation algorithm +// that is used. +type InterpolationFlags int + +const ( + // InterpolationNearestNeighbor is nearest neighbor. (fast but low quality) + InterpolationNearestNeighbor InterpolationFlags = 0 + + // InterpolationLinear is bilinear interpolation. + InterpolationLinear InterpolationFlags = 1 + + // InterpolationCubic is bicube interpolation. + InterpolationCubic InterpolationFlags = 2 + + // InterpolationArea uses pixel area relation. It is preferred for image + // decimation as it gives moire-free results. + InterpolationArea InterpolationFlags = 3 + + // InterpolationLanczos4 is Lanczos interpolation over 8x8 neighborhood. + InterpolationLanczos4 InterpolationFlags = 4 + + // InterpolationDefault is an alias for InterpolationLinear. + InterpolationDefault = InterpolationLinear + + // InterpolationMax indicates use maximum interpolation. + InterpolationMax InterpolationFlags = 7 + + // WarpFillOutliers fills all of the destination image pixels. If some of them correspond to outliers in the source image, they are set to zero. + WarpFillOutliers = 8 + + // WarpInverseMap, inverse transformation. + WarpInverseMap = 16 +) + +// Resize resizes an image. +// It resizes the image src down to or up to the specified size, storing the +// result in dst. Note that src and dst may be the same image. If you wish to +// scale by factor, an empty sz may be passed and non-zero fx and fy. Likewise, +// if you wish to scale to an explicit size, a non-empty sz may be passed with +// zero for both fx and fy. +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d +func Resize(src Mat, dst *Mat, sz image.Point, fx, fy float64, interp InterpolationFlags) { + pSize := C.struct_Size{ + width: C.int(sz.X), + height: C.int(sz.Y), + } + + C.Resize(src.p, dst.p, pSize, C.double(fx), C.double(fy), C.int(interp)) + return +} + +// GetRectSubPix retrieves a pixel rectangle from an image with sub-pixel accuracy. +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga77576d06075c1a4b6ba1a608850cd614 +func GetRectSubPix(src Mat, patchSize image.Point, center image.Point, dst *Mat) { + sz := C.struct_Size{ + width: C.int(patchSize.X), + height: C.int(patchSize.Y), + } + pt := C.struct_Point{ + x: C.int(center.X), + y: C.int(center.Y), + } + C.GetRectSubPix(src.p, sz, pt, dst.p) +} + +// GetRotationMatrix2D calculates an affine matrix of 2D rotation. +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#gafbbc470ce83812914a70abfb604f4326 +func GetRotationMatrix2D(center image.Point, angle, scale float64) Mat { + pc := C.struct_Point{ + x: C.int(center.X), + y: C.int(center.Y), + } + return newMat(C.GetRotationMatrix2D(pc, C.double(angle), C.double(scale))) +} + +// WarpAffine applies an affine transformation to an image. For more parameters please check WarpAffineWithParams +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga0203d9ee5fcd28d40dbc4a1ea4451983 +func WarpAffine(src Mat, dst *Mat, m Mat, sz image.Point) { + pSize := C.struct_Size{ + width: C.int(sz.X), + height: C.int(sz.Y), + } + + C.WarpAffine(src.p, dst.p, m.p, pSize) +} + +// WarpAffineWithParams applies an affine transformation to an image. +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga0203d9ee5fcd28d40dbc4a1ea4451983 +func WarpAffineWithParams(src Mat, dst *Mat, m Mat, sz image.Point, flags InterpolationFlags, borderType BorderType, borderValue color.RGBA) { + pSize := C.struct_Size{ + width: C.int(sz.X), + height: C.int(sz.Y), + } + bv := C.struct_Scalar{ + val1: C.double(borderValue.B), + val2: C.double(borderValue.G), + val3: C.double(borderValue.R), + val4: C.double(borderValue.A), + } + C.WarpAffineWithParams(src.p, dst.p, m.p, pSize, C.int(flags), C.int(borderType), bv) +} + +// WarpPerspective applies a perspective transformation to an image. +// For more parameters please check WarpPerspectiveWithParams. +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#gaf73673a7e8e18ec6963e3774e6a94b87 +func WarpPerspective(src Mat, dst *Mat, m Mat, sz image.Point) { + pSize := C.struct_Size{ + width: C.int(sz.X), + height: C.int(sz.Y), + } + + C.WarpPerspective(src.p, dst.p, m.p, pSize) +} + +// WarpPerspectiveWithParams applies a perspective transformation to an image. +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#gaf73673a7e8e18ec6963e3774e6a94b87 +func WarpPerspectiveWithParams(src Mat, dst *Mat, m Mat, sz image.Point, flags InterpolationFlags, borderType BorderType, borderValue color.RGBA) { + pSize := C.struct_Size{ + width: C.int(sz.X), + height: C.int(sz.Y), + } + bv := C.struct_Scalar{ + val1: C.double(borderValue.B), + val2: C.double(borderValue.G), + val3: C.double(borderValue.R), + val4: C.double(borderValue.A), + } + C.WarpPerspectiveWithParams(src.p, dst.p, m.p, pSize, C.int(flags), C.int(borderType), bv) +} + +// Watershed performs a marker-based image segmentation using the watershed algorithm. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/d1b/group__imgproc__misc.html#ga3267243e4d3f95165d55a618c65ac6e1 +func Watershed(image Mat, markers *Mat) { + C.Watershed(image.p, markers.p) +} + +// ColormapTypes are the 12 GNU Octave/MATLAB equivalent colormaps. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d50/group__imgproc__colormap.html +type ColormapTypes int + +// List of the available color maps +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d50/group__imgproc__colormap.html#ga9a805d8262bcbe273f16be9ea2055a65 +const ( + ColormapAutumn ColormapTypes = 0 + ColormapBone ColormapTypes = 1 + ColormapJet ColormapTypes = 2 + ColormapWinter ColormapTypes = 3 + ColormapRainbow ColormapTypes = 4 + ColormapOcean ColormapTypes = 5 + ColormapSummer ColormapTypes = 6 + ColormapSpring ColormapTypes = 7 + ColormapCool ColormapTypes = 8 + ColormapHsv ColormapTypes = 9 + ColormapPink ColormapTypes = 10 + ColormapHot ColormapTypes = 11 + ColormapParula ColormapTypes = 12 +) + +// ApplyColorMap applies a GNU Octave/MATLAB equivalent colormap on a given image. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d50/group__imgproc__colormap.html#gadf478a5e5ff49d8aa24e726ea6f65d15 +func ApplyColorMap(src Mat, dst *Mat, colormapType ColormapTypes) { + C.ApplyColorMap(src.p, dst.p, C.int(colormapType)) +} + +// ApplyCustomColorMap applies a custom defined colormap on a given image. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/d50/group__imgproc__colormap.html#gacb22288ddccc55f9bd9e6d492b409cae +func ApplyCustomColorMap(src Mat, dst *Mat, customColormap Mat) { + C.ApplyCustomColorMap(src.p, dst.p, customColormap.p) +} + +// GetPerspectiveTransform returns 3x3 perspective transformation for the +// corresponding 4 point pairs as image.Point. +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga8c1ae0e3589a9d77fffc962c49b22043 +func GetPerspectiveTransform(src, dst PointVector) Mat { + return newMat(C.GetPerspectiveTransform(src.p, dst.p)) +} + +// GetPerspectiveTransform2f returns 3x3 perspective transformation for the +// corresponding 4 point pairs as gocv.Point2f. +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga8c1ae0e3589a9d77fffc962c49b22043 +func GetPerspectiveTransform2f(src, dst Point2fVector) Mat { + return newMat(C.GetPerspectiveTransform2f(src.p, dst.p)) +} + +// GetAffineTransform returns a 2x3 affine transformation matrix for the +// corresponding 3 point pairs as image.Point. +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga8f6d378f9f8eebb5cb55cd3ae295a999 +func GetAffineTransform(src, dst PointVector) Mat { + return newMat(C.GetAffineTransform(src.p, dst.p)) +} + +// GetAffineTransform2f returns a 2x3 affine transformation matrix for the +// corresponding 3 point pairs as gocv.Point2f. +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga8f6d378f9f8eebb5cb55cd3ae295a999 +func GetAffineTransform2f(src, dst Point2fVector) Mat { + return newMat(C.GetAffineTransform2f(src.p, dst.p)) +} + +type HomographyMethod int + +const ( + HomograpyMethodAllPoints HomographyMethod = 0 + HomograpyMethodLMEDS HomographyMethod = 4 + HomograpyMethodRANSAC HomographyMethod = 8 +) + +// FindHomography finds an optimal homography matrix using 4 or more point pairs (as opposed to GetPerspectiveTransform, which uses exactly 4) +// +// For further details, please see: +// https://docs.opencv.org/master/d9/d0c/group__calib3d.html#ga4abc2ece9fab9398f2e560d53c8c9780 +func FindHomography(srcPoints Mat, dstPoints *Mat, method HomographyMethod, ransacReprojThreshold float64, mask *Mat, maxIters int, confidence float64) Mat { + return newMat(C.FindHomography(srcPoints.Ptr(), dstPoints.Ptr(), C.int(method), C.double(ransacReprojThreshold), mask.Ptr(), C.int(maxIters), C.double(confidence))) +} + +// DrawContours draws contours outlines or filled contours. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga746c0625f1781f1ffc9056259103edbc +func DrawContours(img *Mat, contours PointsVector, contourIdx int, c color.RGBA, thickness int) { + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + + C.DrawContours(img.p, contours.p, C.int(contourIdx), sColor, C.int(thickness)) +} + +// DrawContoursWithParams draws contours outlines or filled contours. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga746c0625f1781f1ffc9056259103edbc +func DrawContoursWithParams(img *Mat, contours PointsVector, contourIdx int, c color.RGBA, thickness int, lineType LineType, hierarchy Mat, maxLevel int, offset image.Point) { + sColor := C.struct_Scalar{ + val1: C.double(c.B), + val2: C.double(c.G), + val3: C.double(c.R), + val4: C.double(c.A), + } + offsetP := C.struct_Point{ + x: C.int(offset.X), + y: C.int(offset.Y), + } + + C.DrawContoursWithParams(img.p, contours.p, C.int(contourIdx), sColor, C.int(thickness), C.int(lineType), hierarchy.p, C.int(maxLevel), offsetP) +} + +// Remap applies a generic geometrical transformation to an image. +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#gab75ef31ce5cdfb5c44b6da5f3b908ea4 +func Remap(src Mat, dst, map1, map2 *Mat, interpolation InterpolationFlags, borderMode BorderType, borderValue color.RGBA) { + bv := C.struct_Scalar{ + val1: C.double(borderValue.B), + val2: C.double(borderValue.G), + val3: C.double(borderValue.R), + val4: C.double(borderValue.A), + } + C.Remap(src.p, dst.p, map1.p, map2.p, C.int(interpolation), C.int(borderMode), bv) +} + +// Filter2D applies an arbitrary linear filter to an image. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga27c049795ce870216ddfb366086b5a04 +func Filter2D(src Mat, dst *Mat, ddepth MatType, kernel Mat, anchor image.Point, delta float64, borderType BorderType) { + anchorP := C.struct_Point{ + x: C.int(anchor.X), + y: C.int(anchor.Y), + } + C.Filter2D(src.p, dst.p, C.int(ddepth), kernel.p, anchorP, C.double(delta), C.int(borderType)) +} + +// SepFilter2D applies a separable linear filter to the image. +// +// For further details, please see: +// https://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga910e29ff7d7b105057d1625a4bf6318d +func SepFilter2D(src Mat, dst *Mat, ddepth MatType, kernelX, kernelY Mat, anchor image.Point, delta float64, borderType BorderType) { + anchorP := C.struct_Point{ + x: C.int(anchor.X), + y: C.int(anchor.Y), + } + C.SepFilter2D(src.p, dst.p, C.int(ddepth), kernelX.p, kernelY.p, anchorP, C.double(delta), C.int(borderType)) +} + +// LogPolar remaps an image to semilog-polar coordinates space. +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#gaec3a0b126a85b5ca2c667b16e0ae022d +func LogPolar(src Mat, dst *Mat, center image.Point, m float64, flags InterpolationFlags) { + centerP := C.struct_Point{ + x: C.int(center.X), + y: C.int(center.Y), + } + C.LogPolar(src.p, dst.p, centerP, C.double(m), C.int(flags)) +} + +// LinearPolar remaps an image to polar coordinates space. +// +// For further details, please see: +// https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#gaa38a6884ac8b6e0b9bed47939b5362f3 +func LinearPolar(src Mat, dst *Mat, center image.Point, maxRadius float64, flags InterpolationFlags) { + centerP := C.struct_Point{ + x: C.int(center.X), + y: C.int(center.Y), + } + C.LinearPolar(src.p, dst.p, centerP, C.double(maxRadius), C.int(flags)) +} + +// DistanceTypes types for Distance Transform and M-estimatorss +// +// For further details, please see: +// https://docs.opencv.org/master/d7/d1b/group__imgproc__misc.html#gaa2bfbebbc5c320526897996aafa1d8eb +type DistanceTypes int + +const ( + DistUser DistanceTypes = 0 + DistL1 DistanceTypes = 1 + DistL2 DistanceTypes = 2 + DistC DistanceTypes = 3 + DistL12 DistanceTypes = 4 + DistFair DistanceTypes = 5 + DistWelsch DistanceTypes = 6 + DistHuber DistanceTypes = 7 +) + +// FitLine fits a line to a 2D or 3D point set. +// +// For further details, please see: +// https://docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#gaf849da1fdafa67ee84b1e9a23b93f91f +func FitLine(pts PointVector, line *Mat, distType DistanceTypes, param, reps, aeps float64) { + C.FitLine(pts.p, line.p, C.int(distType), C.double(param), C.double(reps), C.double(aeps)) +} + +// Shape matching methods. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d3/dc0/group__imgproc__shape.html#gaadc90cb16e2362c9bd6e7363e6e4c317 +type ShapeMatchModes int + +const ( + ContoursMatchI1 ShapeMatchModes = 1 + ContoursMatchI2 ShapeMatchModes = 2 + ContoursMatchI3 ShapeMatchModes = 3 +) + +// Compares two shapes. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d3/dc0/group__imgproc__shape.html#gaadc90cb16e2362c9bd6e7363e6e4c317 +func MatchShapes(contour1 PointVector, contour2 PointVector, method ShapeMatchModes, parameter float64) float64 { + return float64(C.MatchShapes(contour1.p, contour2.p, C.int(method), C.double(parameter))) +} + +// CLAHE is a wrapper around the cv::CLAHE algorithm. +type CLAHE struct { + // C.CLAHE + p unsafe.Pointer +} + +// NewCLAHE returns a new CLAHE algorithm +// +// For further details, please see: +// https://docs.opencv.org/master/d6/db6/classcv_1_1CLAHE.html +func NewCLAHE() CLAHE { + return CLAHE{p: unsafe.Pointer(C.CLAHE_Create())} +} + +// NewCLAHEWithParams returns a new CLAHE algorithm +// +// For further details, please see: +// https://docs.opencv.org/master/d6/db6/classcv_1_1CLAHE.html +func NewCLAHEWithParams(clipLimit float64, tileGridSize image.Point) CLAHE { + pSize := C.struct_Size{ + width: C.int(tileGridSize.X), + height: C.int(tileGridSize.Y), + } + return CLAHE{p: unsafe.Pointer(C.CLAHE_CreateWithParams(C.double(clipLimit), pSize))} +} + +// Close CLAHE. +func (c *CLAHE) Close() error { + C.CLAHE_Close((C.CLAHE)(c.p)) + c.p = nil + return nil +} + +// Apply CLAHE. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/db6/classcv_1_1CLAHE.html#a4e92e0e427de21be8d1fae8dcd862c5e +func (c *CLAHE) Apply(src Mat, dst *Mat) { + C.CLAHE_Apply((C.CLAHE)(c.p), src.p, dst.p) +} + +func InvertAffineTransform(src Mat, dst *Mat) { + C.InvertAffineTransform(src.p, dst.p) +} + +// Apply phaseCorrelate. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/df3/group__imgproc__motion.html#ga552420a2ace9ef3fb053cd630fdb4952 +func PhaseCorrelate(src1, src2, window Mat) (phaseShift Point2f, response float64) { + var responseDouble C.double + result := C.PhaseCorrelate(src1.p, src2.p, window.p, &responseDouble) + + return Point2f{ + X: float32(result.x), + Y: float32(result.y), + }, float64(responseDouble) +} + +// ToImage converts a Mat to a image.Image. +func (m *Mat) ToImage() (image.Image, error) { + switch m.Type() { + case MatTypeCV8UC1: + img := image.NewGray(image.Rect(0, 0, m.Cols(), m.Rows())) + data, err := m.DataPtrUint8() + if err != nil { + return nil, err + } + copy(img.Pix, data[0:]) + return img, nil + + case MatTypeCV8UC3: + dst := NewMat() + defer dst.Close() + + C.CvtColor(m.p, dst.p, C.int(ColorBGRToRGBA)) + + img := image.NewRGBA(image.Rect(0, 0, m.Cols(), m.Rows())) + data, err := dst.DataPtrUint8() + if err != nil { + return nil, err + } + + copy(img.Pix, data[0:]) + return img, nil + + case MatTypeCV8UC4: + dst := NewMat() + defer dst.Close() + + C.CvtColor(m.p, dst.p, C.int(ColorBGRAToRGBA)) + + img := image.NewNRGBA(image.Rect(0, 0, m.Cols(), m.Rows())) + data, err := dst.DataPtrUint8() + if err != nil { + return nil, err + } + copy(img.Pix, data[0:]) + return img, nil + + default: + return nil, errors.New("ToImage supports only MatType CV8UC1, CV8UC3 and CV8UC4") + } +} + +// ToImageYUV converts a Mat to a image.YCbCr using image.YCbCrSubsampleRatio420 as default subsampling param. +func (m *Mat) ToImageYUV() (*image.YCbCr, error) { + img, err := m.ToImage() + if err != nil { + return nil, err + } + bounds := img.Bounds() + converted := image.NewYCbCr(bounds, image.YCbCrSubsampleRatio420) + + for row := 0; row < bounds.Max.Y; row++ { + for col := 0; col < bounds.Max.X; col++ { + r, g, b, _ := img.At(col, row).RGBA() + y, cb, cr := color.RGBToYCbCr(uint8(r), uint8(g), uint8(b)) + + converted.Y[converted.YOffset(col, row)] = y + converted.Cb[converted.COffset(col, row)] = cb + converted.Cr[converted.COffset(col, row)] = cr + } + } + return converted, nil +} + +// ToImageYUV converts a Mat to a image.YCbCr using provided YUV subsample ratio param. +func (m *Mat) ToImageYUVWithParams(ratio image.YCbCrSubsampleRatio) (*image.YCbCr, error) { + img, err := m.ToImage() + if err != nil { + return nil, err + } + bounds := img.Bounds() + converted := image.NewYCbCr(bounds, ratio) + + for row := 0; row < bounds.Max.Y; row++ { + for col := 0; col < bounds.Max.X; col++ { + r, g, b, _ := img.At(col, row).RGBA() + y, cb, cr := color.RGBToYCbCr(uint8(r), uint8(g), uint8(b)) + + converted.Y[converted.YOffset(col, row)] = y + converted.Cb[converted.COffset(col, row)] = cb + converted.Cr[converted.COffset(col, row)] = cr + } + } + return converted, nil +} + +// ImageToMatRGBA converts image.Image to gocv.Mat, +// which represents RGBA image having 8bit for each component. +// Type of Mat is gocv.MatTypeCV8UC4. +func ImageToMatRGBA(img image.Image) (Mat, error) { + bounds := img.Bounds() + x := bounds.Dx() + y := bounds.Dy() + + var data []uint8 + switch img.ColorModel() { + case color.RGBAModel: + m, res := img.(*image.RGBA) + if !res { + return NewMat(), errors.New("Image color format error") + } + data = m.Pix + + case color.NRGBAModel: + m, res := img.(*image.NRGBA) + if !res { + return NewMat(), errors.New("Image color format error") + } + data = m.Pix + + default: + data := make([]byte, 0, x*y*3) + for j := bounds.Min.Y; j < bounds.Max.Y; j++ { + for i := bounds.Min.X; i < bounds.Max.X; i++ { + r, g, b, _ := img.At(i, j).RGBA() + data = append(data, byte(b>>8), byte(g>>8), byte(r>>8)) + } + } + return NewMatFromBytes(y, x, MatTypeCV8UC3, data) + } + + // speed up the conversion process of RGBA format + cvt, err := NewMatFromBytes(y, x, MatTypeCV8UC4, data) + if err != nil { + return NewMat(), err + } + + defer cvt.Close() + + dst := NewMat() + C.CvtColor(cvt.p, dst.p, C.int(ColorBGRAToRGBA)) + return dst, nil +} + +// ImageToMatRGB converts image.Image to gocv.Mat, +// which represents RGB image having 8bit for each component. +// Type of Mat is gocv.MatTypeCV8UC3. +func ImageToMatRGB(img image.Image) (Mat, error) { + bounds := img.Bounds() + x := bounds.Dx() + y := bounds.Dy() + + var data []uint8 + switch img.ColorModel() { + case color.RGBAModel: + m, res := img.(*image.RGBA) + if true != res { + return NewMat(), errors.New("Image color format error") + } + data = m.Pix + // speed up the conversion process of RGBA format + src, err := NewMatFromBytes(y, x, MatTypeCV8UC4, data) + if err != nil { + return NewMat(), err + } + defer src.Close() + + dst := NewMat() + CvtColor(src, &dst, ColorRGBAToBGR) + return dst, nil + + default: + data := make([]byte, 0, x*y*3) + for j := bounds.Min.Y; j < bounds.Max.Y; j++ { + for i := bounds.Min.X; i < bounds.Max.X; i++ { + r, g, b, _ := img.At(i, j).RGBA() + data = append(data, byte(b>>8), byte(g>>8), byte(r>>8)) + } + } + return NewMatFromBytes(y, x, MatTypeCV8UC3, data) + } +} + +// ImageGrayToMatGray converts image.Gray to gocv.Mat, +// which represents grayscale image 8bit. +// Type of Mat is gocv.MatTypeCV8UC1. +func ImageGrayToMatGray(img *image.Gray) (Mat, error) { + bounds := img.Bounds() + x := bounds.Dx() + y := bounds.Dy() + m, err := NewMatFromBytes(y, x, MatTypeCV8UC1, img.Pix) + if err != nil { + return NewMat(), err + } + return m, nil +} + +// Adds the square of a source image to the accumulator image. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/df3/group__imgproc__motion.html#ga1a567a79901513811ff3b9976923b199 +// + +func Accumulate(src Mat, dst *Mat) { + C.Mat_Accumulate(src.p, dst.p) +} + +// Adds an image to the accumulator image with mask. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/df3/group__imgproc__motion.html#ga1a567a79901513811ff3b9976923b199 +func AccumulateWithMask(src Mat, dst *Mat, mask Mat) { + C.Mat_AccumulateWithMask(src.p, dst.p, mask.p) +} + +// Adds the square of a source image to the accumulator image. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/df3/group__imgproc__motion.html#gacb75e7ffb573227088cef9ceaf80be8c +func AccumulateSquare(src Mat, dst *Mat) { + C.Mat_AccumulateSquare(src.p, dst.p) +} + +// Adds the square of a source image to the accumulator image with mask. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/df3/group__imgproc__motion.html#gacb75e7ffb573227088cef9ceaf80be8c +func AccumulateSquareWithMask(src Mat, dst *Mat, mask Mat) { + C.Mat_AccumulateSquareWithMask(src.p, dst.p, mask.p) +} + +// Adds the per-element product of two input images to the accumulator image. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/df3/group__imgproc__motion.html#ga82518a940ecfda49460f66117ac82520 +func AccumulateProduct(src1 Mat, src2 Mat, dst *Mat) { + C.Mat_AccumulateProduct(src1.p, src2.p, dst.p) +} + +// Adds the per-element product of two input images to the accumulator image with mask. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/df3/group__imgproc__motion.html#ga82518a940ecfda49460f66117ac82520 +func AccumulateProductWithMask(src1 Mat, src2 Mat, dst *Mat, mask Mat) { + C.Mat_AccumulateProductWithMask(src1.p, src2.p, dst.p, mask.p) +} + +// Updates a running average. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/df3/group__imgproc__motion.html#ga4f9552b541187f61f6818e8d2d826bc7 +func AccumulatedWeighted(src Mat, dst *Mat, alpha float64) { + C.Mat_AccumulatedWeighted(src.p, dst.p, C.double(alpha)) +} + +// Updates a running average with mask. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/df3/group__imgproc__motion.html#ga4f9552b541187f61f6818e8d2d826bc7 +func AccumulatedWeightedWithMask(src Mat, dst *Mat, alpha float64, mask Mat) { + C.Mat_AccumulatedWeightedWithMask(src.p, dst.p, C.double(alpha), mask.p) +} diff --git a/vendor/gocv.io/x/gocv/imgproc.h b/vendor/gocv.io/x/gocv/imgproc.h new file mode 100644 index 00000000..ec862bd3 --- /dev/null +++ b/vendor/gocv.io/x/gocv/imgproc.h @@ -0,0 +1,147 @@ +#ifndef _OPENCV3_IMGPROC_H_ +#define _OPENCV3_IMGPROC_H_ + +#include + +#ifdef __cplusplus +#include +extern "C" { +#endif + +#ifdef __cplusplus +typedef cv::Ptr* CLAHE; +#else +typedef void* CLAHE; +#endif + +#include "core.h" + +double ArcLength(PointVector curve, bool is_closed); +PointVector ApproxPolyDP(PointVector curve, double epsilon, bool closed); +void CvtColor(Mat src, Mat dst, int code); +void EqualizeHist(Mat src, Mat dst); +void CalcHist(struct Mats mats, IntVector chans, Mat mask, Mat hist, IntVector sz, FloatVector rng, bool acc); +void CalcBackProject(struct Mats mats, IntVector chans, Mat hist, Mat backProject, FloatVector rng, bool uniform); +double CompareHist(Mat hist1, Mat hist2, int method); +void ConvexHull(PointVector points, Mat hull, bool clockwise, bool returnPoints); +void ConvexityDefects(PointVector points, Mat hull, Mat result); +void BilateralFilter(Mat src, Mat dst, int d, double sc, double ss); +void Blur(Mat src, Mat dst, Size ps); +void BoxFilter(Mat src, Mat dst, int ddepth, Size ps); +void SqBoxFilter(Mat src, Mat dst, int ddepth, Size ps); +void Dilate(Mat src, Mat dst, Mat kernel); +void DilateWithParams(Mat src, Mat dst, Mat kernel, Point anchor, int iterations, int borderType, Scalar borderValue); +void DistanceTransform(Mat src, Mat dst, Mat labels, int distanceType, int maskSize, int labelType); +void Erode(Mat src, Mat dst, Mat kernel); +void ErodeWithParams(Mat src, Mat dst, Mat kernel, Point anchor, int iterations, int borderType); +void MatchTemplate(Mat image, Mat templ, Mat result, int method, Mat mask); +struct Moment Moments(Mat src, bool binaryImage); +void PyrDown(Mat src, Mat dst, Size dstsize, int borderType); +void PyrUp(Mat src, Mat dst, Size dstsize, int borderType); +struct Rect BoundingRect(PointVector pts); +void BoxPoints(RotatedRect rect, Mat boxPts); +double ContourArea(PointVector pts); +struct RotatedRect MinAreaRect(PointVector pts); +struct RotatedRect FitEllipse(PointVector pts); +void MinEnclosingCircle(PointVector pts, Point2f* center, float* radius); +PointsVector FindContours(Mat src, Mat hierarchy, int mode, int method); +double PointPolygonTest(PointVector pts, Point pt, bool measureDist); +int ConnectedComponents(Mat src, Mat dst, int connectivity, int ltype, int ccltype); +int ConnectedComponentsWithStats(Mat src, Mat labels, Mat stats, Mat centroids, int connectivity, int ltype, int ccltype); + +void GaussianBlur(Mat src, Mat dst, Size ps, double sX, double sY, int bt); +Mat GetGaussianKernel(int ksize, double sigma, int ktype); +void Laplacian(Mat src, Mat dst, int dDepth, int kSize, double scale, double delta, int borderType); +void Scharr(Mat src, Mat dst, int dDepth, int dx, int dy, double scale, double delta, + int borderType); +Mat GetStructuringElement(int shape, Size ksize); +Scalar MorphologyDefaultBorderValue(); +void MorphologyEx(Mat src, Mat dst, int op, Mat kernel); +void MorphologyExWithParams(Mat src, Mat dst, int op, Mat kernel, Point pt, int iterations, int borderType); +void MedianBlur(Mat src, Mat dst, int ksize); + +void Canny(Mat src, Mat edges, double t1, double t2); +void CornerSubPix(Mat img, Mat corners, Size winSize, Size zeroZone, TermCriteria criteria); +void GoodFeaturesToTrack(Mat img, Mat corners, int maxCorners, double quality, double minDist); +void GrabCut(Mat img, Mat mask, Rect rect, Mat bgdModel, Mat fgdModel, int iterCount, int mode); +void HoughCircles(Mat src, Mat circles, int method, double dp, double minDist); +void HoughCirclesWithParams(Mat src, Mat circles, int method, double dp, double minDist, + double param1, double param2, int minRadius, int maxRadius); +void HoughLines(Mat src, Mat lines, double rho, double theta, int threshold); +void HoughLinesP(Mat src, Mat lines, double rho, double theta, int threshold); +void HoughLinesPWithParams(Mat src, Mat lines, double rho, double theta, int threshold, double minLineLength, double maxLineGap); +void HoughLinesPointSet(Mat points, Mat lines, int lines_max, int threshold, + double min_rho, double max_rho, double rho_step, + double min_theta, double max_theta, double theta_step); +void Integral(Mat src, Mat sum, Mat sqsum, Mat tilted); +double Threshold(Mat src, Mat dst, double thresh, double maxvalue, int typ); +void AdaptiveThreshold(Mat src, Mat dst, double maxValue, int adaptiveTyp, int typ, int blockSize, + double c); + +void ArrowedLine(Mat img, Point pt1, Point pt2, Scalar color, int thickness); +void Circle(Mat img, Point center, int radius, Scalar color, int thickness); +void CircleWithParams(Mat img, Point center, int radius, Scalar color, int thickness, int lineType, int shift); +void Ellipse(Mat img, Point center, Point axes, double angle, double + startAngle, double endAngle, Scalar color, int thickness); +void EllipseWithParams(Mat img, Point center, Point axes, double angle, double + startAngle, double endAngle, Scalar color, int thickness, int lineType, int shift); +void Line(Mat img, Point pt1, Point pt2, Scalar color, int thickness); +void Rectangle(Mat img, Rect rect, Scalar color, int thickness); +void RectangleWithParams(Mat img, Rect rect, Scalar color, int thickness, int lineType, int shift); +void FillPoly(Mat img, PointsVector points, Scalar color); +void FillPolyWithParams(Mat img, PointsVector points, Scalar color, int lineType, int shift, Point offset); +void Polylines(Mat img, PointsVector points, bool isClosed, Scalar color, int thickness); +struct Size GetTextSize(const char* text, int fontFace, double fontScale, int thickness); +struct Size GetTextSizeWithBaseline(const char* text, int fontFace, double fontScale, int thickness, int* baseline); +void PutText(Mat img, const char* text, Point org, int fontFace, double fontScale, + Scalar color, int thickness); +void PutTextWithParams(Mat img, const char* text, Point org, int fontFace, double fontScale, + Scalar color, int thickness, int lineType, bool bottomLeftOrigin); +void Resize(Mat src, Mat dst, Size sz, double fx, double fy, int interp); +void GetRectSubPix(Mat src, Size patchSize, Point center, Mat dst); +Mat GetRotationMatrix2D(Point center, double angle, double scale); +void WarpAffine(Mat src, Mat dst, Mat rot_mat, Size dsize); +void WarpAffineWithParams(Mat src, Mat dst, Mat rot_mat, Size dsize, int flags, int borderMode, + Scalar borderValue); +void WarpPerspective(Mat src, Mat dst, Mat m, Size dsize); +void WarpPerspectiveWithParams(Mat src, Mat dst, Mat rot_mat, Size dsize, int flags, int borderMode, + Scalar borderValue); +void Watershed(Mat image, Mat markers); +void ApplyColorMap(Mat src, Mat dst, int colormap); +void ApplyCustomColorMap(Mat src, Mat dst, Mat colormap); +Mat GetPerspectiveTransform(PointVector src, PointVector dst); +Mat GetPerspectiveTransform2f(Point2fVector src, Point2fVector dst); +Mat GetAffineTransform(PointVector src, PointVector dst); +Mat GetAffineTransform2f(Point2fVector src, Point2fVector dst); +Mat FindHomography(Mat src, Mat dst, int method, double ransacReprojThreshold, Mat mask, const int maxIters, const double confidence) ; +void DrawContours(Mat src, PointsVector contours, int contourIdx, Scalar color, int thickness); +void DrawContoursWithParams(Mat src, PointsVector contours, int contourIdx, Scalar color, int thickness, int lineType, Mat hierarchy, int maxLevel, Point offset); +void Sobel(Mat src, Mat dst, int ddepth, int dx, int dy, int ksize, double scale, double delta, int borderType); +void SpatialGradient(Mat src, Mat dx, Mat dy, int ksize, int borderType); +void Remap(Mat src, Mat dst, Mat map1, Mat map2, int interpolation, int borderMode, Scalar borderValue); +void Filter2D(Mat src, Mat dst, int ddepth, Mat kernel, Point anchor, double delta, int borderType); +void SepFilter2D(Mat src, Mat dst, int ddepth, Mat kernelX, Mat kernelY, Point anchor, double delta, int borderType); +void LogPolar(Mat src, Mat dst, Point center, double m, int flags); +void FitLine(PointVector pts, Mat line, int distType, double param, double reps, double aeps); +void LinearPolar(Mat src, Mat dst, Point center, double maxRadius, int flags); +double MatchShapes(PointVector contour1, PointVector contour2, int method, double parameter); +bool ClipLine(Size imgSize, Point pt1, Point pt2); +CLAHE CLAHE_Create(); +CLAHE CLAHE_CreateWithParams(double clipLimit, Size tileGridSize); +void CLAHE_Close(CLAHE c); +void CLAHE_Apply(CLAHE c, Mat src, Mat dst); +void InvertAffineTransform(Mat src, Mat dst); +Point2f PhaseCorrelate(Mat src1, Mat src2, Mat window, double* response); +void Mat_Accumulate(Mat src, Mat dst); +void Mat_AccumulateWithMask(Mat src, Mat dst, Mat mask); +void Mat_AccumulateSquare(Mat src, Mat dst); +void Mat_AccumulateSquareWithMask(Mat src, Mat dst, Mat mask); +void Mat_AccumulateProduct(Mat src1, Mat src2, Mat dst); +void Mat_AccumulateProductWithMask(Mat src1, Mat src2, Mat dst, Mat mask); +void Mat_AccumulatedWeighted(Mat src, Mat dst, double alpha); +void Mat_AccumulatedWeightedWithMask(Mat src, Mat dst, double alpha, Mat mask); +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_IMGPROC_H_ diff --git a/vendor/gocv.io/x/gocv/imgproc_colorcodes.go b/vendor/gocv.io/x/gocv/imgproc_colorcodes.go new file mode 100644 index 00000000..de486c61 --- /dev/null +++ b/vendor/gocv.io/x/gocv/imgproc_colorcodes.go @@ -0,0 +1,351 @@ +package gocv + +// ColorConversionCode is a color conversion code used on Mat. +// +// For further details, please see: +// http://docs.opencv.org/master/d7/d1b/group__imgproc__misc.html#ga4e0972be5de079fed4e3a10e24ef5ef0 +// +type ColorConversionCode int + +const ( + // ColorBGRToBGRA adds alpha channel to BGR image. + ColorBGRToBGRA ColorConversionCode = 0 + + // ColorBGRAToBGR removes alpha channel from BGR image. + ColorBGRAToBGR ColorConversionCode = 1 + + // ColorBGRToRGBA converts from BGR to RGB with alpha channel. + ColorBGRToRGBA ColorConversionCode = 2 + + // ColorRGBAToBGR converts from RGB with alpha to BGR color space. + ColorRGBAToBGR ColorConversionCode = 3 + + // ColorBGRToRGB converts from BGR to RGB without alpha channel. + ColorBGRToRGB ColorConversionCode = 4 + + // ColorBGRAToRGBA converts from BGR with alpha channel + // to RGB with alpha channel. + ColorBGRAToRGBA ColorConversionCode = 5 + + // ColorBGRToGray converts from BGR to grayscale. + ColorBGRToGray ColorConversionCode = 6 + + // ColorRGBToGray converts from RGB to grayscale. + ColorRGBToGray ColorConversionCode = 7 + + // ColorGrayToBGR converts from grayscale to BGR. + ColorGrayToBGR ColorConversionCode = 8 + + // ColorGrayToBGRA converts from grayscale to BGR with alpha channel. + ColorGrayToBGRA ColorConversionCode = 9 + + // ColorBGRAToGray converts from BGR with alpha channel to grayscale. + ColorBGRAToGray ColorConversionCode = 10 + + // ColorRGBAToGray converts from RGB with alpha channel to grayscale. + ColorRGBAToGray ColorConversionCode = 11 + + // ColorBGRToBGR565 converts from BGR to BGR565 (16-bit images). + ColorBGRToBGR565 ColorConversionCode = 12 + + // ColorRGBToBGR565 converts from RGB to BGR565 (16-bit images). + ColorRGBToBGR565 ColorConversionCode = 13 + + // ColorBGR565ToBGR converts from BGR565 (16-bit images) to BGR. + ColorBGR565ToBGR ColorConversionCode = 14 + + // ColorBGR565ToRGB converts from BGR565 (16-bit images) to RGB. + ColorBGR565ToRGB ColorConversionCode = 15 + + // ColorBGRAToBGR565 converts from BGRA (with alpha channel) + // to BGR565 (16-bit images). + ColorBGRAToBGR565 ColorConversionCode = 16 + + // ColorRGBAToBGR565 converts from RGBA (with alpha channel) + // to BGR565 (16-bit images). + ColorRGBAToBGR565 ColorConversionCode = 17 + + // ColorBGR565ToBGRA converts from BGR565 (16-bit images) + // to BGRA (with alpha channel). + ColorBGR565ToBGRA ColorConversionCode = 18 + + // ColorBGR565ToRGBA converts from BGR565 (16-bit images) + // to RGBA (with alpha channel). + ColorBGR565ToRGBA ColorConversionCode = 19 + + // ColorGrayToBGR565 converts from grayscale + // to BGR565 (16-bit images). + ColorGrayToBGR565 ColorConversionCode = 20 + + // ColorBGR565ToGray converts from BGR565 (16-bit images) + // to grayscale. + ColorBGR565ToGray ColorConversionCode = 21 + + // ColorBGRToBGR555 converts from BGR to BGR555 (16-bit images). + ColorBGRToBGR555 ColorConversionCode = 22 + + // ColorRGBToBGR555 converts from RGB to BGR555 (16-bit images). + ColorRGBToBGR555 ColorConversionCode = 23 + + // ColorBGR555ToBGR converts from BGR555 (16-bit images) to BGR. + ColorBGR555ToBGR ColorConversionCode = 24 + + // ColorBGR555ToRGB converts from BGR555 (16-bit images) to RGB. + ColorBGR555ToRGB ColorConversionCode = 25 + + // ColorBGRAToBGR555 converts from BGRA (with alpha channel) + // to BGR555 (16-bit images). + ColorBGRAToBGR555 ColorConversionCode = 26 + + // ColorRGBAToBGR555 converts from RGBA (with alpha channel) + // to BGR555 (16-bit images). + ColorRGBAToBGR555 ColorConversionCode = 27 + + // ColorBGR555ToBGRA converts from BGR555 (16-bit images) + // to BGRA (with alpha channel). + ColorBGR555ToBGRA ColorConversionCode = 28 + + // ColorBGR555ToRGBA converts from BGR555 (16-bit images) + // to RGBA (with alpha channel). + ColorBGR555ToRGBA ColorConversionCode = 29 + + // ColorGrayToBGR555 converts from grayscale to BGR555 (16-bit images). + ColorGrayToBGR555 ColorConversionCode = 30 + + // ColorBGR555ToGRAY converts from BGR555 (16-bit images) to grayscale. + ColorBGR555ToGRAY ColorConversionCode = 31 + + // ColorBGRToXYZ converts from BGR to CIE XYZ. + ColorBGRToXYZ ColorConversionCode = 32 + + // ColorRGBToXYZ converts from RGB to CIE XYZ. + ColorRGBToXYZ ColorConversionCode = 33 + + // ColorXYZToBGR converts from CIE XYZ to BGR. + ColorXYZToBGR ColorConversionCode = 34 + + // ColorXYZToRGB converts from CIE XYZ to RGB. + ColorXYZToRGB ColorConversionCode = 35 + + // ColorBGRToYCrCb converts from BGR to luma-chroma (aka YCC). + ColorBGRToYCrCb ColorConversionCode = 36 + + // ColorRGBToYCrCb converts from RGB to luma-chroma (aka YCC). + ColorRGBToYCrCb ColorConversionCode = 37 + + // ColorYCrCbToBGR converts from luma-chroma (aka YCC) to BGR. + ColorYCrCbToBGR ColorConversionCode = 38 + + // ColorYCrCbToRGB converts from luma-chroma (aka YCC) to RGB. + ColorYCrCbToRGB ColorConversionCode = 39 + + // ColorBGRToHSV converts from BGR to HSV (hue saturation value). + ColorBGRToHSV ColorConversionCode = 40 + + // ColorRGBToHSV converts from RGB to HSV (hue saturation value). + ColorRGBToHSV ColorConversionCode = 41 + + // ColorBGRToLab converts from BGR to CIE Lab. + ColorBGRToLab ColorConversionCode = 44 + + // ColorRGBToLab converts from RGB to CIE Lab. + ColorRGBToLab ColorConversionCode = 45 + + // ColorBGRToLuv converts from BGR to CIE Luv. + ColorBGRToLuv ColorConversionCode = 50 + + // ColorRGBToLuv converts from RGB to CIE Luv. + ColorRGBToLuv ColorConversionCode = 51 + + // ColorBGRToHLS converts from BGR to HLS (hue lightness saturation). + ColorBGRToHLS ColorConversionCode = 52 + + // ColorRGBToHLS converts from RGB to HLS (hue lightness saturation). + ColorRGBToHLS ColorConversionCode = 53 + + // ColorHSVToBGR converts from HSV (hue saturation value) to BGR. + ColorHSVToBGR ColorConversionCode = 54 + + // ColorHSVToRGB converts from HSV (hue saturation value) to RGB. + ColorHSVToRGB ColorConversionCode = 55 + + // ColorLabToBGR converts from CIE Lab to BGR. + ColorLabToBGR ColorConversionCode = 56 + + // ColorLabToRGB converts from CIE Lab to RGB. + ColorLabToRGB ColorConversionCode = 57 + + // ColorLuvToBGR converts from CIE Luv to BGR. + ColorLuvToBGR ColorConversionCode = 58 + + // ColorLuvToRGB converts from CIE Luv to RGB. + ColorLuvToRGB ColorConversionCode = 59 + + // ColorHLSToBGR converts from HLS (hue lightness saturation) to BGR. + ColorHLSToBGR ColorConversionCode = 60 + + // ColorHLSToRGB converts from HLS (hue lightness saturation) to RGB. + ColorHLSToRGB ColorConversionCode = 61 + + // ColorBGRToHSVFull converts from BGR to HSV (hue saturation value) full. + ColorBGRToHSVFull ColorConversionCode = 66 + + // ColorRGBToHSVFull converts from RGB to HSV (hue saturation value) full. + ColorRGBToHSVFull ColorConversionCode = 67 + + // ColorBGRToHLSFull converts from BGR to HLS (hue lightness saturation) full. + ColorBGRToHLSFull ColorConversionCode = 68 + + // ColorRGBToHLSFull converts from RGB to HLS (hue lightness saturation) full. + ColorRGBToHLSFull ColorConversionCode = 69 + + // ColorHSVToBGRFull converts from HSV (hue saturation value) to BGR full. + ColorHSVToBGRFull ColorConversionCode = 70 + + // ColorHSVToRGBFull converts from HSV (hue saturation value) to RGB full. + ColorHSVToRGBFull ColorConversionCode = 71 + + // ColorHLSToBGRFull converts from HLS (hue lightness saturation) to BGR full. + ColorHLSToBGRFull ColorConversionCode = 72 + + // ColorHLSToRGBFull converts from HLS (hue lightness saturation) to RGB full. + ColorHLSToRGBFull ColorConversionCode = 73 + + // ColorLBGRToLab converts from LBGR to CIE Lab. + ColorLBGRToLab ColorConversionCode = 74 + + // ColorLRGBToLab converts from LRGB to CIE Lab. + ColorLRGBToLab ColorConversionCode = 75 + + // ColorLBGRToLuv converts from LBGR to CIE Luv. + ColorLBGRToLuv ColorConversionCode = 76 + + // ColorLRGBToLuv converts from LRGB to CIE Luv. + ColorLRGBToLuv ColorConversionCode = 77 + + // ColorLabToLBGR converts from CIE Lab to LBGR. + ColorLabToLBGR ColorConversionCode = 78 + + // ColorLabToLRGB converts from CIE Lab to LRGB. + ColorLabToLRGB ColorConversionCode = 79 + + // ColorLuvToLBGR converts from CIE Luv to LBGR. + ColorLuvToLBGR ColorConversionCode = 80 + + // ColorLuvToLRGB converts from CIE Luv to LRGB. + ColorLuvToLRGB ColorConversionCode = 81 + + // ColorBGRToYUV converts from BGR to YUV. + ColorBGRToYUV ColorConversionCode = 82 + + // ColorRGBToYUV converts from RGB to YUV. + ColorRGBToYUV ColorConversionCode = 83 + + // ColorYUVToBGR converts from YUV to BGR. + ColorYUVToBGR ColorConversionCode = 84 + + // ColorYUVToRGB converts from YUV to RGB. + ColorYUVToRGB ColorConversionCode = 85 + + // ColorYUVToRGBNV12 converts from YUV 4:2:0 to RGB NV12. + ColorYUVToRGBNV12 ColorConversionCode = 90 + + // ColorYUVToBGRNV12 converts from YUV 4:2:0 to BGR NV12. + ColorYUVToBGRNV12 ColorConversionCode = 91 + + // ColorYUVToRGBNV21 converts from YUV 4:2:0 to RGB NV21. + ColorYUVToRGBNV21 ColorConversionCode = 92 + + // ColorYUVToBGRNV21 converts from YUV 4:2:0 to BGR NV21. + ColorYUVToBGRNV21 ColorConversionCode = 93 + + // ColorYUVToRGBANV12 converts from YUV 4:2:0 to RGBA NV12. + ColorYUVToRGBANV12 ColorConversionCode = 94 + + // ColorYUVToBGRANV12 converts from YUV 4:2:0 to BGRA NV12. + ColorYUVToBGRANV12 ColorConversionCode = 95 + + // ColorYUVToRGBANV21 converts from YUV 4:2:0 to RGBA NV21. + ColorYUVToRGBANV21 ColorConversionCode = 96 + + // ColorYUVToBGRANV21 converts from YUV 4:2:0 to BGRA NV21. + ColorYUVToBGRANV21 ColorConversionCode = 97 + + ColorYUVToRGBYV12 ColorConversionCode = 98 + ColorYUVToBGRYV12 ColorConversionCode = 99 + ColorYUVToRGBIYUV ColorConversionCode = 100 + ColorYUVToBGRIYUV ColorConversionCode = 101 + + ColorYUVToRGBAYV12 ColorConversionCode = 102 + ColorYUVToBGRAYV12 ColorConversionCode = 103 + ColorYUVToRGBAIYUV ColorConversionCode = 104 + ColorYUVToBGRAIYUV ColorConversionCode = 105 + + ColorYUVToGRAY420 ColorConversionCode = 106 + + // YUV 4:2:2 family to RGB + ColorYUVToRGBUYVY ColorConversionCode = 107 + ColorYUVToBGRUYVY ColorConversionCode = 108 + + ColorYUVToRGBAUYVY ColorConversionCode = 111 + ColorYUVToBGRAUYVY ColorConversionCode = 112 + + ColorYUVToRGBYUY2 ColorConversionCode = 115 + ColorYUVToBGRYUY2 ColorConversionCode = 116 + ColorYUVToRGBYVYU ColorConversionCode = 117 + ColorYUVToBGRYVYU ColorConversionCode = 118 + + ColorYUVToRGBAYUY2 ColorConversionCode = 119 + ColorYUVToBGRAYUY2 ColorConversionCode = 120 + ColorYUVToRGBAYVYU ColorConversionCode = 121 + ColorYUVToBGRAYVYU ColorConversionCode = 122 + + ColorYUVToGRAYUYVY ColorConversionCode = 123 + ColorYUVToGRAYYUY2 ColorConversionCode = 124 + + // alpha premultiplication + ColorRGBATomRGBA ColorConversionCode = 125 + ColormRGBAToRGBA ColorConversionCode = 126 + + // RGB to YUV 4:2:0 family + ColorRGBToYUVI420 ColorConversionCode = 127 + ColorBGRToYUVI420 ColorConversionCode = 128 + + ColorRGBAToYUVI420 ColorConversionCode = 129 + ColorBGRAToYUVI420 ColorConversionCode = 130 + ColorRGBToYUVYV12 ColorConversionCode = 131 + ColorBGRToYUVYV12 ColorConversionCode = 132 + ColorRGBAToYUVYV12 ColorConversionCode = 133 + ColorBGRAToYUVYV12 ColorConversionCode = 134 + + // Demosaicing + ColorBayerBGToBGR ColorConversionCode = 46 + ColorBayerGBToBGR ColorConversionCode = 47 + ColorBayerRGToBGR ColorConversionCode = 48 + ColorBayerGRToBGR ColorConversionCode = 49 + + ColorBayerBGToGRAY ColorConversionCode = 86 + ColorBayerGBToGRAY ColorConversionCode = 87 + ColorBayerRGToGRAY ColorConversionCode = 88 + ColorBayerGRToGRAY ColorConversionCode = 89 + + // Demosaicing using Variable Number of Gradients + ColorBayerBGToBGRVNG ColorConversionCode = 62 + ColorBayerGBToBGRVNG ColorConversionCode = 63 + ColorBayerRGToBGRVNG ColorConversionCode = 64 + ColorBayerGRToBGRVNG ColorConversionCode = 65 + + // Edge-Aware Demosaicing + ColorBayerBGToBGREA ColorConversionCode = 135 + ColorBayerGBToBGREA ColorConversionCode = 136 + ColorBayerRGToBGREA ColorConversionCode = 137 + ColorBayerGRToBGREA ColorConversionCode = 138 + + // Demosaicing with alpha channel + ColorBayerBGToBGRA ColorConversionCode = 139 + ColorBayerGBToBGRA ColorConversionCode = 140 + ColorBayerRGToBGRA ColorConversionCode = 141 + ColorBayerGRToBGRA ColorConversionCode = 142 + + ColorCOLORCVTMAX ColorConversionCode = 143 +) diff --git a/vendor/gocv.io/x/gocv/imgproc_colorcodes_string.go b/vendor/gocv.io/x/gocv/imgproc_colorcodes_string.go new file mode 100644 index 00000000..ac226efa --- /dev/null +++ b/vendor/gocv.io/x/gocv/imgproc_colorcodes_string.go @@ -0,0 +1,303 @@ +package gocv + +func (c ColorConversionCode) String() string { + switch c { + case ColorBGRToBGRA: + return "color-bgr-to-bgra" + case ColorBGRAToBGR: + return "color-bgra-to-bgr" + case ColorBGRToRGBA: + return "color-bgr-to-rgba" + case ColorRGBAToBGR: + return "color-rgba-to-bgr" + case ColorBGRToRGB: + return "color-bgr-to-rgb" + case ColorBGRAToRGBA: + return "color-bgra-to-rgba" + case ColorBGRToGray: + return "color-bgr-to-gray" + case ColorRGBToGray: + return "color-rgb-to-gray" + case ColorGrayToBGR: + return "color-gray-to-bgr" + case ColorGrayToBGRA: + return "color-gray-to-bgra" + case ColorBGRAToGray: + return "color-bgra-to-gray" + case ColorRGBAToGray: + return "color-rgba-to-gray" + case ColorBGRToBGR565: + return "color-bgr-to-bgr565" + case ColorRGBToBGR565: + return "color-rgb-to-bgr565" + case ColorBGR565ToBGR: + return "color-bgr565-to-bgr" + case ColorBGR565ToRGB: + return "color-bgr565-to-rgb" + case ColorBGRAToBGR565: + return "color-bgra-to-bgr565" + case ColorRGBAToBGR565: + return "color-rgba-to-bgr565" + case ColorBGR565ToBGRA: + return "color-bgr565-to-bgra" + case ColorBGR565ToRGBA: + return "color-bgr565-to-rgba" + case ColorGrayToBGR565: + return "color-gray-to-bgr565" + case ColorBGR565ToGray: + return "color-bgr565-to-gray" + case ColorBGRToBGR555: + return "color-bgr-to-bgr555" + case ColorRGBToBGR555: + return "color-rgb-to-bgr555" + case ColorBGR555ToBGR: + return "color-bgr555-to-bgr" + case ColorBGRAToBGR555: + return "color-bgra-to-bgr555" + case ColorRGBAToBGR555: + return "color-rgba-to-bgr555" + case ColorBGR555ToBGRA: + return "color-bgr555-to-bgra" + case ColorBGR555ToRGBA: + return "color-bgr555-to-rgba" + case ColorGrayToBGR555: + return "color-gray-to-bgr555" + case ColorBGR555ToGRAY: + return "color-bgr555-to-gray" + case ColorBGRToXYZ: + return "color-bgr-to-xyz" + case ColorRGBToXYZ: + return "color-rgb-to-xyz" + case ColorXYZToBGR: + return "color-xyz-to-bgr" + case ColorXYZToRGB: + return "color-xyz-to-rgb" + case ColorBGRToYCrCb: + return "color-bgr-to-ycrcb" + case ColorRGBToYCrCb: + return "color-rgb-to-ycrcb" + case ColorYCrCbToBGR: + return "color-ycrcb-to-bgr" + case ColorYCrCbToRGB: + return "color-ycrcb-to-rgb" + case ColorBGRToHSV: + return "color-bgr-to-hsv" + case ColorRGBToHSV: + return "color-rgb-to-hsv" + case ColorBGRToLab: + return "color-bgr-to-lab" + case ColorRGBToLab: + return "color-rgb-to-lab" + case ColorBGRToLuv: + return "color-bgr-to-luv" + case ColorRGBToLuv: + return "color-rgb-to-luv" + case ColorBGRToHLS: + return "color-bgr-to-hls" + case ColorRGBToHLS: + return "color-rgb-to-hls" + case ColorHSVToBGR: + return "color-hsv-to-bgr" + case ColorHSVToRGB: + return "color-hsv-to-rgb" + case ColorLabToBGR: + return "color-lab-to-bgr" + case ColorLabToRGB: + return "color-lab-to-rgb" + case ColorLuvToBGR: + return "color-luv-to-bgr" + case ColorLuvToRGB: + return "color-luv-to-rgb" + case ColorHLSToBGR: + return "color-hls-to-bgr" + case ColorHLSToRGB: + return "color-hls-to-rgb" + case ColorBGRToHSVFull: + return "color-bgr-to-hsv-full" + case ColorRGBToHSVFull: + return "color-rgb-to-hsv-full" + case ColorBGRToHLSFull: + return "color-bgr-to-hls-full" + case ColorRGBToHLSFull: + return "color-rgb-to-hls-full" + case ColorHSVToBGRFull: + return "color-hsv-to-bgr-full" + case ColorHSVToRGBFull: + return "color-hsv-to-rgb-full" + case ColorHLSToBGRFull: + return "color-hls-to-bgr-full" + case ColorHLSToRGBFull: + return "color-hls-to-rgb-full" + case ColorLBGRToLab: + return "color-lbgr-to-lab" + case ColorLRGBToLab: + return "color-lrgb-to-lab" + case ColorLBGRToLuv: + return "color-lbgr-to-luv" + case ColorLRGBToLuv: + return "color-lrgb-to-luv" + case ColorLabToLBGR: + return "color-lab-to-lbgr" + case ColorLabToLRGB: + return "color-lab-to-lrgb" + case ColorLuvToLBGR: + return "color-luv-to-lbgr" + case ColorLuvToLRGB: + return "color-luv-to-lrgb" + case ColorBGRToYUV: + return "color-bgr-to-yuv" + case ColorRGBToYUV: + return "color-rgb-to-yuv" + case ColorYUVToBGR: + return "color-yuv-to-bgr" + case ColorYUVToRGB: + return "color-yuv-to-rgb" + + case ColorYUVToRGBNV12: + return "color-yuv-to-rgbnv12" + case ColorYUVToBGRNV12: + return "color-yuv-to-bgrnv12" + case ColorYUVToRGBNV21: + return "color-yuv-to-rgbnv21" + case ColorYUVToBGRNV21: + return "color-yuv-to-bgrnv21" + + case ColorYUVToRGBANV12: + return "color-yuv-to-rgbanv12" + case ColorYUVToBGRANV12: + return "color-yuv-to-bgranv12" + case ColorYUVToRGBANV21: + return "color-yuv-to-rgbanv21" + case ColorYUVToBGRANV21: + return "color-yuv-to-bgranv21" + + case ColorYUVToRGBYV12: + return "color-yuv-to-rgbyv12" + case ColorYUVToBGRYV12: + return "color-yuv-to-bgryv12" + + case ColorYUVToRGBIYUV: + return "color-yuv-to-rgbiyuv" + case ColorYUVToBGRIYUV: + return "color-yuv-to-bgriyuv" + + case ColorYUVToRGBAYV12: + return "color-yuv-to-rgbayv12" + case ColorYUVToBGRAYV12: + return "color-yuv-to-bgrayv12" + case ColorYUVToRGBAIYUV: + return "color-yuv-to-rgbaiyuv" + case ColorYUVToBGRAIYUV: + return "color-yuv-to-bgraiyuv" + + case ColorYUVToGRAY420: + return "color-yuv-to-gray420" + + case ColorYUVToRGBUYVY: + return "color-yuv-to-rgbuyvy" + case ColorYUVToBGRUYVY: + return "color-yuv-to-bgruyvy" + + case ColorYUVToRGBAUYVY: + return "color-yuv-to-rgbauyvy" + case ColorYUVToBGRAUYVY: + return "color-yuv-to-bgrauyvy" + + case ColorYUVToRGBYUY2: + return "color-yuv-to-rgbyuy2" + case ColorYUVToBGRYUY2: + return "color-yuv-to-bgryuy2" + + case ColorYUVToRGBYVYU: + return "color-yuv-to-rgbyvyu" + case ColorYUVToBGRYVYU: + return "color-yuv-to-bgryvyu" + + case ColorYUVToRGBAYUY2: + return "color-yuv-to-rgbayuy2" + case ColorYUVToBGRAYUY2: + return "color-yuv-to-bgrayuy2" + + case ColorYUVToRGBAYVYU: + return "color-yuv-to-rgbayvyu" + case ColorYUVToBGRAYVYU: + return "color-yuv-to-bgrayvyu" + + case ColorYUVToGRAYUYVY: + return "color-yuv-to-grayuyvy" + case ColorYUVToGRAYYUY2: + return "color-yuv-to-grayyuy2" + + case ColorRGBATomRGBA: + return "color-rgba-to-mrgba" + case ColormRGBAToRGBA: + return "color-mrgba-to-rgba" + + case ColorRGBToYUVI420: + return "color-rgb-to-yuvi420" + case ColorBGRToYUVI420: + return "color-bgr-to-yuvi420" + + case ColorRGBAToYUVI420: + return "color-rgba-to-yuvi420" + + case ColorBGRAToYUVI420: + return "color-bgra-to-yuvi420" + case ColorRGBToYUVYV12: + return "color-rgb-to-yuvyv12" + case ColorBGRToYUVYV12: + return "color-bgr-to-yuvyv12" + case ColorRGBAToYUVYV12: + return "color-rgba-to-yuvyv12" + case ColorBGRAToYUVYV12: + return "color-bgra-to-yuvyv12" + + case ColorBayerBGToBGR: + return "color-bayer-bgt-to-bgr" + case ColorBayerGBToBGR: + return "color-bayer-gbt-to-bgr" + case ColorBayerRGToBGR: + return "color-bayer-rgt-to-bgr" + case ColorBayerGRToBGR: + return "color-bayer-grt-to-bgr" + + case ColorBayerBGToGRAY: + return "color-bayer-bgt-to-gray" + case ColorBayerGBToGRAY: + return "color-bayer-gbt-to-gray" + case ColorBayerRGToGRAY: + return "color-bayer-rgt-to-gray" + case ColorBayerGRToGRAY: + return "color-bayer-grt-to-gray" + + case ColorBayerBGToBGRVNG: + return "color-bayer-bgt-to-bgrvng" + case ColorBayerGBToBGRVNG: + return "color-bayer-gbt-to-bgrvng" + case ColorBayerRGToBGRVNG: + return "color-bayer-rgt-to-bgrvng" + case ColorBayerGRToBGRVNG: + return "color-bayer-grt-to-bgrvng" + + case ColorBayerBGToBGREA: + return "color-bayer-bgt-to-bgrea" + case ColorBayerGBToBGREA: + return "color-bayer-gbt-to-bgrea" + case ColorBayerRGToBGREA: + return "color-bayer-rgt-to-bgrea" + case ColorBayerGRToBGREA: + return "color-bayer-grt-to-bgrea" + + case ColorBayerBGToBGRA: + return "color-bayer-bgt-to-bgra" + case ColorBayerGBToBGRA: + return "color-bayer-gbt-to-bgra" + case ColorBayerRGToBGRA: + return "color-bayer-rgt-to-bgra" + case ColorBayerGRToBGRA: + return "color-bayer-grt-to-bgra" + case ColorCOLORCVTMAX: + return "color-color-cvt-max" + } + return "" +} diff --git a/vendor/gocv.io/x/gocv/imgproc_string.go b/vendor/gocv.io/x/gocv/imgproc_string.go new file mode 100644 index 00000000..589c7cb8 --- /dev/null +++ b/vendor/gocv.io/x/gocv/imgproc_string.go @@ -0,0 +1,333 @@ +package gocv + +func (c HistCompMethod) String() string { + switch c { + case HistCmpCorrel: + return "hist-cmp-correl" + case HistCmpChiSqr: + return "hist-cmp-chi-sqr" + case HistCmpIntersect: + return "hist-cmp-intersect" + case HistCmpBhattacharya: + return "hist-cmp-bhattacharya" + case HistCmpChiSqrAlt: + return "hist-cmp-chi-sqr-alt" + case HistCmpKlDiv: + return "hist-cmp-kl-div" + } + return "" +} + +func (c DistanceTransformLabelTypes) String() string { + switch c { + case DistanceLabelCComp: + return "distance-label-ccomp" + } + return "" +} + +func (c DistanceTransformMasks) String() string { + switch c { + case DistanceMask3: + return "distance-mask3" + } + return "" +} + +func (c RetrievalMode) String() string { + switch c { + case RetrievalExternal: + return "retrieval-external" + case RetrievalList: + return "retrieval-list" + case RetrievalCComp: + return "retrieval-ccomp" + case RetrievalTree: + return "retrieval-tree" + case RetrievalFloodfill: + return "retrieval-floodfill" + } + return "" +} + +func (c ContourApproximationMode) String() string { + switch c { + case ChainApproxNone: + return "chain-approx-none" + case ChainApproxSimple: + return "chain-approx-simple" + case ChainApproxTC89L1: + return "chain-approx-tc89l1" + case ChainApproxTC89KCOS: + return "chain-approx-tc89kcos" + } + return "" +} + +func (c ConnectedComponentsAlgorithmType) String() string { + switch c { + case CCL_WU: + return "ccl-wu" + case CCL_DEFAULT: + return "ccl-default" + case CCL_GRANA: + return "ccl-grana" + } + return "" +} + +func (c ConnectedComponentsTypes) String() string { + switch c { + case CC_STAT_LEFT: + return "cc-stat-left" + case CC_STAT_TOP: + return "cc-stat-top" + case CC_STAT_WIDTH: + return "cc-stat-width" + case CC_STAT_AREA: + return "cc-stat-area" + case CC_STAT_MAX: + return "cc-stat-max" + case CC_STAT_HEIGHT: + return "cc-stat-height" + } + return "" +} + +func (c TemplateMatchMode) String() string { + switch c { + case TmSqdiff: + return "tm-sq-diff" + case TmSqdiffNormed: + return "tm-sq-diff-normed" + case TmCcorr: + return "tm-ccorr" + case TmCcorrNormed: + return "tm-ccorr-normed" + case TmCcoeff: + return "tm-ccoeff" + case TmCcoeffNormed: + return "tm-ccoeff-normed" + } + return "" +} + +func (c MorphShape) String() string { + switch c { + case MorphRect: + return "morph-rect" + case MorphCross: + return "morph-cross" + case MorphEllipse: + return "morph-ellispe" + } + return "" +} + +func (c MorphType) String() string { + switch c { + case MorphErode: + return "morph-erode" + case MorphDilate: + return "morph-dilate" + case MorphOpen: + return "morph-open" + case MorphClose: + return "morph-close" + case MorphGradient: + return "morph-gradient" + case MorphTophat: + return "morph-tophat" + case MorphBlackhat: + return "morph-blackhat" + case MorphHitmiss: + return "morph-hitmiss" + } + return "" +} + +func (c BorderType) String() string { + switch c { + case BorderConstant: + return "border-constant" + case BorderReplicate: + return "border-replicate" + case BorderReflect: + return "border-reflect" + case BorderWrap: + return "border-wrap" + case BorderTransparent: + return "border-transparent" + case BorderDefault: + return "border-default" + case BorderIsolated: + return "border-isolated" + } + return "" +} + +func (c GrabCutMode) String() string { + switch c { + case GCInitWithRect: + return "gc-init-with-rect" + case GCInitWithMask: + return "gc-init-with-mask" + case GCEval: + return "gc-eval" + case GCEvalFreezeModel: + return "gc-eval-freeze-model" + } + return "" +} + +func (c HoughMode) String() string { + switch c { + case HoughStandard: + return "hough-standard" + case HoughProbabilistic: + return "hough-probabilistic" + case HoughMultiScale: + return "hough-multi-scale" + case HoughGradient: + return "hough-gradient" + } + return "" +} + +func (c ThresholdType) String() string { + switch c { + case ThresholdBinary: + return "threshold-binary" + case ThresholdBinaryInv: + return "threshold-binary-inv" + case ThresholdTrunc: + return "threshold-trunc" + case ThresholdToZero: + return "threshold-to-zero" + case ThresholdToZeroInv: + return "threshold-to-zero-inv" + case ThresholdMask: + return "threshold-mask" + case ThresholdOtsu: + return "threshold-otsu" + case ThresholdTriangle: + return "threshold-triangle" + } + return "" +} + +func (c AdaptiveThresholdType) String() string { + switch c { + case AdaptiveThresholdMean: + return "adaptative-threshold-mean" + case AdaptiveThresholdGaussian: + return "adaptative-threshold-gaussian" + } + return "" +} + +func (c HersheyFont) String() string { + switch c { + case FontHersheySimplex: + return "font-hershey-simplex" + case FontHersheyPlain: + return "font-hershey-plain" + case FontHersheyDuplex: + return "font-hershey-duplex" + case FontHersheyComplex: + return "font-hershey-complex" + case FontHersheyTriplex: + return "font-hershey-triplex" + case FontHersheyComplexSmall: + return "font-hershey-complex-small" + case FontHersheyScriptSimplex: + return "font-hershey-script-simplex" + case FontHersheyScriptComplex: + return "font-hershey-scipt-complex" + case FontItalic: + return "font-italic" + } + return "" +} + +func (c LineType) String() string { + switch c { + case Filled: + return "filled" + case Line4: + return "line4" + case Line8: + return "line8" + case LineAA: + return "line-aa" + } + return "" +} + +func (c InterpolationFlags) String() string { + switch c { + case InterpolationNearestNeighbor: + return "interpolation-nearest-neighbor" + case InterpolationLinear: + return "interpolation-linear" + case InterpolationCubic: + return "interpolation-cubic" + case InterpolationArea: + return "interpolation-area" + case InterpolationLanczos4: + return "interpolation-lanczos4" + case InterpolationMax: + return "interpolation-max" + } + return "" +} + +func (c ColormapTypes) String() string { + switch c { + case ColormapAutumn: + return "colormap-autumn" + case ColormapBone: + return "colormap-bone" + case ColormapJet: + return "colormap-jet" + case ColormapWinter: + return "colormap-winter" + case ColormapRainbow: + return "colormap-rainbow" + case ColormapOcean: + return "colormap-ocean" + case ColormapSummer: + return "colormap-summer" + case ColormapSpring: + return "colormap-spring" + case ColormapCool: + return "colormap-cool" + case ColormapHsv: + return "colormap-hsv" + case ColormapPink: + return "colormap-pink" + case ColormapParula: + return "colormap-parula" + } + return "" +} + +func (c DistanceTypes) String() string { + switch c { + case DistUser: + return "dist-user" + case DistL1: + return "dist-l1" + case DistL2: + return "dist-l2" + case DistL12: + return "dist-l12" + case DistFair: + return "dist-fair" + case DistWelsch: + return "dist-welsch" + case DistHuber: + return "dist-huber" + } + return "" +} diff --git a/vendor/gocv.io/x/gocv/mat_noprofile.go b/vendor/gocv.io/x/gocv/mat_noprofile.go new file mode 100644 index 00000000..5cc82a38 --- /dev/null +++ b/vendor/gocv.io/x/gocv/mat_noprofile.go @@ -0,0 +1,27 @@ +// +build !matprofile + +package gocv + +/* +#include +#include "core.h" +*/ +import "C" + +// addMatToProfile does nothing if matprofile tag is not set. +func addMatToProfile(p C.Mat) { + return +} + +// newMat returns a new Mat from a C Mat +func newMat(p C.Mat) Mat { + return Mat{p: p} +} + +// Close the Mat object. +func (m *Mat) Close() error { + C.Mat_Close(m.p) + m.p = nil + m.d = nil + return nil +} diff --git a/vendor/gocv.io/x/gocv/mat_profile.go b/vendor/gocv.io/x/gocv/mat_profile.go new file mode 100644 index 00000000..eaeaca8b --- /dev/null +++ b/vendor/gocv.io/x/gocv/mat_profile.go @@ -0,0 +1,83 @@ +// +build matprofile + +package gocv + +/* +#include +#include "core.h" +*/ +import ( + "C" +) + +import ( + "runtime/pprof" +) + +// MatProfile a pprof.Profile that contains stack traces that led to (currently) +// unclosed Mat's creations. Every time a Mat is created, the stack trace is +// added to this profile and every time the Mat is closed the trace is removed. +// In a program that is not leaking, this profile's count should not +// continuously increase and ideally when a program is terminated the count +// should be zero. You can get the count at any time with: +// +// gocv.MatProfile.Count() +// +// and you can display the current entries with: +// +// var b bytes.Buffer +// gocv.MatProfile.WriteTo(&b, 1) +// fmt.Print(b.String()) +// +// This will display stack traces of where the unclosed Mats were instantiated. +// For example, the results could look something like this: +// +// 1 @ 0x4146a0c 0x4146a57 0x4119666 0x40bb18f 0x405a841 +// # 0x4146a0b gocv.io/x/gocv.newMat+0x4b /go/src/gocv.io/x/gocv/core.go:120 +// # 0x4146a56 gocv.io/x/gocv.NewMat+0x26 /go/src/gocv.io/x/gocv/core.go:126 +// # 0x4119665 gocv.io/x/gocv.TestMat+0x25 /go/src/gocv.io/x/gocv/core_test.go:29 +// # 0x40bb18e testing.tRunner+0xbe /usr/local/Cellar/go/1.11/libexec/src/testing/testing.go:827 +// +// 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 using: +// +// import _ "net/http/pprof" +// +// In order to include the MatProfile custom profiler, you MUST build or run your application +// or tests using the following build tag: +// -tags matprofile +// +// For more information, see the runtime/pprof package documentation. +var MatProfile *pprof.Profile + +func init() { + profName := "gocv.io/x/gocv.Mat" + MatProfile = pprof.Lookup(profName) + if MatProfile == nil { + MatProfile = pprof.NewProfile(profName) + } +} + +// addMatToProfile records Mat to the MatProfile. +func addMatToProfile(p C.Mat) { + MatProfile.Add(p, 1) + return +} + +// newMat returns a new Mat from a C Mat and records it to the MatProfile. +func newMat(p C.Mat) Mat { + m := Mat{p: p} + MatProfile.Add(p, 1) + return m +} + +// Close the Mat object. +func (m *Mat) Close() error { + // NOTE: The pointer must be removed from the profile before it is deleted to + // avoid a data race. + MatProfile.Remove(m.p) + C.Mat_Close(m.p) + m.p = nil + m.d = nil + return nil +} diff --git a/vendor/gocv.io/x/gocv/objdetect.cpp b/vendor/gocv.io/x/gocv/objdetect.cpp new file mode 100644 index 00000000..ebbe97b8 --- /dev/null +++ b/vendor/gocv.io/x/gocv/objdetect.cpp @@ -0,0 +1,178 @@ +#include "objdetect.h" + +// CascadeClassifier + +CascadeClassifier CascadeClassifier_New() { + return new cv::CascadeClassifier(); +} + +void CascadeClassifier_Close(CascadeClassifier cs) { + delete cs; +} + +int CascadeClassifier_Load(CascadeClassifier cs, const char* name) { + return cs->load(name); +} + +struct Rects CascadeClassifier_DetectMultiScale(CascadeClassifier cs, Mat img) { + std::vector detected; + cs->detectMultiScale(*img, detected); // uses all default parameters + Rect* rects = new Rect[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height}; + rects[i] = r; + } + + Rects ret = {rects, (int)detected.size()}; + return ret; +} + +struct Rects CascadeClassifier_DetectMultiScaleWithParams(CascadeClassifier cs, Mat img, + double scale, int minNeighbors, int flags, Size minSize, Size maxSize) { + + cv::Size minSz(minSize.width, minSize.height); + cv::Size maxSz(maxSize.width, maxSize.height); + + std::vector detected; + cs->detectMultiScale(*img, detected, scale, minNeighbors, flags, minSz, maxSz); + Rect* rects = new Rect[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height}; + rects[i] = r; + } + + Rects ret = {rects, (int)detected.size()}; + return ret; +} + +// HOGDescriptor + +HOGDescriptor HOGDescriptor_New() { + return new cv::HOGDescriptor(); +} + +void HOGDescriptor_Close(HOGDescriptor hog) { + delete hog; +} + +int HOGDescriptor_Load(HOGDescriptor hog, const char* name) { + return hog->load(name); +} + +struct Rects HOGDescriptor_DetectMultiScale(HOGDescriptor hog, Mat img) { + std::vector detected; + hog->detectMultiScale(*img, detected); + Rect* rects = new Rect[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height}; + rects[i] = r; + } + + Rects ret = {rects, (int)detected.size()}; + return ret; +} + +struct Rects HOGDescriptor_DetectMultiScaleWithParams(HOGDescriptor hog, Mat img, + double hitThresh, Size winStride, Size padding, double scale, double finalThresh, + bool useMeanshiftGrouping) { + + cv::Size wSz(winStride.width, winStride.height); + cv::Size pSz(padding.width, padding.height); + + std::vector detected; + hog->detectMultiScale(*img, detected, hitThresh, wSz, pSz, scale, finalThresh, + useMeanshiftGrouping); + Rect* rects = new Rect[detected.size()]; + + for (size_t i = 0; i < detected.size(); ++i) { + Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height}; + rects[i] = r; + } + + Rects ret = {rects, (int)detected.size()}; + return ret; +} + +Mat HOG_GetDefaultPeopleDetector() { + return new cv::Mat(cv::HOGDescriptor::getDefaultPeopleDetector()); +} + +void HOGDescriptor_SetSVMDetector(HOGDescriptor hog, Mat det) { + hog->setSVMDetector(*det); +} + +struct Rects GroupRectangles(struct Rects rects, int groupThreshold, double eps) { + std::vector vRect; + + for (int i = 0; i < rects.length; ++i) { + cv::Rect r = cv::Rect(rects.rects[i].x, rects.rects[i].y, rects.rects[i].width, + rects.rects[i].height); + vRect.push_back(r); + } + + cv::groupRectangles(vRect, groupThreshold, eps); + + Rect* results = new Rect[vRect.size()]; + + for (size_t i = 0; i < vRect.size(); ++i) { + Rect r = {vRect[i].x, vRect[i].y, vRect[i].width, vRect[i].height}; + results[i] = r; + } + + Rects ret = {results, (int)vRect.size()}; + return ret; +} + +// QRCodeDetector + +QRCodeDetector QRCodeDetector_New() { + return new cv::QRCodeDetector(); +} + +void QRCodeDetector_Close(QRCodeDetector qr) { + delete qr; +} + +const char* QRCodeDetector_DetectAndDecode(QRCodeDetector qr, Mat input,Mat points,Mat straight_qrcode) { + cv::String *str = new cv::String(qr->detectAndDecode(*input,*points,*straight_qrcode)); + return str->c_str(); +} + +bool QRCodeDetector_Detect(QRCodeDetector qr, Mat input,Mat points) { + return qr->detect(*input,*points); +} + +const char* QRCodeDetector_Decode(QRCodeDetector qr, Mat input,Mat inputPoints,Mat straight_qrcode) { + cv::String *str = new cv::String(qr->detectAndDecode(*input,*inputPoints,*straight_qrcode)); + return str->c_str(); +} + +bool QRCodeDetector_DetectMulti(QRCodeDetector qr, Mat input, Mat points) { + return qr->detectMulti(*input,*points); +} + +bool QRCodeDetector_DetectAndDecodeMulti(QRCodeDetector qr, Mat input, CStrings* decoded, Mat points, struct Mats* qrCodes) { + std::vector decodedCodes; + std::vector straightQrCodes; + bool res = qr->detectAndDecodeMulti(*input, decodedCodes, *points, straightQrCodes); + if (!res) { + return res; + } + + qrCodes->mats = new Mat[straightQrCodes.size()]; + qrCodes->length = straightQrCodes.size(); + for (size_t i = 0; i < straightQrCodes.size(); i++) { + qrCodes->mats[i] = new cv::Mat(straightQrCodes[i]); + } + + const char **strs = new const char*[decodedCodes.size()]; + for (size_t i = 0; i < decodedCodes.size(); ++i) { + strs[i] = decodedCodes[i].c_str(); + } + decoded->length = decodedCodes.size(); + decoded->strs = strs; + return res; +} \ No newline at end of file diff --git a/vendor/gocv.io/x/gocv/objdetect.go b/vendor/gocv.io/x/gocv/objdetect.go new file mode 100644 index 00000000..af26f4dd --- /dev/null +++ b/vendor/gocv.io/x/gocv/objdetect.go @@ -0,0 +1,285 @@ +package gocv + +/* +#include +#include "objdetect.h" +*/ +import "C" +import ( + "image" + "unsafe" +) + +// CascadeClassifier is a cascade classifier class for object detection. +// +// For further details, please see: +// http://docs.opencv.org/master/d1/de5/classcv_1_1CascadeClassifier.html +// +type CascadeClassifier struct { + p C.CascadeClassifier +} + +// NewCascadeClassifier returns a new CascadeClassifier. +func NewCascadeClassifier() CascadeClassifier { + return CascadeClassifier{p: C.CascadeClassifier_New()} +} + +// Close deletes the CascadeClassifier's pointer. +func (c *CascadeClassifier) Close() error { + C.CascadeClassifier_Close(c.p) + c.p = nil + return nil +} + +// Load cascade classifier from a file. +// +// For further details, please see: +// http://docs.opencv.org/master/d1/de5/classcv_1_1CascadeClassifier.html#a1a5884c8cc749422f9eb77c2471958bc +// +func (c *CascadeClassifier) Load(name string) bool { + cName := C.CString(name) + defer C.free(unsafe.Pointer(cName)) + return C.CascadeClassifier_Load(c.p, cName) != 0 +} + +// DetectMultiScale detects objects of different sizes in the input Mat image. +// The detected objects are returned as a slice of image.Rectangle structs. +// +// For further details, please see: +// http://docs.opencv.org/master/d1/de5/classcv_1_1CascadeClassifier.html#aaf8181cb63968136476ec4204ffca498 +// +func (c *CascadeClassifier) DetectMultiScale(img Mat) []image.Rectangle { + ret := C.CascadeClassifier_DetectMultiScale(c.p, img.p) + defer C.Rects_Close(ret) + + return toRectangles(ret) +} + +// DetectMultiScaleWithParams calls DetectMultiScale but allows setting parameters +// to values other than just the defaults. +// +// For further details, please see: +// http://docs.opencv.org/master/d1/de5/classcv_1_1CascadeClassifier.html#aaf8181cb63968136476ec4204ffca498 +// +func (c *CascadeClassifier) DetectMultiScaleWithParams(img Mat, scale float64, + minNeighbors, flags int, minSize, maxSize image.Point) []image.Rectangle { + + minSz := C.struct_Size{ + width: C.int(minSize.X), + height: C.int(minSize.Y), + } + + maxSz := C.struct_Size{ + width: C.int(maxSize.X), + height: C.int(maxSize.Y), + } + + ret := C.CascadeClassifier_DetectMultiScaleWithParams(c.p, img.p, C.double(scale), + C.int(minNeighbors), C.int(flags), minSz, maxSz) + defer C.Rects_Close(ret) + + return toRectangles(ret) +} + +// HOGDescriptor is a Histogram Of Gradiants (HOG) for object detection. +// +// For further details, please see: +// https://docs.opencv.org/master/d5/d33/structcv_1_1HOGDescriptor.html#a723b95b709cfd3f95cf9e616de988fc8 +// +type HOGDescriptor struct { + p C.HOGDescriptor +} + +// NewHOGDescriptor returns a new HOGDescriptor. +func NewHOGDescriptor() HOGDescriptor { + return HOGDescriptor{p: C.HOGDescriptor_New()} +} + +// Close deletes the HOGDescriptor's pointer. +func (h *HOGDescriptor) Close() error { + C.HOGDescriptor_Close(h.p) + h.p = nil + return nil +} + +// DetectMultiScale detects objects in the input Mat image. +// The detected objects are returned as a slice of image.Rectangle structs. +// +// For further details, please see: +// https://docs.opencv.org/master/d5/d33/structcv_1_1HOGDescriptor.html#a660e5cd036fd5ddf0f5767b352acd948 +// +func (h *HOGDescriptor) DetectMultiScale(img Mat) []image.Rectangle { + ret := C.HOGDescriptor_DetectMultiScale(h.p, img.p) + defer C.Rects_Close(ret) + + return toRectangles(ret) +} + +// DetectMultiScaleWithParams calls DetectMultiScale but allows setting parameters +// to values other than just the defaults. +// +// For further details, please see: +// https://docs.opencv.org/master/d5/d33/structcv_1_1HOGDescriptor.html#a660e5cd036fd5ddf0f5767b352acd948 +// +func (h *HOGDescriptor) DetectMultiScaleWithParams(img Mat, hitThresh float64, + winStride, padding image.Point, scale, finalThreshold float64, useMeanshiftGrouping bool) []image.Rectangle { + wSz := C.struct_Size{ + width: C.int(winStride.X), + height: C.int(winStride.Y), + } + + pSz := C.struct_Size{ + width: C.int(padding.X), + height: C.int(padding.Y), + } + + ret := C.HOGDescriptor_DetectMultiScaleWithParams(h.p, img.p, C.double(hitThresh), + wSz, pSz, C.double(scale), C.double(finalThreshold), C.bool(useMeanshiftGrouping)) + defer C.Rects_Close(ret) + + return toRectangles(ret) +} + +// HOGDefaultPeopleDetector returns a new Mat with the HOG DefaultPeopleDetector. +// +// For further details, please see: +// https://docs.opencv.org/master/d5/d33/structcv_1_1HOGDescriptor.html#a660e5cd036fd5ddf0f5767b352acd948 +// +func HOGDefaultPeopleDetector() Mat { + return newMat(C.HOG_GetDefaultPeopleDetector()) +} + +// SetSVMDetector sets the data for the HOGDescriptor. +// +// For further details, please see: +// https://docs.opencv.org/master/d5/d33/structcv_1_1HOGDescriptor.html#a09e354ad701f56f9c550dc0385dc36f1 +// +func (h *HOGDescriptor) SetSVMDetector(det Mat) error { + C.HOGDescriptor_SetSVMDetector(h.p, det.p) + return nil +} + +// GroupRectangles groups the object candidate rectangles. +// +// For further details, please see: +// https://docs.opencv.org/master/d5/d54/group__objdetect.html#ga3dba897ade8aa8227edda66508e16ab9 +// +func GroupRectangles(rects []image.Rectangle, groupThreshold int, eps float64) []image.Rectangle { + cRectArray := make([]C.struct_Rect, len(rects)) + for i, r := range rects { + cRect := C.struct_Rect{ + x: C.int(r.Min.X), + y: C.int(r.Min.Y), + width: C.int(r.Size().X), + height: C.int(r.Size().Y), + } + cRectArray[i] = cRect + } + cRects := C.struct_Rects{ + rects: (*C.Rect)(&cRectArray[0]), + length: C.int(len(rects)), + } + + ret := C.GroupRectangles(cRects, C.int(groupThreshold), C.double(eps)) + + return toRectangles(ret) +} + +// QRCodeDetector groups the object candidate rectangles. +// +// For further details, please see: +// https://docs.opencv.org/master/de/dc3/classcv_1_1QRCodeDetector.html +// +type QRCodeDetector struct { + p C.QRCodeDetector +} + +// newQRCodeDetector returns a new QRCodeDetector from a C QRCodeDetector +func newQRCodeDetector(p C.QRCodeDetector) QRCodeDetector { + return QRCodeDetector{p: p} +} + +func NewQRCodeDetector() QRCodeDetector { + return newQRCodeDetector(C.QRCodeDetector_New()) +} + +func (a *QRCodeDetector) Close() error { + C.QRCodeDetector_Close(a.p) + a.p = nil + return nil +} + +// DetectAndDecode Both detects and decodes QR code. +// +// Returns true as long as some QR code was detected even in case where the decoding failed +// For further details, please see: +// https://docs.opencv.org/master/de/dc3/classcv_1_1QRCodeDetector.html#a7290bd6a5d59b14a37979c3a14fbf394 +// +func (a *QRCodeDetector) DetectAndDecode(input Mat, points *Mat, straight_qrcode *Mat) string { + goResult := C.GoString(C.QRCodeDetector_DetectAndDecode(a.p, input.p, points.p, straight_qrcode.p)) + return string(goResult) +} + +// Detect detects QR code in image and returns the quadrangle containing the code. +// +// For further details, please see: +// https://docs.opencv.org/master/de/dc3/classcv_1_1QRCodeDetector.html#a64373f7d877d27473f64fe04bb57d22b +// +func (a *QRCodeDetector) Detect(input Mat, points *Mat) bool { + result := C.QRCodeDetector_Detect(a.p, input.p, points.p) + return bool(result) +} + +// Decode decodes QR code in image once it's found by the detect() method. Returns UTF8-encoded output string or empty string if the code cannot be decoded. +// +// For further details, please see: +// https://docs.opencv.org/master/de/dc3/classcv_1_1QRCodeDetector.html#a4172c2eb4825c844fb1b0ae67202d329 +// +func (a *QRCodeDetector) Decode(input Mat, points Mat, straight_qrcode *Mat) string { + goResult := C.GoString(C.QRCodeDetector_DetectAndDecode(a.p, input.p, points.p, straight_qrcode.p)) + return string(goResult) +} + +// Detects QR codes in image and finds of the quadrangles containing the codes. +// +// Each quadrangle would be returned as a row in the `points` Mat and each point is a Vecf. +// Returns true if QR code was detected +// For usage please see TestQRCodeDetector +// For further details, please see: +// https://docs.opencv.org/master/de/dc3/classcv_1_1QRCodeDetector.html#aaf2b6b2115b8e8fbc9acf3a8f68872b6 +func (a *QRCodeDetector) DetectMulti(input Mat, points *Mat) bool { + result := C.QRCodeDetector_DetectMulti(a.p, input.p, points.p) + return bool(result) +} + +// Detects QR codes in image, finds the quadrangles containing the codes, and decodes the QRCodes to strings. +// +// Each quadrangle would be returned as a row in the `points` Mat and each point is a Vecf. +// Returns true as long as some QR code was detected even in case where the decoding failed +// For usage please see TestQRCodeDetector +// For further details, please see: +//https://docs.opencv.org/master/de/dc3/classcv_1_1QRCodeDetector.html#a188b63ffa17922b2c65d8a0ab7b70775 +func (a *QRCodeDetector) DetectAndDecodeMulti(input Mat, decoded *[]string, points *Mat, qrCodes *[]Mat) bool { + cDecoded := C.CStrings{} + defer C.CStrings_Close(cDecoded) + cQrCodes := C.struct_Mats{} + defer C.Mats_Close(cQrCodes) + success := C.QRCodeDetector_DetectAndDecodeMulti(a.p, input.p, &cDecoded, points.p, &cQrCodes) + if !success { + return bool(success) + } + + tmpCodes := make([]Mat, cQrCodes.length) + for i := C.int(0); i < cQrCodes.length; i++ { + tmpCodes[i].p = C.Mats_get(cQrCodes, i) + } + + for _, qr := range tmpCodes { + *qrCodes = append(*qrCodes, qr) + } + + for _, s := range toGoStrings(cDecoded) { + *decoded = append(*decoded, s) + } + return bool(success) +} diff --git a/vendor/gocv.io/x/gocv/objdetect.h b/vendor/gocv.io/x/gocv/objdetect.h new file mode 100644 index 00000000..57b9f737 --- /dev/null +++ b/vendor/gocv.io/x/gocv/objdetect.h @@ -0,0 +1,55 @@ +#ifndef _OPENCV3_OBJDETECT_H_ +#define _OPENCV3_OBJDETECT_H_ + +#include + +#ifdef __cplusplus +#include +extern "C" { +#endif + +#include "core.h" + +#ifdef __cplusplus +typedef cv::CascadeClassifier* CascadeClassifier; +typedef cv::HOGDescriptor* HOGDescriptor; +typedef cv::QRCodeDetector* QRCodeDetector; +#else +typedef void* CascadeClassifier; +typedef void* HOGDescriptor; +typedef void* QRCodeDetector; +#endif + +// CascadeClassifier +CascadeClassifier CascadeClassifier_New(); +void CascadeClassifier_Close(CascadeClassifier cs); +int CascadeClassifier_Load(CascadeClassifier cs, const char* name); +struct Rects CascadeClassifier_DetectMultiScale(CascadeClassifier cs, Mat img); +struct Rects CascadeClassifier_DetectMultiScaleWithParams(CascadeClassifier cs, Mat img, + double scale, int minNeighbors, int flags, Size minSize, Size maxSize); + +HOGDescriptor HOGDescriptor_New(); +void HOGDescriptor_Close(HOGDescriptor hog); +int HOGDescriptor_Load(HOGDescriptor hog, const char* name); +struct Rects HOGDescriptor_DetectMultiScale(HOGDescriptor hog, Mat img); +struct Rects HOGDescriptor_DetectMultiScaleWithParams(HOGDescriptor hog, Mat img, + double hitThresh, Size winStride, Size padding, double scale, double finalThreshold, + bool useMeanshiftGrouping); +Mat HOG_GetDefaultPeopleDetector(); +void HOGDescriptor_SetSVMDetector(HOGDescriptor hog, Mat det); + +struct Rects GroupRectangles(struct Rects rects, int groupThreshold, double eps); + +QRCodeDetector QRCodeDetector_New(); +const char* QRCodeDetector_DetectAndDecode(QRCodeDetector qr, Mat input,Mat points,Mat straight_qrcode); +bool QRCodeDetector_Detect(QRCodeDetector qr, Mat input,Mat points); +const char* QRCodeDetector_Decode(QRCodeDetector qr, Mat input,Mat inputPoints,Mat straight_qrcode); +void QRCodeDetector_Close(QRCodeDetector qr); +bool QRCodeDetector_DetectMulti(QRCodeDetector qr, Mat input, Mat points); +bool QRCodeDetector_DetectAndDecodeMulti(QRCodeDetector qr, Mat input, CStrings* decoded ,Mat points, struct Mats* mats); + +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_OBJDETECT_H_ diff --git a/vendor/gocv.io/x/gocv/photo.cpp b/vendor/gocv.io/x/gocv/photo.cpp new file mode 100644 index 00000000..69ce909d --- /dev/null +++ b/vendor/gocv.io/x/gocv/photo.cpp @@ -0,0 +1,122 @@ +#include "photo.h" + +void ColorChange(Mat src, Mat mask, Mat dst, float red_mul, float green_mul, float blue_mul) { + cv::colorChange(*src, *mask, *dst, red_mul, green_mul, blue_mul); +} + +void IlluminationChange(Mat src, Mat mask, Mat dst, float alpha, float beta) { + cv::illuminationChange(*src, *mask, *dst, alpha, beta); +} + +void SeamlessClone(Mat src, Mat dst, Mat mask, Point p, Mat blend, int flags) { + cv::Point pt(p.x, p.y); + cv::seamlessClone(*src, *dst, *mask, pt, *blend, flags); +} + +void TextureFlattening(Mat src, Mat mask, Mat dst, float low_threshold, float high_threshold, int kernel_size) { + cv::textureFlattening(*src, *mask, *dst, low_threshold, high_threshold, kernel_size); +} + + +void FastNlMeansDenoisingColoredMulti( struct Mats src, Mat dst, int imgToDenoiseIndex, int temporalWindowSize){ + std::vector images; + for (int i = 0; i < src.length; ++i) { + images.push_back(*src.mats[i]); + } + cv::fastNlMeansDenoisingColoredMulti( images, *dst, imgToDenoiseIndex, temporalWindowSize ); +} + +void FastNlMeansDenoisingColoredMultiWithParams( struct Mats src, Mat dst, int imgToDenoiseIndex, int temporalWindowSize, float h, float hColor, int templateWindowSize, int searchWindowSize ){ + std::vector images; + for (int i = 0; i < src.length; ++i) { + images.push_back(*src.mats[i]); + } + cv::fastNlMeansDenoisingColoredMulti( images, *dst, imgToDenoiseIndex, temporalWindowSize, h, hColor, templateWindowSize, searchWindowSize ); +} + +MergeMertens MergeMertens_Create() { + return new cv::Ptr(cv::createMergeMertens()); +} + +MergeMertens MergeMertens_CreateWithParams(float contrast_weight, + float saturation_weight, + float exposure_weight) { + return new cv::Ptr(cv::createMergeMertens( + contrast_weight, saturation_weight, exposure_weight)); +} + +void MergeMertens_Close(MergeMertens b) { + delete b; +} + +void MergeMertens_Process(MergeMertens b, struct Mats src, Mat dst) { + std::vector images; + for (int i = 0; i < src.length; ++i) { + images.push_back(*src.mats[i]); + } + (*b)->process(images, *dst); +} + +AlignMTB AlignMTB_Create() { + return new cv::Ptr(cv::createAlignMTB(6,4,false)); +} + +AlignMTB AlignMTB_CreateWithParams(int max_bits, int exclude_range, bool cut) { + return new cv::Ptr( + cv::createAlignMTB(max_bits, exclude_range, cut)); +} + +void AlignMTB_Close(AlignMTB b) { delete b; } + +void AlignMTB_Process(AlignMTB b, struct Mats src, struct Mats *dst) { + + std::vector srcMats; + for (int i = 0; i < src.length; ++i) { + srcMats.push_back(*src.mats[i]); + } + + std::vector dstMats; + (*b)->process(srcMats, dstMats); + + dst->mats = new Mat[dstMats.size()]; + for (size_t i = 0; i < dstMats.size() ; ++i) { + dst->mats[i] = new cv::Mat( dstMats[i] ); + } + dst->length = (int)dstMats.size(); +} + +void FastNlMeansDenoising(Mat src, Mat dst) { + cv::fastNlMeansDenoising(*src, *dst); +} + +void FastNlMeansDenoisingWithParams(Mat src, Mat dst, float h, int templateWindowSize, int searchWindowSize) { + cv::fastNlMeansDenoising(*src, *dst, h, templateWindowSize, searchWindowSize); +} + +void FastNlMeansDenoisingColored(Mat src, Mat dst) { + cv::fastNlMeansDenoisingColored(*src, *dst); +} + +void FastNlMeansDenoisingColoredWithParams(Mat src, Mat dst, float h, float hColor, int templateWindowSize, int searchWindowSize) { + cv::fastNlMeansDenoisingColored(*src, *dst, h, hColor, templateWindowSize, searchWindowSize); +} + +void EdgePreservingFilter(Mat src, Mat dst, int filter, float sigma_s, float sigma_r) { + cv::edgePreservingFilter(*src, *dst, filter, sigma_s, sigma_r); +} + +void DetailEnhance(Mat src, Mat dst, float sigma_s, float sigma_r) { + cv::detailEnhance(*src, *dst, sigma_s, sigma_r); +} + +void PencilSketch(Mat src, Mat dst1, Mat dst2, float sigma_s, float sigma_r, float shade_factor) { + cv::pencilSketch(*src, *dst1, *dst2, sigma_s, sigma_r, shade_factor); +} + +void Stylization(Mat src, Mat dst, float sigma_s, float sigma_r) { + cv::stylization(*src, *dst, sigma_s, sigma_r); +} + +void PhotoInpaint(Mat src, Mat mask, Mat dst, float inpaint_radius, int algorithm_type) { + cv::inpaint(*src, *mask, *dst, inpaint_radius, algorithm_type); +} diff --git a/vendor/gocv.io/x/gocv/photo.go b/vendor/gocv.io/x/gocv/photo.go new file mode 100644 index 00000000..5bd43348 --- /dev/null +++ b/vendor/gocv.io/x/gocv/photo.go @@ -0,0 +1,339 @@ +package gocv + +/* +#include +#include "photo.h" +*/ +import "C" + +import ( + "image" + "unsafe" +) + +//SeamlessCloneFlags seamlessClone algorithm flags +type SeamlessCloneFlags int + +// MergeMertens is a wrapper around the cv::MergeMertens. +type MergeMertens struct { + p unsafe.Pointer // This unsafe pointer will in fact be a C.MergeMertens +} + +// AlignMTB is a wrapper around the cv::AlignMTB. +type AlignMTB struct { + p unsafe.Pointer // This unsafe pointer will in fact be a C.AlignMTB +} + +const ( + // NormalClone The power of the method is fully expressed when inserting objects with complex outlines into a new background. + NormalClone SeamlessCloneFlags = iota + + // MixedClone The classic method, color-based selection and alpha masking might be time consuming and often leaves an undesirable halo. Seamless cloning, even averaged with the original image, is not effective. Mixed seamless cloning based on a loose selection proves effective. + MixedClone + + // MonochromeTransfer Monochrome transfer allows the user to easily replace certain features of one object by alternative features. + MonochromeTransfer +) + +// ColorChange mix two differently colored versions of an image seamlessly. +// +// For further details, please see: +// https://docs.opencv.org/master/df/da0/group__photo__clone.html#ga6684f35dc669ff6196a7c340dc73b98e +// +func ColorChange(src, mask Mat, dst *Mat, red_mul, green_mul, blue_mul float32) { + C.ColorChange(src.p, mask.p, dst.p, C.float(red_mul), C.float(green_mul), C.float(blue_mul)) +} + +// SeamlessClone blend two image by Poisson Blending. +// +// For further details, please see: +// https://docs.opencv.org/master/df/da0/group__photo__clone.html#ga2bf426e4c93a6b1f21705513dfeca49d +// +func SeamlessClone(src, dst, mask Mat, p image.Point, blend *Mat, flags SeamlessCloneFlags) { + cp := C.struct_Point{ + x: C.int(p.X), + y: C.int(p.Y), + } + + C.SeamlessClone(src.p, dst.p, mask.p, cp, blend.p, C.int(flags)) +} + +// IlluminationChange modifies locally the apparent illumination of an image. +// +// For further details, please see: +// https://docs.opencv.org/master/df/da0/group__photo__clone.html#gac5025767cf2febd8029d474278e886c7 +// +func IlluminationChange(src, mask Mat, dst *Mat, alpha, beta float32) { + C.IlluminationChange(src.p, mask.p, dst.p, C.float(alpha), C.float(beta)) +} + +// TextureFlattening washes out the texture of the selected region, giving its contents a flat aspect. +// +// For further details, please see: +// https://docs.opencv.org/master/df/da0/group__photo__clone.html#gad55df6aa53797365fa7cc23959a54004 +// +func TextureFlattening(src, mask Mat, dst *Mat, lowThreshold, highThreshold float32, kernelSize int) { + C.TextureFlattening(src.p, mask.p, dst.p, C.float(lowThreshold), C.float(highThreshold), C.int(kernelSize)) +} + +// FastNlMeansDenoisingColoredMulti denoises the selected images. +// +// For further details, please see: +// https://docs.opencv.org/master/d1/d79/group__photo__denoise.html#gaa501e71f52fb2dc17ff8ca5e7d2d3619 +// +func FastNlMeansDenoisingColoredMulti(src []Mat, dst *Mat, imgToDenoiseIndex int, temporalWindowSize int) { + cMatArray := make([]C.Mat, len(src)) + for i, r := range src { + cMatArray[i] = (C.Mat)(r.p) + } + matsVector := C.struct_Mats{ + mats: (*C.Mat)(&cMatArray[0]), + length: C.int(len(src)), + } + C.FastNlMeansDenoisingColoredMulti(matsVector, dst.p, C.int(imgToDenoiseIndex), C.int(temporalWindowSize)) +} + +// FastNlMeansDenoisingColoredMulti denoises the selected images. +// +// For further details, please see: +// https://docs.opencv.org/master/d1/d79/group__photo__denoise.html#gaa501e71f52fb2dc17ff8ca5e7d2d3619 +// +func FastNlMeansDenoisingColoredMultiWithParams(src []Mat, dst *Mat, imgToDenoiseIndex int, temporalWindowSize int, h float32, hColor float32, templateWindowSize int, searchWindowSize int) { + cMatArray := make([]C.Mat, len(src)) + for i, r := range src { + cMatArray[i] = (C.Mat)(r.p) + } + matsVector := C.struct_Mats{ + mats: (*C.Mat)(&cMatArray[0]), + length: C.int(len(src)), + } + C.FastNlMeansDenoisingColoredMultiWithParams(matsVector, dst.p, C.int(imgToDenoiseIndex), C.int(temporalWindowSize), C.float(h), C.float(hColor), C.int(templateWindowSize), C.int(searchWindowSize)) +} + +// NewMergeMertens returns returns a new MergeMertens white LDR merge algorithm. +// of type MergeMertens with default parameters. +// MergeMertens algorithm merge the ldr image should result in a HDR image. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html +// https://docs.opencv.org/master/d7/dd6/classcv_1_1MergeMertens.html +// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga79d59aa3cb3a7c664e59a4b5acc1ccb6 +// +func NewMergeMertens() MergeMertens { + return MergeMertens{p: unsafe.Pointer(C.MergeMertens_Create())} +} + +// NewMergeMertensWithParams returns a new MergeMertens white LDR merge algorithm +// of type MergeMertens with customized parameters. +// MergeMertens algorithm merge the ldr image should result in a HDR image. +// +// For further details, please see: +// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html +// https://docs.opencv.org/master/d7/dd6/classcv_1_1MergeMertens.html +// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga79d59aa3cb3a7c664e59a4b5acc1ccb6 +// +func NewMergeMertensWithParams(contrast_weight float32, saturation_weight float32, exposure_weight float32) MergeMertens { + return MergeMertens{p: unsafe.Pointer(C.MergeMertens_CreateWithParams(C.float(contrast_weight), C.float(saturation_weight), C.float(exposure_weight)))} +} + +// Close MergeMertens. +func (b *MergeMertens) Close() error { + C.MergeMertens_Close((C.MergeMertens)(b.p)) // Here the unsafe pointer is cast into the right type + b.p = nil + return nil +} + +// BalanceWhite computes merge LDR images using the current MergeMertens. +// Return a image MAT : 8bits 3 channel image ( RGB 8 bits ) +// For further details, please see: +// https://docs.opencv.org/master/d7/dd6/classcv_1_1MergeMertens.html#a2d2254b2aab722c16954de13a663644d +// +func (b *MergeMertens) Process(src []Mat, dst *Mat) { + cMatArray := make([]C.Mat, len(src)) + for i, r := range src { + cMatArray[i] = (C.Mat)(r.p) + } + // Conversion function from a Golang slice into an array of matrices that are understood by OpenCV + matsVector := C.struct_Mats{ + mats: (*C.Mat)(&cMatArray[0]), + length: C.int(len(src)), + } + C.MergeMertens_Process((C.MergeMertens)(b.p), matsVector, dst.p) + // Convert a series of double [0.0,1.0] to [0,255] with Golang + dst.ConvertToWithParams(dst, MatTypeCV8UC3, 255.0, 0.0) +} + +// NewAlignMTB returns an AlignMTB for converts images to median threshold bitmaps. +// of type AlignMTB converts images to median threshold bitmaps (1 for pixels +// brighter than median luminance and 0 otherwise) and than aligns the resulting +// bitmaps using bit operations. + +// For further details, please see: +// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html +// https://docs.opencv.org/master/d7/db6/classcv_1_1AlignMTB.html +// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga2f1fafc885a5d79dbfb3542e08db0244 +// +func NewAlignMTB() AlignMTB { + return AlignMTB{p: unsafe.Pointer(C.AlignMTB_Create())} +} + +// NewAlignMTBWithParams returns an AlignMTB for converts images to median threshold bitmaps. +// of type AlignMTB converts images to median threshold bitmaps (1 for pixels +// brighter than median luminance and 0 otherwise) and than aligns the resulting +// bitmaps using bit operations. + +// For further details, please see: +// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html +// https://docs.opencv.org/master/d7/db6/classcv_1_1AlignMTB.html +// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga2f1fafc885a5d79dbfb3542e08db0244 +// +func NewAlignMTBWithParams(max_bits int, exclude_range int, cut bool) AlignMTB { + return AlignMTB{p: unsafe.Pointer(C.AlignMTB_CreateWithParams(C.int(max_bits), C.int(exclude_range), C.bool(cut)))} +} + +// Close AlignMTB. +func (b *AlignMTB) Close() error { + C.AlignMTB_Close((C.AlignMTB)(b.p)) + b.p = nil + return nil +} + +// Process computes an alignment using the current AlignMTB. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/db6/classcv_1_1AlignMTB.html#a37b3417d844f362d781f34155cbcb201 +// +func (b *AlignMTB) Process(src []Mat, dst *[]Mat) { + + cSrcArray := make([]C.Mat, len(src)) + for i, r := range src { + cSrcArray[i] = r.p + } + cSrcMats := C.struct_Mats{ + mats: (*C.Mat)(&cSrcArray[0]), + length: C.int(len(src)), + } + + cDstMats := C.struct_Mats{} + + C.AlignMTB_Process((C.AlignMTB)(b.p), cSrcMats, &cDstMats) + + // Pass the matrices by reference from an OpenCV/C++ to a GoCV::Mat object + for i := C.int(0); i < cDstMats.length; i++ { + var tempdst Mat + tempdst.p = C.Mats_get(cDstMats, i) + *dst = append(*dst, tempdst) + } + return +} + +// FastNlMeansDenoising performs image denoising using Non-local Means Denoising algorithm +// http://www.ipol.im/pub/algo/bcm_non_local_means_denoising/ +// +// For further details, please see: +// https://docs.opencv.org/4.x/d1/d79/group__photo__denoise.html#ga4c6b0031f56ea3f98f768881279ffe93 +// +func FastNlMeansDenoising(src Mat, dst *Mat) { + C.FastNlMeansDenoising(src.p, dst.p) +} + +// FastNlMeansDenoisingWithParams performs image denoising using Non-local Means Denoising algorithm +// http://www.ipol.im/pub/algo/bcm_non_local_means_denoising/ +// +// For further details, please see: +// https://docs.opencv.org/4.x/d1/d79/group__photo__denoise.html#ga4c6b0031f56ea3f98f768881279ffe93 +// +func FastNlMeansDenoisingWithParams(src Mat, dst *Mat, h float32, templateWindowSize int, searchWindowSize int) { + C.FastNlMeansDenoisingWithParams(src.p, dst.p, C.float(h), C.int(templateWindowSize), C.int(searchWindowSize)) +} + +// FastNlMeansDenoisingColored is a modification of fastNlMeansDenoising function for colored images. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d1/d79/group__photo__denoise.html#ga21abc1c8b0e15f78cd3eff672cb6c476 +// +func FastNlMeansDenoisingColored(src Mat, dst *Mat) { + C.FastNlMeansDenoisingColored(src.p, dst.p) +} + +// FastNlMeansDenoisingColoredWithParams is a modification of fastNlMeansDenoising function for colored images. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d1/d79/group__photo__denoise.html#ga21abc1c8b0e15f78cd3eff672cb6c476 +// +func FastNlMeansDenoisingColoredWithParams(src Mat, dst *Mat, h float32, hColor float32, templateWindowSize int, searchWindowSize int) { + C.FastNlMeansDenoisingColoredWithParams(src.p, dst.p, C.float(h), C.float(hColor), C.int(templateWindowSize), C.int(searchWindowSize)) +} + +// DetailEnhance filter enhances the details of a particular image +// +// For further details, please see: +// https://docs.opencv.org/4.x/df/dac/group__photo__render.html#gae5930dd822c713b36f8529b21ddebd0c +// +func DetailEnhance(src Mat, dst *Mat, sigma_s, sigma_r float32) { + C.DetailEnhance(src.p, dst.p, C.float(sigma_s), C.float(sigma_r)) +} + +type EdgeFilter int + +const ( + // RecursFilter Recursive Filtering. + RecursFilter EdgeFilter = 1 + + // NormconvFilter Normalized Convolution Filtering. + NormconvFilter = 2 +) + +// EdgePreservingFilter filtering is the fundamental operation in image and video processing. +// Edge-preserving smoothing filters are used in many different applications. +// +// For further details, please see: +// https://docs.opencv.org/4.x/df/dac/group__photo__render.html#gafaee2977597029bc8e35da6e67bd31f7 +// +func EdgePreservingFilter(src Mat, dst *Mat, filter EdgeFilter, sigma_s, sigma_r float32) { + C.EdgePreservingFilter(src.p, dst.p, C.int(filter), C.float(sigma_s), C.float(sigma_r)) +} + +// PencilSketch pencil-like non-photorealistic line drawing. +// +// For further details, please see: +// https://docs.opencv.org/4.x/df/dac/group__photo__render.html#gae5930dd822c713b36f8529b21ddebd0c +// +func PencilSketch(src Mat, dst1, dst2 *Mat, sigma_s, sigma_r, shade_factor float32) { + C.PencilSketch(src.p, dst1.p, dst2.p, C.float(sigma_s), C.float(sigma_r), C.float(shade_factor)) +} + +// Stylization aims to produce digital imagery with a wide variety of effects +// not focused on photorealism. Edge-aware filters are ideal for stylization, +// as they can abstract regions of low contrast while preserving, or enhancing, +// high-contrast features. +// +// For further details, please see: +// https://docs.opencv.org/4.x/df/dac/group__photo__render.html#gacb0f7324017df153d7b5d095aed53206 +// +func Stylization(src Mat, dst *Mat, sigma_s, sigma_r float32) { + C.Stylization(src.p, dst.p, C.float(sigma_s), C.float(sigma_r)) +} + +// InpaintMethods is the methods for inpainting process. +type InpaintMethods int + +const ( + // NS inpaints using Navier-Stokes based method, created by Bertalmio, Marcelo, + // Andrea L. Bertozzi, and Guillermo Sapiro in 2001 + NS InpaintMethods = 0 + + // Telea inpaints using Fast Marching Method proposed by Alexandru Telea in 2004. + Telea InpaintMethods = 1 +) + +// Inpaint reconstructs the selected image area from the pixel near the area boundary. +// The function may be used to remove dust and scratches from a scanned photo, or to +// remove undesirable objects from still images or video. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d7/d8b/group__photo__inpaint.html#gaedd30dfa0214fec4c88138b51d678085 +// +func Inpaint(src Mat, mask Mat, dst *Mat, inpaintRadius float32, algorithmType InpaintMethods) { + C.PhotoInpaint(C.Mat(src.Ptr()), C.Mat(mask.Ptr()), C.Mat(dst.Ptr()), C.float(inpaintRadius), C.int(algorithmType)) +} diff --git a/vendor/gocv.io/x/gocv/photo.h b/vendor/gocv.io/x/gocv/photo.h new file mode 100644 index 00000000..9964ac8a --- /dev/null +++ b/vendor/gocv.io/x/gocv/photo.h @@ -0,0 +1,58 @@ +#ifndef _OPENCV3_PHOTO_H_ +#define _OPENCV3_PHOTO_H_ + +#ifdef __cplusplus +#include +#include +extern "C" { +#endif + +#include "core.h" + +#ifdef __cplusplus +// see : https://docs.opencv.org/3.4/d7/dd6/classcv_1_1MergeMertens.html +typedef cv::Ptr *MergeMertens; +// see : https://docs.opencv.org/master/d7/db6/classcv_1_1AlignMTB.html +typedef cv::Ptr *AlignMTB; +#else +typedef void *MergeMertens; +typedef void *AlignMTB; +#endif + +void ColorChange(Mat src, Mat mask, Mat dst, float red_mul, float green_mul, float blue_mul); + +void SeamlessClone(Mat src, Mat dst, Mat mask, Point p, Mat blend, int flags); + +void IlluminationChange(Mat src, Mat mask, Mat dst, float alpha, float beta); + +void TextureFlattening(Mat src, Mat mask, Mat dst, float low_threshold, float high_threshold, int kernel_size); + +void FastNlMeansDenoisingColoredMulti(struct Mats src, Mat dst, int imgToDenoiseIndex, int temporalWindowSize); +void FastNlMeansDenoisingColoredMultiWithParams(struct Mats src, Mat dst, int imgToDenoiseIndex, int temporalWindowSize, float h, float hColor, int templateWindowSize, int searchWindowSize ); +void FastNlMeansDenoising(Mat src, Mat dst); +void FastNlMeansDenoisingWithParams(Mat src, Mat dst, float h, int templateWindowSize, int searchWindowSize); +void FastNlMeansDenoisingColored(Mat src, Mat dst); +void FastNlMeansDenoisingColoredWithParams(Mat src, Mat dst, float h, float hColor, int templateWindowSize, int searchWindowSize); + +MergeMertens MergeMertens_Create(); +MergeMertens MergeMertens_CreateWithParams(float contrast_weight, float saturation_weight, float exposure_weight); +void MergeMertens_Process(MergeMertens b, struct Mats src, Mat dst); +void MergeMertens_Close(MergeMertens b); + +AlignMTB AlignMTB_Create(); +AlignMTB AlignMTB_CreateWithParams(int max_bits, int exclude_range, bool cut); +void AlignMTB_Process(AlignMTB b, struct Mats src, struct Mats *dst); +void AlignMTB_Close(AlignMTB b); + +void DetailEnhance(Mat src, Mat dst, float sigma_s, float sigma_r); +void EdgePreservingFilter(Mat src, Mat dst, int filter, float sigma_s, float sigma_r); +void PencilSketch(Mat src, Mat dst1, Mat dst2, float sigma_s, float sigma_r, float shade_factor); +void Stylization(Mat src, Mat dst, float sigma_s, float sigma_r); + +void PhotoInpaint(Mat src, Mat mask, Mat dst, float inpaint_radius, int algorithm_type); + +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_PHOTO_H diff --git a/vendor/gocv.io/x/gocv/photo_string.go b/vendor/gocv.io/x/gocv/photo_string.go new file mode 100644 index 00000000..786e5f78 --- /dev/null +++ b/vendor/gocv.io/x/gocv/photo_string.go @@ -0,0 +1,13 @@ +package gocv + +func (c SeamlessCloneFlags) String() string { + switch c { + case NormalClone: + return "normal-clone" + case MixedClone: + return "mixed-clone" + case MonochromeTransfer: + return "monochrome-transfer" + } + return "" +} diff --git a/vendor/gocv.io/x/gocv/svd.cpp b/vendor/gocv.io/x/gocv/svd.cpp new file mode 100644 index 00000000..0e0e82d6 --- /dev/null +++ b/vendor/gocv.io/x/gocv/svd.cpp @@ -0,0 +1,5 @@ +#include "svd.h" + +void SVD_Compute(Mat src, Mat w, Mat u, Mat vt) { + cv::SVD::compute(*src, *w, *u, *vt, 0); +} \ No newline at end of file diff --git a/vendor/gocv.io/x/gocv/svd.go b/vendor/gocv.io/x/gocv/svd.go new file mode 100644 index 00000000..16f26ef4 --- /dev/null +++ b/vendor/gocv.io/x/gocv/svd.go @@ -0,0 +1,14 @@ +package gocv + +/* +#include +#include "svd.h" +*/ +import "C" + +// SVDCompute decomposes matrix and stores the results to user-provided matrices +// +// https://docs.opencv.org/4.1.2/df/df7/classcv_1_1SVD.html#a76f0b2044df458160292045a3d3714c6 +func SVDCompute(src Mat, w, u, vt *Mat) { + C.SVD_Compute(src.Ptr(), w.Ptr(), u.Ptr(), vt.Ptr()) +} diff --git a/vendor/gocv.io/x/gocv/svd.h b/vendor/gocv.io/x/gocv/svd.h new file mode 100644 index 00000000..e3aab12f --- /dev/null +++ b/vendor/gocv.io/x/gocv/svd.h @@ -0,0 +1,18 @@ +#ifndef _OPENCV3_SVD_H_ +#define _OPENCV3_SVD_H_ + +#ifdef __cplusplus +#include + +extern "C" { +#endif + +#include "core.h" + +void SVD_Compute(Mat src, Mat w, Mat u, Mat vt); + +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_SVD_H \ No newline at end of file diff --git a/vendor/gocv.io/x/gocv/version.cpp b/vendor/gocv.io/x/gocv/version.cpp new file mode 100644 index 00000000..d4aa1654 --- /dev/null +++ b/vendor/gocv.io/x/gocv/version.cpp @@ -0,0 +1,5 @@ +#include "version.h" + +const char* openCVVersion() { + return CV_VERSION; +} diff --git a/vendor/gocv.io/x/gocv/version.go b/vendor/gocv.io/x/gocv/version.go new file mode 100644 index 00000000..214c88dc --- /dev/null +++ b/vendor/gocv.io/x/gocv/version.go @@ -0,0 +1,20 @@ +package gocv + +/* +#include +#include "version.h" +*/ +import "C" + +// GoCVVersion of this package, for display purposes. +const GoCVVersion = "0.33.0" + +// Version returns the current golang package version +func Version() string { + return GoCVVersion +} + +// OpenCVVersion returns the current OpenCV lib version +func OpenCVVersion() string { + return C.GoString(C.openCVVersion()) +} diff --git a/vendor/gocv.io/x/gocv/version.h b/vendor/gocv.io/x/gocv/version.h new file mode 100644 index 00000000..3372e577 --- /dev/null +++ b/vendor/gocv.io/x/gocv/version.h @@ -0,0 +1,17 @@ +#ifndef _OPENCV3_VERSION_H_ +#define _OPENCV3_VERSION_H_ + +#ifdef __cplusplus +#include +extern "C" { +#endif + +#include "core.h" + +const char* openCVVersion(); + +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_VERSION_H_ diff --git a/vendor/gocv.io/x/gocv/video.cpp b/vendor/gocv.io/x/gocv/video.cpp new file mode 100644 index 00000000..6e9f17a0 --- /dev/null +++ b/vendor/gocv.io/x/gocv/video.cpp @@ -0,0 +1,209 @@ +#include "video.h" + +BackgroundSubtractorMOG2 BackgroundSubtractorMOG2_Create() { + return new cv::Ptr(cv::createBackgroundSubtractorMOG2()); +} + +BackgroundSubtractorMOG2 BackgroundSubtractorMOG2_CreateWithParams(int history, double varThreshold, bool detectShadows) { + return new cv::Ptr(cv::createBackgroundSubtractorMOG2(history,varThreshold,detectShadows)); +} + +BackgroundSubtractorKNN BackgroundSubtractorKNN_Create() { + return new cv::Ptr(cv::createBackgroundSubtractorKNN()); +} + +BackgroundSubtractorKNN BackgroundSubtractorKNN_CreateWithParams(int history, double dist2Threshold, bool detectShadows) { + return new cv::Ptr(cv::createBackgroundSubtractorKNN(history,dist2Threshold,detectShadows)); +} + +void BackgroundSubtractorMOG2_Close(BackgroundSubtractorMOG2 b) { + delete b; +} + +void BackgroundSubtractorMOG2_Apply(BackgroundSubtractorMOG2 b, Mat src, Mat dst) { + (*b)->apply(*src, *dst); +} + +void BackgroundSubtractorKNN_Close(BackgroundSubtractorKNN k) { + delete k; +} + +void BackgroundSubtractorKNN_Apply(BackgroundSubtractorKNN k, Mat src, Mat dst) { + (*k)->apply(*src, *dst); +} + +void CalcOpticalFlowFarneback(Mat prevImg, Mat nextImg, Mat flow, double scale, int levels, + int winsize, int iterations, int polyN, double polySigma, int flags) { + cv::calcOpticalFlowFarneback(*prevImg, *nextImg, *flow, scale, levels, winsize, iterations, polyN, + polySigma, flags); +} + +void CalcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, Mat prevPts, Mat nextPts, Mat status, Mat err) { + cv::calcOpticalFlowPyrLK(*prevImg, *nextImg, *prevPts, *nextPts, *status, *err); +} + +void CalcOpticalFlowPyrLKWithParams(Mat prevImg, Mat nextImg, Mat prevPts, Mat nextPts, Mat status, Mat err, Size winSize, int maxLevel, TermCriteria criteria, int flags, double minEigThreshold){ + cv::Size sz(winSize.width, winSize.height); + cv::calcOpticalFlowPyrLK(*prevImg, *nextImg, *prevPts, *nextPts, *status, *err, sz, maxLevel, *criteria, flags, minEigThreshold); +} + +double FindTransformECC(Mat templateImage, Mat inputImage, Mat warpMatrix, int motionType, TermCriteria criteria, Mat inputMask, int gaussFiltSize){ + return cv::findTransformECC(*templateImage, *inputImage, *warpMatrix, motionType, *criteria, *inputMask, gaussFiltSize); +} + +bool Tracker_Init(Tracker self, Mat image, Rect boundingBox) { + cv::Rect bb(boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height); + + (*self)->init(*image, bb); + return true; +} + +bool Tracker_Update(Tracker self, Mat image, Rect* boundingBox) { + cv::Rect bb; + bool ret = (*self)->update(*image, bb); + boundingBox->x = int(bb.x); + boundingBox->y = int(bb.y); + boundingBox->width = int(bb.width); + boundingBox->height = int(bb.height); + return ret; +} + +TrackerMIL TrackerMIL_Create() { + return new cv::Ptr(cv::TrackerMIL::create()); +} + +void TrackerMIL_Close(TrackerMIL self) { + delete self; +} + +KalmanFilter KalmanFilter_New(int dynamParams, int measureParams) { + return new cv::KalmanFilter(dynamParams, measureParams, 0, CV_32F); +} + +KalmanFilter KalmanFilter_NewWithParams(int dynamParams, int measureParams, int controlParams, int type) { + return new cv::KalmanFilter(dynamParams, measureParams, controlParams, type); +} + +void KalmanFilter_Init(KalmanFilter kf, int dynamParams, int measureParams) { + kf->init(dynamParams, measureParams, 0, CV_32F); +} + +void KalmanFilter_InitWithParams(KalmanFilter kf, int dynamParams, int measureParams, int controlParams, int type) { + kf->init(dynamParams, measureParams, controlParams, type); +} + +void KalmanFilter_Close(KalmanFilter kf) { + delete kf; +} + +Mat KalmanFilter_Predict(KalmanFilter kf) { + return new cv::Mat(kf->predict()); +} + +Mat KalmanFilter_PredictWithParams(KalmanFilter kf, Mat control) { + return new cv::Mat(kf->predict(*control)); +} + +Mat KalmanFilter_Correct(KalmanFilter kf, Mat measurement) { + return new cv::Mat(kf->correct(*measurement)); +} + +Mat KalmanFilter_GetStatePre(KalmanFilter kf) { + return new cv::Mat(kf->statePre); +} + +Mat KalmanFilter_GetStatePost(KalmanFilter kf) { + return new cv::Mat(kf->statePost); +} + +Mat KalmanFilter_GetTransitionMatrix(KalmanFilter kf) { + return new cv::Mat(kf->transitionMatrix); +} + +Mat KalmanFilter_GetControlMatrix(KalmanFilter kf) { + return new cv::Mat(kf->controlMatrix); +} + +Mat KalmanFilter_GetMeasurementMatrix(KalmanFilter kf) { + return new cv::Mat(kf->measurementMatrix); +} + +Mat KalmanFilter_GetProcessNoiseCov(KalmanFilter kf) { + return new cv::Mat(kf->processNoiseCov); +} + +Mat KalmanFilter_GetMeasurementNoiseCov(KalmanFilter kf) { + return new cv::Mat(kf->measurementNoiseCov); +} + +Mat KalmanFilter_GetErrorCovPre(KalmanFilter kf) { + return new cv::Mat(kf->errorCovPre); +} + +Mat KalmanFilter_GetGain(KalmanFilter kf) { + return new cv::Mat(kf->gain); +} + +Mat KalmanFilter_GetErrorCovPost(KalmanFilter kf) { + return new cv::Mat(kf->errorCovPost); +} + +Mat KalmanFilter_GetTemp1(KalmanFilter kf) { + return new cv::Mat(kf->temp1); +} + +Mat KalmanFilter_GetTemp2(KalmanFilter kf) { + return new cv::Mat(kf->temp2); +} + +Mat KalmanFilter_GetTemp3(KalmanFilter kf) { + return new cv::Mat(kf->temp3); +} + +Mat KalmanFilter_GetTemp4(KalmanFilter kf) { + return new cv::Mat(kf->temp4); +} + +Mat KalmanFilter_GetTemp5(KalmanFilter kf) { + return new cv::Mat(kf->temp5); +} + +void KalmanFilter_SetStatePre(KalmanFilter kf, Mat statePre) { + kf->statePre = *statePre; +} + +void KalmanFilter_SetStatePost(KalmanFilter kf, Mat statePost) { + kf->statePost = *statePost; +} + +void KalmanFilter_SetTransitionMatrix(KalmanFilter kf, Mat transitionMatrix) { + kf->transitionMatrix = *transitionMatrix; +} + +void KalmanFilter_SetControlMatrix(KalmanFilter kf, Mat controlMatrix) { + kf->controlMatrix = *controlMatrix; +} + +void KalmanFilter_SetMeasurementMatrix(KalmanFilter kf, Mat measurementMatrix) { + kf->measurementMatrix = *measurementMatrix; +} + +void KalmanFilter_SetProcessNoiseCov(KalmanFilter kf, Mat processNoiseCov) { + kf->processNoiseCov = *processNoiseCov; +} + +void KalmanFilter_SetMeasurementNoiseCov(KalmanFilter kf, Mat measurementNoiseCov) { + kf->measurementNoiseCov = *measurementNoiseCov; +} + +void KalmanFilter_SetErrorCovPre(KalmanFilter kf, Mat errorCovPre) { + kf->errorCovPre = *errorCovPre; +} + +void KalmanFilter_SetGain(KalmanFilter kf, Mat gain) { + kf->gain = *gain; +} + +void KalmanFilter_SetErrorCovPost(KalmanFilter kf, Mat errorCovPost) { + kf->errorCovPost = *errorCovPost; +} diff --git a/vendor/gocv.io/x/gocv/video.go b/vendor/gocv.io/x/gocv/video.go new file mode 100644 index 00000000..eae1efbb --- /dev/null +++ b/vendor/gocv.io/x/gocv/video.go @@ -0,0 +1,534 @@ +package gocv + +/* +#include +#include "video.h" +*/ +import "C" +import ( + "image" + "unsafe" +) + +/** + cv::OPTFLOW_USE_INITIAL_FLOW = 4, + cv::OPTFLOW_LK_GET_MIN_EIGENVALS = 8, + cv::OPTFLOW_FARNEBACK_GAUSSIAN = 256 + For further details, please see: https://docs.opencv.org/master/dc/d6b/group__video__track.html#gga2c6cc144c9eee043575d5b311ac8af08a9d4430ac75199af0cf6fcdefba30eafe +*/ +const ( + OptflowUseInitialFlow = 4 + OptflowLkGetMinEigenvals = 8 + OptflowFarnebackGaussian = 256 +) + +/** + cv::MOTION_TRANSLATION = 0, + cv::MOTION_EUCLIDEAN = 1, + cv::MOTION_AFFINE = 2, + cv::MOTION_HOMOGRAPHY = 3 + For further details, please see: https://docs.opencv.org/4.x/dc/d6b/group__video__track.html#ggaaedb1f94e6b143cef163622c531afd88a01106d6d20122b782ff25eaeffe9a5be +*/ +const ( + MotionTranslation = 0 + MotionEuclidean = 1 + MotionAffine = 2 + MotionHomography = 3 +) + +// BackgroundSubtractorMOG2 is a wrapper around the cv::BackgroundSubtractorMOG2. +type BackgroundSubtractorMOG2 struct { + // C.BackgroundSubtractorMOG2 + p unsafe.Pointer +} + +// NewBackgroundSubtractorMOG2 returns a new BackgroundSubtractor algorithm +// of type MOG2. MOG2 is a Gaussian Mixture-based Background/Foreground +// Segmentation Algorithm. +// +// For further details, please see: +// https://docs.opencv.org/master/de/de1/group__video__motion.html#ga2beb2dee7a073809ccec60f145b6b29c +// https://docs.opencv.org/master/d7/d7b/classcv_1_1BackgroundSubtractorMOG2.html +// +func NewBackgroundSubtractorMOG2() BackgroundSubtractorMOG2 { + return BackgroundSubtractorMOG2{p: unsafe.Pointer(C.BackgroundSubtractorMOG2_Create())} +} + +// NewBackgroundSubtractorMOG2WithParams returns a new BackgroundSubtractor algorithm +// of type MOG2 with customized parameters. MOG2 is a Gaussian Mixture-based Background/Foreground +// Segmentation Algorithm. +// +// For further details, please see: +// https://docs.opencv.org/master/de/de1/group__video__motion.html#ga2beb2dee7a073809ccec60f145b6b29c +// https://docs.opencv.org/master/d7/d7b/classcv_1_1BackgroundSubtractorMOG2.html +// +func NewBackgroundSubtractorMOG2WithParams(history int, varThreshold float64, detectShadows bool) BackgroundSubtractorMOG2 { + return BackgroundSubtractorMOG2{p: unsafe.Pointer(C.BackgroundSubtractorMOG2_CreateWithParams(C.int(history), C.double(varThreshold), C.bool(detectShadows)))} +} + +// Close BackgroundSubtractorMOG2. +func (b *BackgroundSubtractorMOG2) Close() error { + C.BackgroundSubtractorMOG2_Close((C.BackgroundSubtractorMOG2)(b.p)) + b.p = nil + return nil +} + +// Apply computes a foreground mask using the current BackgroundSubtractorMOG2. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/df6/classcv_1_1BackgroundSubtractor.html#aa735e76f7069b3fa9c3f32395f9ccd21 +// +func (b *BackgroundSubtractorMOG2) Apply(src Mat, dst *Mat) { + C.BackgroundSubtractorMOG2_Apply((C.BackgroundSubtractorMOG2)(b.p), src.p, dst.p) + return +} + +// BackgroundSubtractorKNN is a wrapper around the cv::BackgroundSubtractorKNN. +type BackgroundSubtractorKNN struct { + // C.BackgroundSubtractorKNN + p unsafe.Pointer +} + +// NewBackgroundSubtractorKNN returns a new BackgroundSubtractor algorithm +// of type KNN. K-Nearest Neighbors (KNN) uses a Background/Foreground +// Segmentation Algorithm +// +// For further details, please see: +// https://docs.opencv.org/master/de/de1/group__video__motion.html#gac9be925771f805b6fdb614ec2292006d +// https://docs.opencv.org/master/db/d88/classcv_1_1BackgroundSubtractorKNN.html +// +func NewBackgroundSubtractorKNN() BackgroundSubtractorKNN { + return BackgroundSubtractorKNN{p: unsafe.Pointer(C.BackgroundSubtractorKNN_Create())} +} + +// NewBackgroundSubtractorKNNWithParams returns a new BackgroundSubtractor algorithm +// of type KNN with customized parameters. K-Nearest Neighbors (KNN) uses a Background/Foreground +// Segmentation Algorithm +// +// For further details, please see: +// https://docs.opencv.org/master/de/de1/group__video__motion.html#gac9be925771f805b6fdb614ec2292006d +// https://docs.opencv.org/master/db/d88/classcv_1_1BackgroundSubtractorKNN.html +// +func NewBackgroundSubtractorKNNWithParams(history int, dist2Threshold float64, detectShadows bool) BackgroundSubtractorKNN { + return BackgroundSubtractorKNN{p: unsafe.Pointer(C.BackgroundSubtractorKNN_CreateWithParams(C.int(history), C.double(dist2Threshold), C.bool(detectShadows)))} +} + +// Close BackgroundSubtractorKNN. +func (k *BackgroundSubtractorKNN) Close() error { + C.BackgroundSubtractorKNN_Close((C.BackgroundSubtractorKNN)(k.p)) + k.p = nil + return nil +} + +// Apply computes a foreground mask using the current BackgroundSubtractorKNN. +// +// For further details, please see: +// https://docs.opencv.org/master/d7/df6/classcv_1_1BackgroundSubtractor.html#aa735e76f7069b3fa9c3f32395f9ccd21 +// +func (k *BackgroundSubtractorKNN) Apply(src Mat, dst *Mat) { + C.BackgroundSubtractorKNN_Apply((C.BackgroundSubtractorKNN)(k.p), src.p, dst.p) + return +} + +// CalcOpticalFlowFarneback computes a dense optical flow using +// Gunnar Farneback's algorithm. +// +// For further details, please see: +// https://docs.opencv.org/master/dc/d6b/group__video__track.html#ga5d10ebbd59fe09c5f650289ec0ece5af +// +func CalcOpticalFlowFarneback(prevImg Mat, nextImg Mat, flow *Mat, pyrScale float64, levels int, winsize int, + iterations int, polyN int, polySigma float64, flags int) { + C.CalcOpticalFlowFarneback(prevImg.p, nextImg.p, flow.p, C.double(pyrScale), C.int(levels), C.int(winsize), + C.int(iterations), C.int(polyN), C.double(polySigma), C.int(flags)) + return +} + +// CalcOpticalFlowPyrLK calculates an optical flow for a sparse feature set using +// the iterative Lucas-Kanade method with pyramids. +// +// For further details, please see: +// https://docs.opencv.org/master/dc/d6b/group__video__track.html#ga473e4b886d0bcc6b65831eb88ed93323 +// +func CalcOpticalFlowPyrLK(prevImg Mat, nextImg Mat, prevPts Mat, nextPts Mat, status *Mat, err *Mat) { + C.CalcOpticalFlowPyrLK(prevImg.p, nextImg.p, prevPts.p, nextPts.p, status.p, err.p) + return +} + +// CalcOpticalFlowPyrLKWithParams calculates an optical flow for a sparse feature set using +// the iterative Lucas-Kanade method with pyramids. +// +// For further details, please see: +// https://docs.opencv.org/master/dc/d6b/group__video__track.html#ga473e4b886d0bcc6b65831eb88ed93323 +// +func CalcOpticalFlowPyrLKWithParams(prevImg Mat, nextImg Mat, prevPts Mat, nextPts Mat, status *Mat, err *Mat, + winSize image.Point, maxLevel int, criteria TermCriteria, flags int, minEigThreshold float64) { + winSz := C.struct_Size{ + width: C.int(winSize.X), + height: C.int(winSize.Y), + } + C.CalcOpticalFlowPyrLKWithParams(prevImg.p, nextImg.p, prevPts.p, nextPts.p, status.p, err.p, winSz, C.int(maxLevel), criteria.p, C.int(flags), C.double(minEigThreshold)) + return +} + +// FindTransformECC finds the geometric transform (warp) between two images in terms of the ECC criterion. +// +// For futther details, please see: +// https://docs.opencv.org/4.x/dc/d6b/group__video__track.html#ga1aa357007eaec11e9ed03500ecbcbe47 +// +func FindTransformECC(templateImage Mat, inputImage Mat, warpMatrix *Mat, motionType int, criteria TermCriteria, inputMask Mat, gaussFiltSize int) float64 { + return float64(C.FindTransformECC(templateImage.p, inputImage.p, warpMatrix.p, C.int(motionType), criteria.p, inputMask.p, C.int(gaussFiltSize))) +} + +// Tracker is the base interface for object tracking. +// +// see: https://docs.opencv.org/master/d0/d0a/classcv_1_1Tracker.html +// +type Tracker interface { + // Close closes, as Trackers need to be Closed manually. + // + Close() error + + // Init initializes the tracker with a known bounding box that surrounded the target. + // Note: this can only be called once. If you lose the object, you have to Close() the instance, + // create a new one, and call Init() on it again. + // + // see: https://docs.opencv.org/master/d0/d0a/classcv_1_1Tracker.html#a4d285747589b1bdd16d2e4f00c3255dc + // + Init(image Mat, boundingBox image.Rectangle) bool + + // Update updates the tracker, returns a new bounding box and a boolean determining whether the tracker lost the target. + // + // see: https://docs.opencv.org/master/d0/d0a/classcv_1_1Tracker.html#a549159bd0553e6a8de356f3866df1f18 + // + Update(image Mat) (image.Rectangle, bool) +} + +func trackerInit(trk C.Tracker, img Mat, boundingBox image.Rectangle) bool { + cBox := C.struct_Rect{ + x: C.int(boundingBox.Min.X), + y: C.int(boundingBox.Min.Y), + width: C.int(boundingBox.Size().X), + height: C.int(boundingBox.Size().Y), + } + + ret := C.Tracker_Init(trk, C.Mat(img.Ptr()), cBox) + return bool(ret) +} + +func trackerUpdate(trk C.Tracker, img Mat) (image.Rectangle, bool) { + cBox := C.struct_Rect{} + + ret := C.Tracker_Update(trk, C.Mat(img.Ptr()), &cBox) + + rect := image.Rect(int(cBox.x), int(cBox.y), int(cBox.x+cBox.width), int(cBox.y+cBox.height)) + return rect, bool(ret) +} + +// TrackerMIL is a Tracker that uses the MIL algorithm. MIL trains a classifier in an online manner +// to separate the object from the background. +// Multiple Instance Learning avoids the drift problem for a robust tracking. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d26/classcv_1_1TrackerMIL.html +// +type TrackerMIL struct { + p C.TrackerMIL +} + +// NewTrackerMIL returns a new TrackerMIL. +func NewTrackerMIL() Tracker { + return TrackerMIL{p: C.TrackerMIL_Create()} +} + +// Close closes the TrackerMIL. +func (trk TrackerMIL) Close() error { + C.TrackerMIL_Close(trk.p) + trk.p = nil + return nil +} + +// Init initializes the TrackerMIL. +func (trk TrackerMIL) Init(img Mat, boundingBox image.Rectangle) bool { + return trackerInit(C.Tracker(trk.p), img, boundingBox) +} + +// Update updates the TrackerMIL. +func (trk TrackerMIL) Update(img Mat) (image.Rectangle, bool) { + return trackerUpdate(C.Tracker(trk.p), img) +} + +// KalmanFilter implements a standard Kalman filter http://en.wikipedia.org/wiki/Kalman_filter. +// However, you can modify transitionMatrix, controlMatrix, and measurementMatrix +// to get an extended Kalman filter functionality. +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html +// +type KalmanFilter struct { + p C.KalmanFilter +} + +// NewKalmanFilter returns a new KalmanFilter. +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#ac0799f0611baee9e7e558f016e4a7b40 +// +func NewKalmanFilter(dynamParams int, measureParams int) KalmanFilter { + return KalmanFilter{p: C.KalmanFilter_New(C.int(dynamParams), C.int(measureParams))} +} + +// NewKalmanFilterWithParams returns a new KalmanFilter. +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#abac82ecfa530611a163255bc7d91c088 +// +func NewKalmanFilterWithParams(dynamParams int, measureParams int, controlParams int, matType MatType) KalmanFilter { + return KalmanFilter{p: C.KalmanFilter_NewWithParams(C.int(dynamParams), C.int(measureParams), C.int(controlParams), C.int(matType))} +} + +// Init re-initializes the Kalman filter. The previous content is destroyed. +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#a4f136c39c016d3530c7c5801dd1ddb3b +// +func (kf *KalmanFilter) Init(dynamParams int, measureParams int) { + C.KalmanFilter_Init(kf.p, C.int(dynamParams), C.int(measureParams)) +} + +// Predict computes a predicted state. +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#aa710d2255566bec8d6ce608d103d4fa7 +// +func (kf *KalmanFilter) Predict() Mat { + return newMat(C.KalmanFilter_Predict(kf.p)) +} + +// PredictWithParams computes a predicted state. +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#aa710d2255566bec8d6ce608d103d4fa7 +// +func (kf *KalmanFilter) PredictWithParams(control Mat) Mat { + return newMat(C.KalmanFilter_PredictWithParams(kf.p, control.p)) +} + +// Correct the predicted state from the measurement. +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#a60eb7feb569222ad0657ef1875884b5e +// +func (kf *KalmanFilter) Correct(measurement Mat) Mat { + return newMat(C.KalmanFilter_Correct(kf.p, measurement.p)) +} + +// Close closes the kalman filter. +func (kf *KalmanFilter) Close() { + C.KalmanFilter_Close(kf.p) + kf.p = nil +} + +// GetStatePre returns the Kalman filter's statePre Mat. +// +// predicted state (x'(k)): x(k)=A*x(k-1)+B*u(k) +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#a60eb7feb569222ad0657ef1875884b5e +// +func (kf *KalmanFilter) GetStatePre() Mat { + return newMat(C.KalmanFilter_GetStatePre(kf.p)) +} + +// GetStatePost returns the Kalman filter's statePost Mat. +// +// corrected state (x(k)): x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#add8fb5ac9c04b4600b679698dcb0447d +// +func (kf *KalmanFilter) GetStatePost() Mat { + return newMat(C.KalmanFilter_GetStatePost(kf.p)) +} + +// GetTransitionMatrix returns the Kalman filter's transitionMatrix Mat. +// +// state transition matrix (A) +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#a0657173e411acbf40d2d3c6b46e03b19 +// +func (kf *KalmanFilter) GetTransitionMatrix() Mat { + return newMat(C.KalmanFilter_GetTransitionMatrix(kf.p)) +} + +// GetControlMatrix returns the Kalman filter's controlMatrix Mat. +// +// control matrix (B) (not used if there is no control) +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#a6486e7287114810636fb33953280ed52 +// +func (kf *KalmanFilter) GetControlMatrix() Mat { + return newMat(C.KalmanFilter_GetControlMatrix(kf.p)) +} + +// GetMeasurementMatrix returns the Kalman filter's measurementMatrix Mat. +// +// measurement matrix (H) +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#a0f60b78726d8eccf74a1f2479c2d1f97 +// +func (kf *KalmanFilter) GetMeasurementMatrix() Mat { + return newMat(C.KalmanFilter_GetMeasurementMatrix(kf.p)) +} + +// GetProcessNoiseCov returns the Kalman filter's processNoiseCov Mat. +// +// process noise covariance matrix (Q) +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#af19be9c0630d0f658bdbaea409a35cda +// +func (kf *KalmanFilter) GetProcessNoiseCov() Mat { + return newMat(C.KalmanFilter_GetProcessNoiseCov(kf.p)) +} + +// GetMeasurementNoiseCov returns the Kalman filter's measurementNoiseCov Mat. +// +// measurement noise covariance matrix (R) +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#a828d051035ba807966ad65edf288a08e +// +func (kf *KalmanFilter) GetMeasurementNoiseCov() Mat { + return newMat(C.KalmanFilter_GetMeasurementNoiseCov(kf.p)) +} + +// GetErrorCovPre returns the Kalman filter's errorCovPre Mat. +// +// priori error estimate covariance matrix (P'(k)): P'(k)=A*P(k-1)*At + Q)*/ +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#ae1bd3a86f10753d723e7174d570d9ac1 +// +func (kf *KalmanFilter) GetErrorCovPre() Mat { + return newMat(C.KalmanFilter_GetErrorCovPre(kf.p)) +} + +// GetGain returns the Kalman filter's gain Mat. +// +// Kalman gain matrix (K(k)): K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R) +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#a077d73eb075b00779dc009a9057c27c3 +// +func (kf *KalmanFilter) GetGain() Mat { + return newMat(C.KalmanFilter_GetGain(kf.p)) +} + +// GetErrorCovPost returns the Kalman filter's errorCovPost Mat. +// +// posteriori error estimate covariance matrix (P(k)): P(k)=(I-K(k)*H)*P'(k) +// +// For further details, please see: +//https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#a446d8e9a0105b0aa35cd66119c529803 +// +func (kf *KalmanFilter) GetErrorCovPost() Mat { + return newMat(C.KalmanFilter_GetErrorCovPost(kf.p)) +} + +// GetTemp1 returns the Kalman filter's temp1 Mat. +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#aa3d064a9194c2815dbe19c056b6dc763 +// +func (kf *KalmanFilter) GetTemp1() Mat { + return newMat(C.KalmanFilter_GetTemp1(kf.p)) +} + +// GetTemp2 returns the Kalman filter's temp2 Mat. +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#a14866bd506668eb0ed57b3974b3a1ee7 +// +func (kf *KalmanFilter) GetTemp2() Mat { + return newMat(C.KalmanFilter_GetTemp2(kf.p)) +} + +// GetTemp3 returns the Kalman filter's temp3 Mat. +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#afdbe36066a7d7f560aa02abe6be114d8 +// +func (kf *KalmanFilter) GetTemp3() Mat { + return newMat(C.KalmanFilter_GetTemp3(kf.p)) +} + +// GetTemp4 returns the Kalman filter's temp4 Mat. +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#a84342f2d9dec1e6389025ad229401809 +// +func (kf *KalmanFilter) GetTemp4() Mat { + return newMat(C.KalmanFilter_GetTemp4(kf.p)) +} + +// GetTemp5 returns the Kalman filter's temp5 Mat. +// +// For further details, please see: +// https://docs.opencv.org/4.6.0/dd/d6a/classcv_1_1KalmanFilter.html#a846c2a6222c6e5d8b1385dfbccc83ae0 +// +func (kf *KalmanFilter) GetTemp5() Mat { + return newMat(C.KalmanFilter_GetTemp5(kf.p)) +} + +// SetStatePre sets the Kalman filter's statePre Mat. +func (kf *KalmanFilter) SetStatePre(statePre Mat) { + C.KalmanFilter_SetStatePre(kf.p, statePre.p) +} + +// SetStatePost sets the Kalman filter's statePost Mat. +func (kf *KalmanFilter) SetStatePost(statePost Mat) { + C.KalmanFilter_SetStatePost(kf.p, statePost.p) +} + +// SetTransitionMatrix sets the Kalman filter's transitionMatrix Mat. +func (kf *KalmanFilter) SetTransitionMatrix(transitionMatrix Mat) { + C.KalmanFilter_SetTransitionMatrix(kf.p, transitionMatrix.p) +} + +// SetControlMatrix sets the Kalman filter's controlMatrix Mat. +func (kf *KalmanFilter) SetControlMatrix(controlMatrix Mat) { + C.KalmanFilter_SetControlMatrix(kf.p, controlMatrix.p) +} + +// SetMeasurementMatrix sets the Kalman filter's measurementMatrix Mat. +func (kf *KalmanFilter) SetMeasurementMatrix(measurementMatrix Mat) { + C.KalmanFilter_SetMeasurementMatrix(kf.p, measurementMatrix.p) +} + +// SetProcessNoiseCov sets the Kalman filter's processNoiseCov Mat. +func (kf *KalmanFilter) SetProcessNoiseCov(processNoiseCov Mat) { + C.KalmanFilter_SetProcessNoiseCov(kf.p, processNoiseCov.p) +} + +// SetMeasurementNoiseCov sets the Kalman filter's measurementNoiseCov Mat. +func (kf *KalmanFilter) SetMeasurementNoiseCov(measurementNoiseCov Mat) { + C.KalmanFilter_SetMeasurementNoiseCov(kf.p, measurementNoiseCov.p) +} + +// SetErrorCovPre sets the Kalman filter's errorCovPre Mat. +func (kf *KalmanFilter) SetErrorCovPre(errorCovPre Mat) { + C.KalmanFilter_SetErrorCovPre(kf.p, errorCovPre.p) +} + +// SetGain sets the Kalman filter's gain Mat. +func (kf *KalmanFilter) SetGain(gain Mat) { + C.KalmanFilter_SetGain(kf.p, gain.p) +} + +// SetErrorCovPost sets the Kalman filter's errorCovPost Mat. +func (kf *KalmanFilter) SetErrorCovPost(errorCovPost Mat) { + C.KalmanFilter_SetErrorCovPost(kf.p, errorCovPost.p) +} diff --git a/vendor/gocv.io/x/gocv/video.h b/vendor/gocv.io/x/gocv/video.h new file mode 100644 index 00000000..76cfddcc --- /dev/null +++ b/vendor/gocv.io/x/gocv/video.h @@ -0,0 +1,93 @@ +#ifndef _OPENCV3_VIDEO_H_ +#define _OPENCV3_VIDEO_H_ + +#ifdef __cplusplus +#include +#include +extern "C" { +#endif + +#include "core.h" + +#ifdef __cplusplus +typedef cv::Ptr* BackgroundSubtractorMOG2; +typedef cv::Ptr* BackgroundSubtractorKNN; +typedef cv::Ptr* Tracker; +typedef cv::Ptr* TrackerMIL; +typedef cv::Ptr* TrackerGOTURN; +typedef cv::KalmanFilter* KalmanFilter; +#else +typedef void* BackgroundSubtractorMOG2; +typedef void* BackgroundSubtractorKNN; +typedef void* Tracker; +typedef void* TrackerMIL; +typedef void* TrackerGOTURN; +typedef void* KalmanFilter; +#endif + +BackgroundSubtractorMOG2 BackgroundSubtractorMOG2_Create(); +BackgroundSubtractorMOG2 BackgroundSubtractorMOG2_CreateWithParams(int history, double varThreshold, bool detectShadows); +void BackgroundSubtractorMOG2_Close(BackgroundSubtractorMOG2 b); +void BackgroundSubtractorMOG2_Apply(BackgroundSubtractorMOG2 b, Mat src, Mat dst); + +BackgroundSubtractorKNN BackgroundSubtractorKNN_Create(); +BackgroundSubtractorKNN BackgroundSubtractorKNN_CreateWithParams(int history, double dist2Threshold, bool detectShadows); + +void BackgroundSubtractorKNN_Close(BackgroundSubtractorKNN b); +void BackgroundSubtractorKNN_Apply(BackgroundSubtractorKNN b, Mat src, Mat dst); + +void CalcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, Mat prevPts, Mat nextPts, Mat status, Mat err); +void CalcOpticalFlowPyrLKWithParams(Mat prevImg, Mat nextImg, Mat prevPts, Mat nextPts, Mat status, Mat err, Size winSize, int maxLevel, TermCriteria criteria, int flags, double minEigThreshold); +void CalcOpticalFlowFarneback(Mat prevImg, Mat nextImg, Mat flow, double pyrScale, int levels, + int winsize, int iterations, int polyN, double polySigma, int flags); + +double FindTransformECC(Mat templateImage, Mat inputImage, Mat warpMatrix, int motionType, TermCriteria criteria, Mat inputMask, int gaussFiltSize); + +bool Tracker_Init(Tracker self, Mat image, Rect boundingBox); +bool Tracker_Update(Tracker self, Mat image, Rect* boundingBox); + +TrackerMIL TrackerMIL_Create(); +void TrackerMIL_Close(TrackerMIL self); + +KalmanFilter KalmanFilter_New(int dynamParams, int measureParams); +KalmanFilter KalmanFilter_NewWithParams(int dynamParams, int measureParams, int controlParams, int type); +void KalmanFilter_Close(KalmanFilter kf); + +void KalmanFilter_Init(KalmanFilter kf, int dynamParams, int measureParams); +void KalmanFilter_InitWithParams(KalmanFilter kf, int dynamParams, int measureParams, int controlParams, int type); +Mat KalmanFilter_Predict(KalmanFilter kf); +Mat KalmanFilter_PredictWithParams(KalmanFilter kf, Mat control); +Mat KalmanFilter_Correct(KalmanFilter kf, Mat measurement); + +Mat KalmanFilter_GetStatePre(KalmanFilter kf); +Mat KalmanFilter_GetStatePost(KalmanFilter kf); +Mat KalmanFilter_GetTransitionMatrix(KalmanFilter kf); +Mat KalmanFilter_GetControlMatrix(KalmanFilter kf); +Mat KalmanFilter_GetMeasurementMatrix(KalmanFilter kf); +Mat KalmanFilter_GetProcessNoiseCov(KalmanFilter kf); +Mat KalmanFilter_GetMeasurementNoiseCov(KalmanFilter kf); +Mat KalmanFilter_GetErrorCovPre(KalmanFilter kf); +Mat KalmanFilter_GetGain(KalmanFilter kf); +Mat KalmanFilter_GetErrorCovPost(KalmanFilter kf); +Mat KalmanFilter_GetTemp1(KalmanFilter kf); +Mat KalmanFilter_GetTemp2(KalmanFilter kf); +Mat KalmanFilter_GetTemp3(KalmanFilter kf); +Mat KalmanFilter_GetTemp4(KalmanFilter kf); +Mat KalmanFilter_GetTemp5(KalmanFilter kf); + +void KalmanFilter_SetStatePre(KalmanFilter kf, Mat statePre); +void KalmanFilter_SetStatePost(KalmanFilter kf, Mat statePost); +void KalmanFilter_SetTransitionMatrix(KalmanFilter kf, Mat transitionMatrix); +void KalmanFilter_SetControlMatrix(KalmanFilter kf, Mat controlMatrix); +void KalmanFilter_SetMeasurementMatrix(KalmanFilter kf, Mat measurementMatrix); +void KalmanFilter_SetProcessNoiseCov(KalmanFilter kf, Mat processNoiseCov); +void KalmanFilter_SetMeasurementNoiseCov(KalmanFilter kf, Mat measurementNoiseCov); +void KalmanFilter_SetErrorCovPre(KalmanFilter kf, Mat errorCovPre); +void KalmanFilter_SetGain(KalmanFilter kf, Mat gain); +void KalmanFilter_SetErrorCovPost(KalmanFilter kf, Mat errorCovPost); + +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_VIDEO_H_ diff --git a/vendor/gocv.io/x/gocv/videoio.cpp b/vendor/gocv.io/x/gocv/videoio.cpp new file mode 100644 index 00000000..31d9e035 --- /dev/null +++ b/vendor/gocv.io/x/gocv/videoio.cpp @@ -0,0 +1,71 @@ +#include "videoio.h" + +// VideoWriter +VideoCapture VideoCapture_New() { + return new cv::VideoCapture(); +} + +void VideoCapture_Close(VideoCapture v) { + delete v; +} + +bool VideoCapture_Open(VideoCapture v, const char* uri) { + return v->open(uri); +} + +bool VideoCapture_OpenWithAPI(VideoCapture v, const char* uri, int apiPreference) { + return v->open(uri, apiPreference); +} + +bool VideoCapture_OpenDevice(VideoCapture v, int device) { + return v->open(device); +} + +bool VideoCapture_OpenDeviceWithAPI(VideoCapture v, int device, int apiPreference) { + return v->open(device, apiPreference); +} + +void VideoCapture_Set(VideoCapture v, int prop, double param) { + v->set(prop, param); +} + +double VideoCapture_Get(VideoCapture v, int prop) { + return v->get(prop); +} + +int VideoCapture_IsOpened(VideoCapture v) { + return v->isOpened(); +} + +int VideoCapture_Read(VideoCapture v, Mat buf) { + return v->read(*buf); +} + +void VideoCapture_Grab(VideoCapture v, int skip) { + for (int i = 0; i < skip; i++) { + v->grab(); + } +} + +// VideoWriter +VideoWriter VideoWriter_New() { + return new cv::VideoWriter(); +} + +void VideoWriter_Close(VideoWriter vw) { + delete vw; +} + +void VideoWriter_Open(VideoWriter vw, const char* name, const char* codec, double fps, int width, + int height, bool isColor) { + int codecCode = cv::VideoWriter::fourcc(codec[0], codec[1], codec[2], codec[3]); + vw->open(name, codecCode, fps, cv::Size(width, height), isColor); +} + +int VideoWriter_IsOpened(VideoWriter vw) { + return vw->isOpened(); +} + +void VideoWriter_Write(VideoWriter vw, Mat img) { + *vw << *img; +} diff --git a/vendor/gocv.io/x/gocv/videoio.go b/vendor/gocv.io/x/gocv/videoio.go new file mode 100644 index 00000000..2258961e --- /dev/null +++ b/vendor/gocv.io/x/gocv/videoio.go @@ -0,0 +1,504 @@ +package gocv + +/* +#include +#include "videoio.h" +*/ +import "C" +import ( + "errors" + "fmt" + "strconv" + "sync" + "unsafe" +) + +// Select preferred API for a capture object. +// Note: Backends are available only if they have been built with your OpenCV binaries +type VideoCaptureAPI int + +const ( + // Auto detect == 0 + VideoCaptureAny VideoCaptureAPI = 0 + + // Video For Windows (obsolete, removed) + VideoCaptureVFW VideoCaptureAPI = 200 + + // V4L/V4L2 capturing support + VideoCaptureV4L VideoCaptureAPI = 200 + + // Same as VideoCaptureV4L + VideoCaptureV4L2 VideoCaptureAPI = 200 + + // IEEE 1394 drivers + VideoCaptureFirewire VideoCaptureAPI = 300 + + // Same value as VideoCaptureFirewire + VideoCaptureFireware VideoCaptureAPI = 300 + + // Same value as VideoCaptureFirewire + VideoCaptureIEEE1394 VideoCaptureAPI = 300 + + // Same value as VideoCaptureFirewire + VideoCaptureDC1394 VideoCaptureAPI = 300 + + // Same value as VideoCaptureFirewire + VideoCaptureCMU1394 VideoCaptureAPI = 300 + + // QuickTime (obsolete, removed) + VideoCaptureQT VideoCaptureAPI = 500 + + // Unicap drivers (obsolete, removed) + VideoCaptureUnicap VideoCaptureAPI = 600 + + // DirectShow (via videoInput) + VideoCaptureDshow VideoCaptureAPI = 700 + + // PvAPI, Prosilica GigE SDK + VideoCapturePvAPI VideoCaptureAPI = 800 + + // OpenNI (for Kinect) + VideoCaptureOpenNI VideoCaptureAPI = 900 + + // OpenNI (for Asus Xtion) + VideoCaptureOpenNIAsus VideoCaptureAPI = 910 + + // Android - not used + VideoCaptureAndroid VideoCaptureAPI = 1000 + + // XIMEA Camera API + VideoCaptureXiAPI VideoCaptureAPI = 1100 + + // AVFoundation framework for iOS (OS X Lion will have the same API) + VideoCaptureAVFoundation VideoCaptureAPI = 1200 + + // Smartek Giganetix GigEVisionSDK + VideoCaptureGiganetix VideoCaptureAPI = 1300 + + // Microsoft Media Foundation (via videoInput) + VideoCaptureMSMF VideoCaptureAPI = 1400 + + // Microsoft Windows Runtime using Media Foundation + VideoCaptureWinRT VideoCaptureAPI = 1410 + + // RealSense (former Intel Perceptual Computing SDK) + VideoCaptureIntelPerc VideoCaptureAPI = 1500 + + // Synonym for VideoCaptureIntelPerc + VideoCaptureRealsense VideoCaptureAPI = 1500 + + // OpenNI2 (for Kinect) + VideoCaptureOpenNI2 VideoCaptureAPI = 1600 + + // OpenNI2 (for Asus Xtion and Occipital Structure sensors) + VideoCaptureOpenNI2Asus VideoCaptureAPI = 1610 + + // gPhoto2 connection + VideoCaptureGPhoto2 VideoCaptureAPI = 1700 + + // GStreamer + VideoCaptureGstreamer VideoCaptureAPI = 1800 + + // Open and record video file or stream using the FFMPEG library + VideoCaptureFFmpeg VideoCaptureAPI = 1900 + + // OpenCV Image Sequence (e.g. img_%02d.jpg) + VideoCaptureImages VideoCaptureAPI = 2000 + + // Aravis SDK + VideoCaptureAravis VideoCaptureAPI = 2100 + + // Built-in OpenCV MotionJPEG codec + VideoCaptureOpencvMjpeg VideoCaptureAPI = 2200 + + // Intel MediaSDK + VideoCaptureIntelMFX VideoCaptureAPI = 2300 + + // XINE engine (Linux) + VideoCaptureXINE VideoCaptureAPI = 2400 +) + +// VideoCaptureProperties are the properties used for VideoCapture operations. +type VideoCaptureProperties int + +const ( + // VideoCapturePosMsec contains current position of the + // video file in milliseconds. + VideoCapturePosMsec VideoCaptureProperties = 0 + + // VideoCapturePosFrames 0-based index of the frame to be + // decoded/captured next. + VideoCapturePosFrames VideoCaptureProperties = 1 + + // VideoCapturePosAVIRatio relative position of the video file: + // 0=start of the film, 1=end of the film. + VideoCapturePosAVIRatio VideoCaptureProperties = 2 + + // VideoCaptureFrameWidth is width of the frames in the video stream. + VideoCaptureFrameWidth VideoCaptureProperties = 3 + + // VideoCaptureFrameHeight controls height of frames in the video stream. + VideoCaptureFrameHeight VideoCaptureProperties = 4 + + // VideoCaptureFPS controls capture frame rate. + VideoCaptureFPS VideoCaptureProperties = 5 + + // VideoCaptureFOURCC contains the 4-character code of codec. + // see VideoWriter::fourcc for details. + VideoCaptureFOURCC VideoCaptureProperties = 6 + + // VideoCaptureFrameCount contains number of frames in the video file. + VideoCaptureFrameCount VideoCaptureProperties = 7 + + // VideoCaptureFormat format of the Mat objects returned by + // VideoCapture::retrieve(). + VideoCaptureFormat VideoCaptureProperties = 8 + + // VideoCaptureMode contains backend-specific value indicating + // the current capture mode. + VideoCaptureMode VideoCaptureProperties = 9 + + // VideoCaptureBrightness is brightness of the image + // (only for those cameras that support). + VideoCaptureBrightness VideoCaptureProperties = 10 + + // VideoCaptureContrast is contrast of the image + // (only for cameras that support it). + VideoCaptureContrast VideoCaptureProperties = 11 + + // VideoCaptureSaturation saturation of the image + // (only for cameras that support). + VideoCaptureSaturation VideoCaptureProperties = 12 + + // VideoCaptureHue hue of the image (only for cameras that support). + VideoCaptureHue VideoCaptureProperties = 13 + + // VideoCaptureGain is the gain of the capture image. + // (only for those cameras that support). + VideoCaptureGain VideoCaptureProperties = 14 + + // VideoCaptureExposure is the exposure of the capture image. + // (only for those cameras that support). + VideoCaptureExposure VideoCaptureProperties = 15 + + // VideoCaptureConvertRGB is a boolean flags indicating whether + // images should be converted to RGB. + VideoCaptureConvertRGB VideoCaptureProperties = 16 + + // VideoCaptureWhiteBalanceBlueU is currently unsupported. + VideoCaptureWhiteBalanceBlueU VideoCaptureProperties = 17 + + // VideoCaptureRectification is the rectification flag for stereo cameras. + // Note: only supported by DC1394 v 2.x backend currently. + VideoCaptureRectification VideoCaptureProperties = 18 + + // VideoCaptureMonochrome indicates whether images should be + // converted to monochrome. + VideoCaptureMonochrome VideoCaptureProperties = 19 + + // VideoCaptureSharpness controls image capture sharpness. + VideoCaptureSharpness VideoCaptureProperties = 20 + + // VideoCaptureAutoExposure controls the DC1394 exposure control + // done by camera, user can adjust reference level using this feature. + VideoCaptureAutoExposure VideoCaptureProperties = 21 + + // VideoCaptureGamma controls video capture gamma. + VideoCaptureGamma VideoCaptureProperties = 22 + + // VideoCaptureTemperature controls video capture temperature. + VideoCaptureTemperature VideoCaptureProperties = 23 + + // VideoCaptureTrigger controls video capture trigger. + VideoCaptureTrigger VideoCaptureProperties = 24 + + // VideoCaptureTriggerDelay controls video capture trigger delay. + VideoCaptureTriggerDelay VideoCaptureProperties = 25 + + // VideoCaptureWhiteBalanceRedV controls video capture setting for + // white balance. + VideoCaptureWhiteBalanceRedV VideoCaptureProperties = 26 + + // VideoCaptureZoom controls video capture zoom. + VideoCaptureZoom VideoCaptureProperties = 27 + + // VideoCaptureFocus controls video capture focus. + VideoCaptureFocus VideoCaptureProperties = 28 + + // VideoCaptureGUID controls video capture GUID. + VideoCaptureGUID VideoCaptureProperties = 29 + + // VideoCaptureISOSpeed controls video capture ISO speed. + VideoCaptureISOSpeed VideoCaptureProperties = 30 + + // VideoCaptureBacklight controls video capture backlight. + VideoCaptureBacklight VideoCaptureProperties = 32 + + // VideoCapturePan controls video capture pan. + VideoCapturePan VideoCaptureProperties = 33 + + // VideoCaptureTilt controls video capture tilt. + VideoCaptureTilt VideoCaptureProperties = 34 + + // VideoCaptureRoll controls video capture roll. + VideoCaptureRoll VideoCaptureProperties = 35 + + // VideoCaptureIris controls video capture iris. + VideoCaptureIris VideoCaptureProperties = 36 + + // VideoCaptureSettings is the pop up video/camera filter dialog. Note: + // only supported by DSHOW backend currently. The property value is ignored. + VideoCaptureSettings VideoCaptureProperties = 37 + + // VideoCaptureBufferSize controls video capture buffer size. + VideoCaptureBufferSize VideoCaptureProperties = 38 + + // VideoCaptureAutoFocus controls video capture auto focus.. + VideoCaptureAutoFocus VideoCaptureProperties = 39 + + // VideoCaptureSarNumerator controls the sample aspect ratio: num/den (num) + VideoCaptureSarNumerator VideoCaptureProperties = 40 + + // VideoCaptureSarDenominator controls the sample aspect ratio: num/den (den) + VideoCaptureSarDenominator VideoCaptureProperties = 41 + + // VideoCaptureBackend is the current api backend (VideoCaptureAPI). Read-only property. + VideoCaptureBackend VideoCaptureProperties = 42 + + // VideoCaptureChannel controls the video input or channel number (only for those cameras that support). + VideoCaptureChannel VideoCaptureProperties = 43 + + // VideoCaptureAutoWB controls the auto white-balance. + VideoCaptureAutoWB VideoCaptureProperties = 44 + + // VideoCaptureWBTemperature controls the white-balance color temperature + VideoCaptureWBTemperature VideoCaptureProperties = 45 + + // VideoCaptureCodecPixelFormat shows the the codec's pixel format (4-character code). Read-only property. + // Subset of AV_PIX_FMT_* or -1 if unknown. + VideoCaptureCodecPixelFormat VideoCaptureProperties = 46 + + // VideoCaptureBitrate displays the video bitrate in kbits/s. Read-only property. + VideoCaptureBitrate VideoCaptureProperties = 47 +) + +// VideoCapture is a wrapper around the OpenCV VideoCapture class. +// +// For further details, please see: +// http://docs.opencv.org/master/d8/dfe/classcv_1_1VideoCapture.html +// +type VideoCapture struct { + p C.VideoCapture +} + +// VideoCaptureFile opens a VideoCapture from a file and prepares +// to start capturing. It returns error if it fails to open the file stored in uri path. +func VideoCaptureFile(uri string) (vc *VideoCapture, err error) { + vc = &VideoCapture{p: C.VideoCapture_New()} + + cURI := C.CString(uri) + defer C.free(unsafe.Pointer(cURI)) + + if !C.VideoCapture_Open(vc.p, cURI) { + err = fmt.Errorf("Error opening file: %s", uri) + } + + return +} + +// VideoCaptureFile opens a VideoCapture from a file and prepares +// to start capturing. It returns error if it fails to open the file stored in uri path. +func VideoCaptureFileWithAPI(uri string, apiPreference VideoCaptureAPI) (vc *VideoCapture, err error) { + vc = &VideoCapture{p: C.VideoCapture_New()} + + cURI := C.CString(uri) + defer C.free(unsafe.Pointer(cURI)) + + if !C.VideoCapture_OpenWithAPI(vc.p, cURI, C.int(apiPreference)) { + err = fmt.Errorf("Error opening file: %s with api backend: %d", uri, apiPreference) + } + + return +} + +// VideoCaptureDevice opens a VideoCapture from a device and prepares +// to start capturing. It returns error if it fails to open the video device. +func VideoCaptureDevice(device int) (vc *VideoCapture, err error) { + vc = &VideoCapture{p: C.VideoCapture_New()} + + if !C.VideoCapture_OpenDevice(vc.p, C.int(device)) { + err = fmt.Errorf("Error opening device: %d", device) + } + + return +} + +// VideoCaptureDevice opens a VideoCapture from a device with the api preference. +// It returns error if it fails to open the video device. +func VideoCaptureDeviceWithAPI(device int, apiPreference VideoCaptureAPI) (vc *VideoCapture, err error) { + vc = &VideoCapture{p: C.VideoCapture_New()} + + if !C.VideoCapture_OpenDeviceWithAPI(vc.p, C.int(device), C.int(apiPreference)) { + err = fmt.Errorf("Error opening device: %d with api backend: %d", device, apiPreference) + } + + return +} + +// Close VideoCapture object. +func (v *VideoCapture) Close() error { + C.VideoCapture_Close(v.p) + v.p = nil + return nil +} + +// Set parameter with property (=key). +func (v *VideoCapture) Set(prop VideoCaptureProperties, param float64) { + C.VideoCapture_Set(v.p, C.int(prop), C.double(param)) +} + +// Get parameter with property (=key). +func (v VideoCapture) Get(prop VideoCaptureProperties) float64 { + return float64(C.VideoCapture_Get(v.p, C.int(prop))) +} + +// IsOpened returns if the VideoCapture has been opened to read from +// a file or capture device. +func (v *VideoCapture) IsOpened() bool { + isOpened := C.VideoCapture_IsOpened(v.p) + return isOpened != 0 +} + +// Read reads the next frame from the VideoCapture to the Mat passed in +// as the param. It returns false if the VideoCapture cannot read frame. +func (v *VideoCapture) Read(m *Mat) bool { + return C.VideoCapture_Read(v.p, m.p) != 0 +} + +// Grab skips a specific number of frames. +func (v *VideoCapture) Grab(skip int) { + C.VideoCapture_Grab(v.p, C.int(skip)) +} + +// CodecString returns a string representation of FourCC bytes, i.e. the name of a codec +func (v *VideoCapture) CodecString() string { + res := "" + hexes := []int64{0xff, 0xff00, 0xff0000, 0xff000000} + for i, h := range hexes { + res += string(rune(int64(v.Get(VideoCaptureFOURCC)) & h >> (uint(i * 8)))) + } + return res +} + +// ToCodec returns an float64 representation of FourCC bytes +func (v *VideoCapture) ToCodec(codec string) float64 { + if len(codec) != 4 { + return -1.0 + } + c1 := []rune(string(codec[0]))[0] + c2 := []rune(string(codec[1]))[0] + c3 := []rune(string(codec[2]))[0] + c4 := []rune(string(codec[3]))[0] + return float64((c1 & 255) + ((c2 & 255) << 8) + ((c3 & 255) << 16) + ((c4 & 255) << 24)) +} + +// VideoWriter is a wrapper around the OpenCV VideoWriter`class. +// +// For further details, please see: +// http://docs.opencv.org/master/dd/d9e/classcv_1_1VideoWriter.html +// +type VideoWriter struct { + mu *sync.RWMutex + p C.VideoWriter +} + +// VideoWriterFile opens a VideoWriter with a specific output file. +// The "codec" param should be the four-letter code for the desired output +// codec, for example "MJPG". +// +// For further details, please see: +// http://docs.opencv.org/master/dd/d9e/classcv_1_1VideoWriter.html#a0901c353cd5ea05bba455317dab81130 +// +func VideoWriterFile(name string, codec string, fps float64, width int, height int, isColor bool) (vw *VideoWriter, err error) { + + if fps == 0 || width == 0 || height == 0 { + return nil, fmt.Errorf("one of the numerical parameters "+ + "is equal to zero: FPS: %f, width: %d, height: %d", fps, width, height) + } + + vw = &VideoWriter{ + p: C.VideoWriter_New(), + mu: &sync.RWMutex{}, + } + + cName := C.CString(name) + defer C.free(unsafe.Pointer(cName)) + + cCodec := C.CString(codec) + defer C.free(unsafe.Pointer(cCodec)) + + C.VideoWriter_Open(vw.p, cName, cCodec, C.double(fps), C.int(width), C.int(height), C.bool(isColor)) + return +} + +// Close VideoWriter object. +func (vw *VideoWriter) Close() error { + C.VideoWriter_Close(vw.p) + vw.p = nil + return nil +} + +// IsOpened checks if the VideoWriter is open and ready to be written to. +// +// For further details, please see: +// http://docs.opencv.org/master/dd/d9e/classcv_1_1VideoWriter.html#a9a40803e5f671968ac9efa877c984d75 +// +func (vw *VideoWriter) IsOpened() bool { + isOpend := C.VideoWriter_IsOpened(vw.p) + return isOpend != 0 +} + +// Write the next video frame from the Mat image to the open VideoWriter. +// +// For further details, please see: +// http://docs.opencv.org/master/dd/d9e/classcv_1_1VideoWriter.html#a3115b679d612a6a0b5864a0c88ed4b39 +// +func (vw *VideoWriter) Write(img Mat) error { + vw.mu.Lock() + defer vw.mu.Unlock() + C.VideoWriter_Write(vw.p, img.p) + return nil +} + +// OpenVideoCapture return VideoCapture specified by device ID if v is a +// number. Return VideoCapture created from video file, URL, or GStreamer +// pipeline if v is a string. +func OpenVideoCapture(v interface{}) (*VideoCapture, error) { + switch vv := v.(type) { + case int: + return VideoCaptureDevice(vv) + case string: + id, err := strconv.Atoi(vv) + if err == nil { + return VideoCaptureDevice(id) + } + return VideoCaptureFile(vv) + default: + return nil, errors.New("argument must be int or string") + } +} + +func OpenVideoCaptureWithAPI(v interface{}, apiPreference VideoCaptureAPI) (*VideoCapture, error) { + switch vv := v.(type) { + case int: + return VideoCaptureDeviceWithAPI(vv, apiPreference) + case string: + id, err := strconv.Atoi(vv) + if err == nil { + return VideoCaptureDeviceWithAPI(id, apiPreference) + } + return VideoCaptureFileWithAPI(vv, apiPreference) + default: + return nil, errors.New("argument must be int or string") + } +} diff --git a/vendor/gocv.io/x/gocv/videoio.h b/vendor/gocv.io/x/gocv/videoio.h new file mode 100644 index 00000000..7993d803 --- /dev/null +++ b/vendor/gocv.io/x/gocv/videoio.h @@ -0,0 +1,44 @@ +#ifndef _OPENCV3_VIDEOIO_H_ +#define _OPENCV3_VIDEOIO_H_ + +#ifdef __cplusplus +#include +extern "C" { +#endif + +#include "core.h" + +#ifdef __cplusplus +typedef cv::VideoCapture* VideoCapture; +typedef cv::VideoWriter* VideoWriter; +#else +typedef void* VideoCapture; +typedef void* VideoWriter; +#endif + +// VideoCapture +VideoCapture VideoCapture_New(); +void VideoCapture_Close(VideoCapture v); +bool VideoCapture_Open(VideoCapture v, const char* uri); +bool VideoCapture_OpenWithAPI(VideoCapture v, const char* uri, int apiPreference); +bool VideoCapture_OpenDevice(VideoCapture v, int device); +bool VideoCapture_OpenDeviceWithAPI(VideoCapture v, int device, int apiPreference); +void VideoCapture_Set(VideoCapture v, int prop, double param); +double VideoCapture_Get(VideoCapture v, int prop); +int VideoCapture_IsOpened(VideoCapture v); +int VideoCapture_Read(VideoCapture v, Mat buf); +void VideoCapture_Grab(VideoCapture v, int skip); + +// VideoWriter +VideoWriter VideoWriter_New(); +void VideoWriter_Close(VideoWriter vw); +void VideoWriter_Open(VideoWriter vw, const char* name, const char* codec, double fps, int width, + int height, bool isColor); +int VideoWriter_IsOpened(VideoWriter vw); +void VideoWriter_Write(VideoWriter vw, Mat img); + +#ifdef __cplusplus +} +#endif + +#endif //_OPENCV3_VIDEOIO_H_ diff --git a/vendor/gocv.io/x/gocv/videoio_string.go b/vendor/gocv.io/x/gocv/videoio_string.go new file mode 100644 index 00000000..6d67d8cf --- /dev/null +++ b/vendor/gocv.io/x/gocv/videoio_string.go @@ -0,0 +1,159 @@ +package gocv + +func (c VideoCaptureAPI) String() string { + switch c { + case VideoCaptureAny: + return "video-capture-any" + case VideoCaptureV4L2: + return "video-capture-v4l2" + case VideoCaptureFirewire: + return "video-capture-firewire" + case VideoCaptureQT: + return "video-capture-qt" + case VideoCaptureUnicap: + return "video-capture-unicap" + case VideoCaptureDshow: + return "video-capture-dshow" + case VideoCapturePvAPI: + return "video-capture-pvapi" + case VideoCaptureOpenNI: + return "video-capture-openni" + case VideoCaptureOpenNIAsus: + return "video-capture-openni-asus" + case VideoCaptureAndroid: + return "video-capture-android" + case VideoCaptureXiAPI: + return "video-capture-xiapi" + case VideoCaptureAVFoundation: + return "video-capture-av-foundation" + case VideoCaptureGiganetix: + return "video-capture-giganetix" + case VideoCaptureMSMF: + return "video-capture-msmf" + case VideoCaptureWinRT: + return "video-capture-winrt" + case VideoCaptureIntelPerc: + return "video-capture-intel-perc" + case VideoCaptureOpenNI2: + return "video-capture-openni2" + case VideoCaptureOpenNI2Asus: + return "video-capture-openni2-asus" + case VideoCaptureGPhoto2: + return "video-capture-gphoto2" + case VideoCaptureGstreamer: + return "video-capture-gstreamer" + case VideoCaptureFFmpeg: + return "video-capture-ffmpeg" + case VideoCaptureImages: + return "video-capture-images" + case VideoCaptureAravis: + return "video-capture-aravis" + case VideoCaptureOpencvMjpeg: + return "video-capture-opencv-mjpeg" + case VideoCaptureIntelMFX: + return "video-capture-intel-mfx" + case VideoCaptureXINE: + return "video-capture-xine" + } + return "" +} + +func (c VideoCaptureProperties) String() string { + switch c { + case VideoCapturePosMsec: + return "video-capture-pos-msec" + case VideoCapturePosFrames: + return "video-capture-pos-frames" + case VideoCapturePosAVIRatio: + return "video-capture-pos-avi-ratio" + case VideoCaptureFrameWidth: + return "video-capture-frame-width" + case VideoCaptureFrameHeight: + return "video-capture-frame-height" + case VideoCaptureFPS: + return "video-capture-fps" + case VideoCaptureFOURCC: + return "video-capture-fourcc" + case VideoCaptureFrameCount: + return "video-capture-frame-count" + case VideoCaptureFormat: + return "video-capture-format" + case VideoCaptureMode: + return "video-capture-mode" + case VideoCaptureBrightness: + return "video-capture-brightness" + case VideoCaptureContrast: + return "video-capture-contrast" + case VideoCaptureSaturation: + return "video-capture-saturation" + case VideoCaptureHue: + return "video-capture-hue" + case VideoCaptureGain: + return "video-capture-gain" + case VideoCaptureExposure: + return "video-capture-exposure" + case VideoCaptureConvertRGB: + return "video-capture-convert-rgb" + case VideoCaptureWhiteBalanceBlueU: + return "video-capture-white-balanced-blue-u" + case VideoCaptureWhiteBalanceRedV: + return "video-capture-white-balanced-red-v" + case VideoCaptureRectification: + return "video-capture-rectification" + case VideoCaptureMonochrome: + return "video-capture-monochrome" + case VideoCaptureSharpness: + return "video-capture-sharpness" + case VideoCaptureAutoExposure: + return "video-capture-auto-exposure" + case VideoCaptureGamma: + return "video-capture-gamma" + case VideoCaptureTemperature: + return "video-capture-temperature" + case VideoCaptureTrigger: + return "video-capture-trigger" + case VideoCaptureTriggerDelay: + return "video-capture-trigger-delay" + case VideoCaptureZoom: + return "video-capture-zoom" + case VideoCaptureFocus: + return "video-capture-focus" + case VideoCaptureGUID: + return "video-capture-guid" + case VideoCaptureISOSpeed: + return "video-capture-iso-speed" + case VideoCaptureBacklight: + return "video-capture-backlight" + case VideoCapturePan: + return "video-capture-pan" + case VideoCaptureTilt: + return "video-capture-tilt" + case VideoCaptureRoll: + return "video-capture-roll" + case VideoCaptureIris: + return "video-capture-iris" + case VideoCaptureSettings: + return "video-capture-settings" + case VideoCaptureBufferSize: + return "video-capture-buffer-size" + case VideoCaptureAutoFocus: + return "video-capture-auto-focus" + case VideoCaptureSarNumerator: + return "video-capture-sar-numerator" + case VideoCaptureSarDenominator: + return "video-capture-sar-denominator" + case VideoCaptureBackend: + return "video-capture-backend" + case VideoCaptureChannel: + return "video-capture-channel" + case VideoCaptureAutoWB: + return "video-capture-auto-wb" + case VideoCaptureWBTemperature: + return "video-capture-wb-temperature" + case VideoCaptureCodecPixelFormat: + return "video-capture-pixel-format" + case VideoCaptureBitrate: + return "video-capture-bitrate" + } + return "" +} diff --git a/vendor/gocv.io/x/gocv/win_build_opencv.cmd b/vendor/gocv.io/x/gocv/win_build_opencv.cmd new file mode 100644 index 00000000..802a3c30 --- /dev/null +++ b/vendor/gocv.io/x/gocv/win_build_opencv.cmd @@ -0,0 +1,46 @@ +@echo off + +if not exist "C:\opencv" mkdir "C:\opencv" +if not exist "C:\opencv\build" mkdir "C:\opencv\build" + +echo Downloading OpenCV sources +echo. +echo For monitoring the download progress please check the C:\opencv directory. +echo. + +REM This is why there is no progress bar: +REM https://github.com/PowerShell/PowerShell/issues/2138 + +echo Downloading: opencv-4.7.0.zip [91MB] +powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri https://github.com/opencv/opencv/archive/4.7.0.zip -OutFile c:\opencv\opencv-4.7.0.zip" +echo Extracting... +powershell -command "$ProgressPreference = 'SilentlyContinue'; Expand-Archive -Path c:\opencv\opencv-4.7.0.zip -DestinationPath c:\opencv" +del c:\opencv\opencv-4.7.0.zip /q +echo. + +echo Downloading: opencv_contrib-4.7.0.zip [58MB] +powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri https://github.com/opencv/opencv_contrib/archive/4.7.0.zip -OutFile c:\opencv\opencv_contrib-4.7.0.zip" +echo Extracting... +powershell -command "$ProgressPreference = 'SilentlyContinue'; Expand-Archive -Path c:\opencv\opencv_contrib-4.7.0.zip -DestinationPath c:\opencv" +del c:\opencv\opencv_contrib-4.7.0.zip /q +echo. + +echo Done with downloading and extracting sources. +echo. + +@echo on + +cd /D C:\opencv\build +set PATH=%PATH%;C:\Program Files (x86)\CMake\bin;C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin +if [%1]==[static] ( + echo Build static opencv + set enable_shared=OFF +) else ( + set enable_shared=ON +) +cmake C:\opencv\opencv-4.7.0 -G "MinGW Makefiles" -BC:\opencv\build -DENABLE_CXX11=ON -DOPENCV_EXTRA_MODULES_PATH=C:\opencv\opencv_contrib-4.7.0\modules -DBUILD_SHARED_LIBS=%enable_shared% -DWITH_IPP=OFF -DWITH_MSMF=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=ON -DBUILD_opencv_java=OFF -DBUILD_opencv_python=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DBUILD_DOCS=OFF -DENABLE_PRECOMPILED_HEADERS=OFF -DBUILD_opencv_saliency=OFF -DBUILD_opencv_wechat_qrcode=ON -DCPU_DISPATCH= -DOPENCV_GENERATE_PKGCONFIG=ON -DWITH_OPENCL_D3D11_NV=OFF -DOPENCV_ALLOCATOR_STATS_COUNTER_TYPE=int64_t -Wno-dev +mingw32-make -j%NUMBER_OF_PROCESSORS% +mingw32-make install +rmdir c:\opencv\opencv-4.7.0 /s /q +rmdir c:\opencv\opencv_contrib-4.7.0 /s /q +chdir /D %GOPATH%\src\gocv.io\x\gocv diff --git a/vendor/modules.txt b/vendor/modules.txt index 4f8e5b7e..46e0e2ee 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -66,6 +66,9 @@ github.com/rs/zerolog/hlog/internal/mutil github.com/rs/zerolog/internal/cbor github.com/rs/zerolog/internal/json github.com/rs/zerolog/log +# gocv.io/x/gocv v0.33.0 +## explicit; go 1.13 +gocv.io/x/gocv # golang.org/x/crypto v0.7.0 ## explicit; go 1.17 golang.org/x/crypto/sha3