From f684ee7148c2bc244303ff8f45c9079f755c1524 Mon Sep 17 00:00:00 2001 From: diegohce Date: Thu, 19 Sep 2024 14:44:42 -0300 Subject: [PATCH] added missing cuda imgproc standalone functions --- ROADMAP.md | 26 ++-- core.go | 5 + cuda/imgproc.cpp | 114 +++++++++++++++ cuda/imgproc.go | 260 +++++++++++++++++++++++++++++++++ cuda/imgproc.h | 14 ++ cuda/imgproc_alphacomptypes.go | 19 +++ cuda/imgproc_test.go | 176 ++++++++++++++++++++++ 7 files changed, 601 insertions(+), 13 deletions(-) create mode 100644 cuda/imgproc_alphacomptypes.go diff --git a/ROADMAP.md b/ROADMAP.md index bf1bd04d..017f397c 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -273,24 +273,24 @@ Your pull requests will be greatly appreciated! - [ ] [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: - - [ ] [cv::cuda::alphaComp](https://docs.opencv.org/master/db/d8c/group__cudaimgproc__color.html#ga08a698700458d9311390997b57fbf8dc) - - [ ] [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) + - [X] [cv::cuda::alphaComp](https://docs.opencv.org/master/db/d8c/group__cudaimgproc__color.html#ga08a698700458d9311390997b57fbf8dc) + - [X] [cv::cuda::gammaCorrection](https://docs.opencv.org/master/db/d8c/group__cudaimgproc__color.html#gaf4195a8409c3b8fbfa37295c2b2c4729) + - [X] [cv::cuda::swapChannels](https://docs.opencv.org/master/db/d8c/group__cudaimgproc__color.html#ga75a29cc4a97cde0d43ea066b01de927e) + - [X] [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) + - [X] [cv::cuda::equalizeHist](https://docs.opencv.org/master/d8/d0e/group__cudaimgproc__hist.html#ga2384be74bd2feba7e6c46815513f0060) + - [X] [cv::cuda::evenLevels](https://docs.opencv.org/master/d8/d0e/group__cudaimgproc__hist.html#ga2f2cbd21dc6d7367a7c4ee1a826f389d) + - [X] [cv::cuda::histEven](https://docs.opencv.org/master/d8/d0e/group__cudaimgproc__hist.html#gacd3b14279fb77a57a510cb8c89a1856f) + - [X] [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] [cv::cuda::bilateralFilter](https://docs.opencv.org/master/d0/d05/group__cudaimgproc.html#ga6abeaecdd4e7edc0bd1393a04f4f20bd) + - [X] [cv::cuda::blendLinear](https://docs.opencv.org/master/d0/d05/group__cudaimgproc.html#ga4793607e5729bcc15b27ea33d9fe335e) + - [X] [cv::cuda::meanShiftFiltering](https://docs.opencv.org/master/d0/d05/group__cudaimgproc.html#gae13b3035bc6df0e512d876dbb8c00555) + - [X] [cv::cuda::meanShiftProc](https://docs.opencv.org/master/d0/d05/group__cudaimgproc.html#ga6039dc8ecbe2f912bc83fcc9b3bcca39) + - [X] [cv::cuda::meanShiftSegmentation](https://docs.opencv.org/master/d0/d05/group__cudaimgproc.html#ga70ed80533a448829dc48cf22b1845c16) - [X] **cudaobjdetect. Object Detection** diff --git a/core.go b/core.go index 79a49188..b0014f47 100644 --- a/core.go +++ b/core.go @@ -1985,6 +1985,11 @@ func NewTermCriteria(typ TermCriteriaType, maxCount int, epsilon float64) TermCr return TermCriteria{p: C.TermCriteria_New(C.int(typ), C.int(maxCount), C.double(epsilon))} } +// Ptr returns the underlying C.TermCriteria +func (tc *TermCriteria) Ptr() C.TermCriteria { + return tc.p +} + // Scalar is a 4-element vector widely used in OpenCV to pass pixel values. // // For further details, please see: diff --git a/cuda/imgproc.cpp b/cuda/imgproc.cpp index c5309cca..d44dfa77 100644 --- a/cuda/imgproc.cpp +++ b/cuda/imgproc.cpp @@ -124,4 +124,118 @@ void TemplateMatching_Match(TemplateMatching tm, GpuMat img, GpuMat tmpl, GpuMat (*tm)->match(*img, *tmpl, *dst, *s); } return; +} + +void AlphaComp(GpuMat img1, GpuMat img2, GpuMat dst, int alpha_op, Stream s) { + if(s == NULL) { + cv::cuda::alphaComp(*img1, *img2, *dst, alpha_op); + } else { + cv::cuda::alphaComp(*img1, *img2, *dst, alpha_op, *s); + } +} + +void GammaCorrection(GpuMat src, GpuMat dst, bool forward, Stream s) { + if(s == NULL) { + cv::cuda::gammaCorrection(*src, *dst, forward); + } else { + cv::cuda::gammaCorrection(*src, *dst, forward, *s); + } +} + +void SwapChannels(GpuMat image, int dstOrder[4], Stream s) { + if(s == NULL) { + cv::cuda::swapChannels(*image, dstOrder); + } else { + cv::cuda::swapChannels(*image, dstOrder, *s); + } +} + +void Cuda_CalcHist(GpuMat src, GpuMat dst, Stream s) { + if(s == NULL) { + cv::cuda::calcHist(*src, *dst); + }else{ + cv::cuda::calcHist(*src, *dst, *s); + } +} + +void Cuda_CalcHist_WithParams(GpuMat src, GpuMat mask, GpuMat dst, Stream s) { + if(s == NULL) { + cv::cuda::calcHist(*src, *mask, *dst); + }else{ + cv::cuda::calcHist(*src, *mask, *dst, *s); + } +} + +void Cuda_EqualizeHist(GpuMat src, GpuMat dst, Stream s) { + if(s == NULL) { + cv::cuda::equalizeHist(*src, *dst); + }else{ + cv::cuda::equalizeHist(*src, *dst, *s); + } +} + +void Cuda_EvenLevels(GpuMat levels, int nLevels, int lowerLevel, int upperLevel, Stream s) { + if(s == NULL) { + cv::cuda::evenLevels(*levels, nLevels, lowerLevel, upperLevel); + }else{ + cv::cuda::evenLevels(*levels, nLevels, lowerLevel, upperLevel, *s); + } +} + +void Cuda_HistEven(GpuMat src, GpuMat hist, int histSize, int lowerLevel, int upperLevel, Stream s) { + if(s == NULL) { + cv::cuda::histEven(*src, *hist, histSize, lowerLevel, upperLevel); + }else{ + cv::cuda::histEven(*src, *hist, histSize, lowerLevel, upperLevel, *s); + } +} + + +void Cuda_HistRange(GpuMat src, GpuMat hist, GpuMat levels, Stream s){ + if(s == NULL) { + cv::cuda::histRange(*src, *hist, *levels); + } else { + cv::cuda::histRange(*src, *hist, *levels, *s); + } +} + +void Cuda_BilateralFilter(GpuMat src, GpuMat dst, int kernel_size, float sigma_color, float sigma_spatial, int borderMode, Stream s) { + if(s == NULL) { + cv::cuda::bilateralFilter(*src, *dst, kernel_size, sigma_color, sigma_spatial, borderMode); + } else { + cv::cuda::bilateralFilter(*src, *dst, kernel_size, sigma_color, sigma_spatial, borderMode, *s); + } +} + +void Cuda_BlendLinear(GpuMat img1, GpuMat img2, GpuMat weights1, GpuMat weights2, GpuMat result, Stream s) { + if(s == NULL) { + cv::cuda::blendLinear(*img1, *img2, *weights1, *weights2, *result); + } else { + cv::cuda::blendLinear(*img1, *img2, *weights1, *weights2, *result, *s); + } +} + +void Cuda_MeanShiftFiltering(GpuMat src, GpuMat dst, int sp, int sr, TermCriteria criteria, Stream s) { + if(s == NULL) { + cv::cuda::meanShiftFiltering(*src, *dst, sp, sr, *criteria); + } else { + cv::cuda::meanShiftFiltering(*src, *dst, sp, sr, *criteria, *s); + } +} + +void Cuda_MeanShiftProc(GpuMat src, GpuMat dstr, GpuMat dstsp, int sp, int sr, TermCriteria criteria, Stream s) { + if(s == NULL) { + cv::cuda::meanShiftProc(*src, *dstr, *dstsp, sp, sr, *criteria); + } else { + cv::cuda::meanShiftProc(*src, *dstr, *dstsp, sp, sr, *criteria, *s); + } +} + + +void Cuda_MeanShiftSegmentation(GpuMat src, GpuMat dst, int sp, int sr, int minSize, TermCriteria criteria, Stream s) { + if(s == NULL) { + cv::cuda::meanShiftSegmentation(*src, *dst, sp, sr, minSize, *criteria); + } else { + cv::cuda::meanShiftSegmentation(*src, *dst, sp, sr, minSize, *criteria, *s); + } } \ No newline at end of file diff --git a/cuda/imgproc.go b/cuda/imgproc.go index c7927cb1..f04b798c 100644 --- a/cuda/imgproc.go +++ b/cuda/imgproc.go @@ -282,3 +282,263 @@ func (tm *TemplateMatching) MatchWithStream(img GpuMat, tmpl GpuMat, dst *GpuMat C.TemplateMatching_Match(C.TemplateMatching(tm.p), img.p, tmpl.p, dst.p, s.p) return } + +// AlphaComp Composites two images using alpha opacity values contained in each image. +// +// img1: First image. Supports CV_8UC4 , CV_16UC4 , CV_32SC4 and CV_32FC4 types. +// +// img2: Second image. Must have the same size and the same type as img1. +// +// dst: Destination image. +// +// alpha_op: Flag specifying the alpha-blending operation +// +// For further details, please see: +// https://docs.opencv.org/4.x/db/d8c/group__cudaimgproc__color.html#ga08a698700458d9311390997b57fbf8dc +func AlphaComp(img1 GpuMat, img2 GpuMat, dst *GpuMat, alphaOp AlphaCompTypes, s Stream) { + C.AlphaComp(img1.p, img2.p, dst.p, C.int(alphaOp), s.p) +} + +// GammaCorrection Routines for correcting image color gamma. +// +// src: Source image (3- or 4-channel 8 bit). +// +// dst: Destination image. +// +// forward: true for forward gamma correction or false for inverse gamma correction. +// +// stream: Stream for the asynchronous version. +// +// For further details, please see: +// https://docs.opencv.org/4.x/db/d8c/group__cudaimgproc__color.html#gaf4195a8409c3b8fbfa37295c2b2c4729 +func GammaCorrection(src GpuMat, dst *GpuMat, forward bool, s Stream) { + C.GammaCorrection(src.p, dst.p, C.bool(forward), s.p) +} + +// SwapChannels Exchanges the color channels of an image in-place. +// +// image: Source image. Supports only CV_8UC4 type. +// +// dstOrder: Integer array describing how channel values are permutated. The n-th entry of the array +// contains the number of the channel that is stored in the n-th channel of the output image. +// E.g. Given an RGBA image, aDstOrder = [3,2,1,0] converts this to ABGR channel order. +// +// stream: Stream for the asynchronous version. +// +// supports arbitrary permutations of the original channels, including replication. +// +// For further details, please see: +// https://docs.opencv.org/4.x/db/d8c/group__cudaimgproc__color.html#ga75a29cc4a97cde0d43ea066b01de927e +func SwapChannels(image *GpuMat, dstOrder []int, s Stream) { + C.SwapChannels(image.p, (*C.int)(unsafe.Pointer(&dstOrder[0])), s.p) +} + +// CalcHist Calculates histogram for one channel 8-bit image. +// +// src: Source image with CV_8UC1 type. +// +// hist: Destination histogram with one row, 256 columns, and the CV_32SC1 type. +// +// stream: Stream for the asynchronous version. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d8/d0e/group__cudaimgproc__hist.html#gaaf3944106890947020bb4522a7619c26 +func CalcHist(src GpuMat, dst *GpuMat, s Stream) { + C.Cuda_CalcHist(src.p, dst.p, s.p) +} + +// CalcHistWithParams Calculates histogram for one channel 8-bit image confined in given mask. +// +// src: Source image with CV_8UC1 type. +// +// mask: A mask image same size as src and of type CV_8UC1. +// +// hist: Destination histogram with one row, 256 columns, and the CV_32SC1 type. +// +// stream: Stream for the asynchronous version. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d8/d0e/group__cudaimgproc__hist.html#ga2d55b444ce776c8bbd3087cc90c47f32 +func CalcHistWithParams(src GpuMat, mask GpuMat, dst *GpuMat, s Stream) { + C.Cuda_CalcHist_WithParams(src.p, mask.p, dst.p, s.p) +} + +// EqualizeHist Equalizes the histogram of a grayscale image. +// +// src: Source image with CV_8UC1 type. +// +// dst: Destination image. +// +// stream: Stream for the asynchronous version. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d8/d0e/group__cudaimgproc__hist.html#ga2384be74bd2feba7e6c46815513f0060 +func EqualizeHist(src GpuMat, dst *GpuMat, s Stream) { + C.Cuda_EqualizeHist(src.p, dst.p, s.p) +} + +// EvenLevels Computes levels with even distribution. +// +// levels: Destination array. levels has 1 row, nLevels columns, and the CV_32SC1 type. +// +// nLevels: Number of computed levels. nLevels must be at least 2. +// +// lowerLevel: Lower boundary value of the lowest level. +// +// upperLevel: Upper boundary value of the greatest level. +// +// stream: Stream for the asynchronous version. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d8/d0e/group__cudaimgproc__hist.html#ga2f2cbd21dc6d7367a7c4ee1a826f389dFor further details, please see: +func EvenLevels(levels *GpuMat, nLevels int, lowerLevel int, upperLevel int, s Stream) { + C.Cuda_EvenLevels(levels.p, C.int(nLevels), C.int(lowerLevel), C.int(upperLevel), s.p) +} + +// HistEven Calculates a histogram with evenly distributed bins. +// +// src: Source image. CV_8U, CV_16U, or CV_16S depth and 1 or 4 channels are supported. +// For a four-channel image, all channels are processed separately. +// +// hist: Destination histogram with one row, histSize columns, and the CV_32S type. +// +// histSize: Size of the histogram. +// +// lowerLevel: Lower boundary of lowest-level bin. +// +// upperLevel: Upper boundary of highest-level bin. +// +// stream: Stream for the asynchronous version. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d8/d0e/group__cudaimgproc__hist.html#gacd3b14279fb77a57a510cb8c89a1856f +func HistEven(src GpuMat, hist *GpuMat, histSize int, lowerLevel int, upperLevel int, s Stream) { + C.Cuda_HistEven(src.p, hist.p, C.int(histSize), C.int(lowerLevel), C.int(upperLevel), s.p) +} + +// HistRange Calculates a histogram with bins determined by the levels array. +// +// src: Source image. CV_8U , CV_16U , or CV_16S depth and 1 or 4 channels are supported. +// For a four-channel image, all channels are processed separately. +// +// hist: Destination histogram with one row, (levels.cols-1) columns, and the CV_32SC1 type. +// +// levels: Number of levels in the histogram. +// +// stream: Stream for the asynchronous version. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d8/d0e/group__cudaimgproc__hist.html#ga87819085c1059186d9cdeacd92cea783 +func HistRange(src GpuMat, hist *GpuMat, levels GpuMat, s Stream) { + C.Cuda_HistRange(src.p, hist.p, levels.p, s.p) +} + +// BilateralFilter Performs bilateral filtering of passed image. +// +// src: Source image. Supports only (channels != 2 && depth() != CV_8S && depth() != CV_32S && depth() != CV_64F). +// +// dst: Destination imagwe. +// +// kernelSize: Kernel window size. +// +// sigmaColor: Filter sigma in the color space. +// +// sigmaSpatial: Filter sigma in the coordinate space. +// +// borderMode: Border type. See borderInterpolate for details. +// BorderReflect101 , BorderReplicate , BorderConstant , BorderReflect and BorderWrap are supported for now. +// +// stream: Stream for the asynchronous version. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d0/d05/group__cudaimgproc.html#ga6abeaecdd4e7edc0bd1393a04f4f20bd +func BilateralFilter(src GpuMat, dst *GpuMat, kernelSize int, sigmaColor float32, sigmaSpatial float32, borderMode BorderType, s Stream) { + C.Cuda_BilateralFilter(src.p, dst.p, C.int(kernelSize), C.float(sigmaColor), C.float(sigmaSpatial), C.int(borderMode), s.p) +} + +// BlendLinear Performs linear blending of two images. +// +// img1: First image. Supports only CV_8U and CV_32F depth. +// +// img2: Second image. Must have the same size and the same type as img1 . +// +// weights1: Weights for first image. Must have tha same size as img1 . Supports only CV_32F type. +// +// weights2: Weights for second image. Must have tha same size as img2 . Supports only CV_32F type. +// +// result: Destination image. +// +// stream: Stream for the asynchronous version. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d0/d05/group__cudaimgproc.html#ga4793607e5729bcc15b27ea33d9fe335e +func BlendLinear(img1 GpuMat, img2 GpuMat, weights1 GpuMat, weights2 GpuMat, result *GpuMat, s Stream) { + C.Cuda_BlendLinear(img1.p, img2.p, weights1.p, weights2.p, result.p, s.p) +} + +// MeanShiftFiltering Performs mean-shift filtering for each point of the source image. +// It maps each point of the source image into another point. +// As a result, you have a new color and new position of each point. +// +// src: Source image. Only CV_8UC4 images are supported for now. +// +// dst: Destination image containing the color of mapped points. It has the same size and type as src . +// +// sp: Spatial window radius. +// +// sr: Color window radius. +// +// criteria: Termination criteria. See TermCriteria. +// +// stream: Stream for the asynchronous version. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d0/d05/group__cudaimgproc.html#gae13b3035bc6df0e512d876dbb8c00555 +func MeanShiftFiltering(src GpuMat, dst *GpuMat, sp int, sr int, criteria gocv.TermCriteria, s Stream) { + C.Cuda_MeanShiftFiltering(src.p, dst.p, C.int(sp), C.int(sr), C.TermCriteria(criteria.Ptr()), s.p) +} + +// MeanShiftProc Performs a mean-shift procedure and stores information +// about processed points (their colors and positions) in two images. +// +// src: Source image. Only CV_8UC4 images are supported for now. +// +// dstr: Destination image containing the color of mapped points. The size and type is the same as src . +// +// dstsp: Destination image containing the position of mapped points. The size is the same as src size. The type is CV_16SC2 . +// +// sp: Spatial window radius. +// +// sr: Color window radius. +// +// criteria: Termination criteria. See TermCriteria. +// +// stream: Stream for the asynchronous version. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d0/d05/group__cudaimgproc.html#ga6039dc8ecbe2f912bc83fcc9b3bcca39 +func MeanShiftProc(src GpuMat, dstr *GpuMat, dstsp *GpuMat, sp int, sr int, criteria gocv.TermCriteria, s Stream) { + C.Cuda_MeanShiftProc(src.p, dstr.p, dstsp.p, C.int(sp), C.int(sr), C.TermCriteria(criteria.Ptr()), s.p) +} + +// MeanShiftSegmentation Performs a mean-shift segmentation of the source image and eliminates small segments. +// +// src: Source image. Only CV_8UC4 images are supported for now. +// +// dst: Segmented image with the same size and type as src. +// +// sp: Spatial window radius. +// +// sr: Color window radius. +// +// minsize: Minimum segment size. Smaller segments are merged. +// +// criteria: Termination criteria. See TermCriteria. +// +// stream: Stream for the asynchronous version. +// +// For further details, please see: +// https://docs.opencv.org/4.x/d0/d05/group__cudaimgproc.html#ga70ed80533a448829dc48cf22b1845c16 +func MeanShiftSegmentation(src GpuMat, dst *GpuMat, sp int, sr int, minSize int, criteria gocv.TermCriteria, s Stream) { + C.Cuda_MeanShiftSegmentation(src.p, dst.p, C.int(sp), C.int(sr), C.int(minSize), C.TermCriteria(criteria.Ptr()), s.p) +} diff --git a/cuda/imgproc.h b/cuda/imgproc.h index 4d743f59..5440dd43 100644 --- a/cuda/imgproc.h +++ b/cuda/imgproc.h @@ -27,6 +27,20 @@ typedef void* TemplateMatching; // standalone functions void GpuCvtColor(GpuMat src, GpuMat dst, int code, Stream s); void GpuDemosaicing(GpuMat src, GpuMat dst, int code, Stream s); +void AlphaComp(GpuMat img1, GpuMat img2, GpuMat dst, int alpha_op, Stream s); +void GammaCorrection(GpuMat src, GpuMat dst, bool forward, Stream s); +void SwapChannels(GpuMat image, int dstOrder[4], Stream s); +void Cuda_CalcHist(GpuMat src, GpuMat dst, Stream s); +void Cuda_CalcHist_WithParams(GpuMat src, GpuMat mask, GpuMat dst, Stream s); +void Cuda_EqualizeHist(GpuMat src, GpuMat dst, Stream s); +void Cuda_EvenLevels(GpuMat levels, int nLevels, int lowerLevel, int upperLevel, Stream s); +void Cuda_HistEven(GpuMat src, GpuMat hist, int histSize, int lowerLevel, int upperLevel, Stream s); +void Cuda_HistRange(GpuMat src, GpuMat hist, GpuMat levels, Stream s); +void Cuda_BilateralFilter(GpuMat src, GpuMat dst, int kernel_size, float sigma_color, float sigma_spatial, int borderMode, Stream s); +void Cuda_BlendLinear(GpuMat img1, GpuMat img2, GpuMat weights1, GpuMat weights2, GpuMat result, Stream s); +void Cuda_MeanShiftFiltering(GpuMat src, GpuMat dst, int sp, int sr, TermCriteria criteria, Stream s); +void Cuda_MeanShiftProc(GpuMat src, GpuMat dstr, GpuMat dstsp, int sp, int sr, TermCriteria criteria, Stream s); +void Cuda_MeanShiftSegmentation(GpuMat src, GpuMat dst, int sp, int sr, int minSize, TermCriteria criteria, Stream s); // CannyEdgeDetector CannyEdgeDetector CreateCannyEdgeDetector(double lowThresh, double highThresh); diff --git a/cuda/imgproc_alphacomptypes.go b/cuda/imgproc_alphacomptypes.go new file mode 100644 index 00000000..e2a3fc1b --- /dev/null +++ b/cuda/imgproc_alphacomptypes.go @@ -0,0 +1,19 @@ +package cuda + +type AlphaCompTypes int + +const ( + AlphaCompTypeOver AlphaCompTypes = iota + AlphaCompTypeIn + AlphaCompTypeOut + AlphaCompTypeAtop + AlphaCompTypeXor + AlphaCompTypePlus + AlphaCompTypeOverPremul + AlphaCompTypeInPremul + AlphaCompTypeOutPremul + AlphaCompTypeAtopPremul + AlphaCompTypeXorPremul + AlphaCompTypePlusPremul + AlphaCompTypePremul +) diff --git a/cuda/imgproc_test.go b/cuda/imgproc_test.go index 041e9f28..dbd418df 100644 --- a/cuda/imgproc_test.go +++ b/cuda/imgproc_test.go @@ -458,3 +458,179 @@ func NewBayerFromMat(src gocv.Mat, pattern string) (gocv.Mat, error) { return dest, nil } + +func TestAlphaComp(t *testing.T) { + img := gocv.IMRead("../images/box.png", gocv.IMReadUnchanged) + defer img.Close() + + converted := gocv.NewMat() + defer converted.Close() + + gocv.CvtColor(img, &converted, gocv.ColorRGBAToBGRA) + + m1 := NewGpuMatFromMat(converted) + defer m1.Close() + + m2 := NewGpuMatFromMat(converted) + defer m2.Close() + + dst := NewGpuMat() + defer dst.Close() + + AlphaComp(m1, m2, &dst, AlphaCompTypeOver, Stream{}) + +} + +func TestGammaCorrection(t *testing.T) { + img := gocv.IMRead("../images/box.png", gocv.IMReadUnchanged) + defer img.Close() + + converted := gocv.NewMat() + defer converted.Close() + + gocv.CvtColor(img, &converted, gocv.ColorRGBAToBGRA) + + m1 := NewGpuMatFromMat(converted) + defer m1.Close() + + dst := NewGpuMat() + defer dst.Close() + + GammaCorrection(m1, &dst, true, Stream{}) + +} +func TestSwapChannels(t *testing.T) { + img := gocv.IMRead("../images/box.png", gocv.IMReadUnchanged) + defer img.Close() + + converted := gocv.NewMat() + defer converted.Close() + + gocv.CvtColor(img, &converted, gocv.ColorRGBAToBGRA) + + m1 := NewGpuMatFromMat(converted) + defer m1.Close() + + SwapChannels(&m1, []int{3, 2, 1, 0}, Stream{}) + +} + +func TestCalcHist(t *testing.T) { + m1 := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC1) + defer m1.Close() + + m2 := NewGpuMatWithSize(1, 256, gocv.MatTypeCV32SC1) + defer m2.Close() + + CalcHist(m1, &m2, Stream{}) + CalcHistWithParams(m1, m1, &m2, Stream{}) +} + +func TestEqualizeHist(t *testing.T) { + m1 := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC1) + defer m1.Close() + + m2 := NewGpuMatWithSize(1, 256, gocv.MatTypeCV32SC1) + defer m2.Close() + + EqualizeHist(m1, &m2, Stream{}) +} + +func TestEvenLevels(t *testing.T) { + m1 := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC1) + defer m1.Close() + + EvenLevels(&m1, 2, 1, 2, Stream{}) +} + +func TestHistEven(t *testing.T) { + m1 := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC1) + defer m1.Close() + + m2 := NewGpuMatWithSize(1, 256, gocv.MatTypeCV32SC1) + defer m2.Close() + + HistEven(m1, &m2, 256, 1, 2, Stream{}) +} + +func TestHistRange(t *testing.T) { + src := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC1) + defer src.Close() + + levels := NewGpuMatWithSize(1, 256, gocv.MatTypeCV32SC1) + defer levels.Close() + + hist := NewGpuMatWithSize(1, 256, gocv.MatTypeCV32SC1) + defer hist.Close() + + HistRange(src, &hist, levels, Stream{}) +} + +func TestBilateralFilter(t *testing.T) { + src := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC1) + defer src.Close() + + dst := NewGpuMatWithSize(256, 256, gocv.MatTypeCV32SC1) + defer dst.Close() + + BilateralFilter(src, &dst, 1, 2.2, 3.3, BorderDefault, Stream{}) +} + +func TestBlendLinear(t *testing.T) { + img1 := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC1) + defer img1.Close() + + img2 := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC1) + defer img2.Close() + + result := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC1) + defer result.Close() + + weights1 := NewGpuMatWithSize(256, 256, gocv.MatTypeCV32FC1) + defer weights1.Close() + + weights2 := NewGpuMatWithSize(256, 256, gocv.MatTypeCV32FC1) + defer weights2.Close() + + BlendLinear(img1, img2, weights1, weights2, &result, Stream{}) + +} + +func TestMeanShiftFiltering(t *testing.T) { + src := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC4) + defer src.Close() + + dst := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC4) + defer dst.Close() + + criteria := gocv.NewTermCriteria(gocv.Count, 1, 2.2) + + MeanShiftFiltering(src, &dst, 1, 2, criteria, Stream{}) +} + +func TestMeanShiftProc(t *testing.T) { + src := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC4) + defer src.Close() + + dstr := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC4) + defer dstr.Close() + + dstsp := NewGpuMatWithSize(256, 256, gocv.MatTypeCV16SC2) + defer dstsp.Close() + + criteria := gocv.NewTermCriteria(gocv.Count, 1, 2.2) + + MeanShiftProc(src, &dstr, &dstsp, 1, 2, criteria, Stream{}) +} + +func TestMeanShiftSegmentation(t *testing.T) { + src := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC4) + defer src.Close() + + dst := NewGpuMatWithSize(256, 256, gocv.MatTypeCV8UC4) + defer dst.Close() + + criteria := gocv.NewTermCriteria(gocv.Count, 1, 2.2) + + MeanShiftSegmentation(src, &dst, 1, 2, 3, criteria, Stream{}) +}