diff --git a/Dockerfile-test.gpu-cuda-10 b/Dockerfile-test.gpu-cuda-10 index 6479594d..17391c60 100644 --- a/Dockerfile-test.gpu-cuda-10 +++ b/Dockerfile-test.gpu-cuda-10 @@ -4,6 +4,7 @@ # To run tests: # docker run -it --rm --gpus all gocv-test-gpu-cuda-10 # + FROM gocv/opencv:4.6.0-gpu-cuda-10 AS gocv-gpu-test-cuda-10 ENV GOPATH /go diff --git a/Dockerfile.opencv-arm64 b/Dockerfile.opencv-arm64 new file mode 100644 index 00000000..7f3c8c25 --- /dev/null +++ b/Dockerfile.opencv-arm64 @@ -0,0 +1,48 @@ +# to build this docker image: +# docker build -f Dockerfile.opencv -t gocv/opencv:4.6.0 . +FROM golang:1.18-buster AS opencv +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 \ + libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev && \ + rm -rf /var/lib/apt/lists/* + +ARG OPENCV_VERSION="4.6.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 +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 OPENCV_ENABLE_NONFREE=ON \ + -D INSTALL_C_EXAMPLES=OFF \ + -D INSTALL_PYTHON_EXAMPLES=OFF \ + -D BUILD_opencv_python3=TRUE \ + -D OPENCV_GENERATE_PKGCONFIG=ON \ + -D BUILD_EXAMPLES=OFF \ + -D CMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake .. && \ + make -j $(nproc --all) && \ + make preinstall && make install && ldconfig && \ + cd / && rm -rf opencv* + +CMD ["go version"] diff --git a/cuda/cuda.cpp b/cuda/cuda.cpp index 3195ba90..9da50b02 100644 --- a/cuda/cuda.cpp +++ b/cuda/cuda.cpp @@ -68,6 +68,14 @@ void GpuMat_ConvertTo(GpuMat m, GpuMat dst, int type, Stream s) { m->convertTo(*dst, type, *s); } +void GpuMat_ConvertToWithParams(GpuMat m, GpuMat dst, int type, float alpha, float beta, Stream s) { + if (s == NULL) { + m->convertTo(*dst, type, alpha, beta); + return; + } + m->convertTo(*dst, type, alpha, beta, *s); +} + void GpuMat_CopyTo(GpuMat m, GpuMat dst, Stream s) { if (s == NULL) { m->copyTo(*dst); diff --git a/cuda/cuda.go b/cuda/cuda.go index 542670af..0b88da0d 100644 --- a/cuda/cuda.go +++ b/cuda/cuda.go @@ -152,6 +152,26 @@ func (m *GpuMat) ConvertToWithStream(dst *GpuMat, mt gocv.MatType, s Stream) { return } +// ConvertToWithParams converts GpuMat into destination GpuMat. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d60/classcv_1_1cuda_1_1GpuMat.html#a3a1b076e54d8a8503014e27a5440d98a +// +func (m *GpuMat) ConvertToWithParams(dst *GpuMat, mt gocv.MatType, alpha, beta float32) { + C.GpuMat_ConvertToWithParams(m.p, dst.p, C.int(mt), C.float(alpha), C.float(beta), nil) + return +} + +// ConvertToWithParamsStream converts GpuMat into destination GpuMat. +// +// For further details, please see: +// https://docs.opencv.org/master/d0/d60/classcv_1_1cuda_1_1GpuMat.html#a3a1b076e54d8a8503014e27a5440d98a +// +func (m *GpuMat) ConvertToWithParamsStream(dst *GpuMat, mt gocv.MatType, alpha, beta float32, s Stream) { + C.GpuMat_ConvertToWithParams(m.p, dst.p, C.int(mt), C.float(alpha), C.float(beta), s.p) + return +} + // CopyTo copies GpuMat into destination GpuMat. // // For further details, please see: diff --git a/cuda/cuda.h b/cuda/cuda.h index 7e9f2e9f..2a8a9dea 100644 --- a/cuda/cuda.h +++ b/cuda/cuda.h @@ -26,6 +26,7 @@ void GpuMat_Download(GpuMat m, Mat dst, Stream s); void GpuMat_Close(GpuMat m); int GpuMat_Empty(GpuMat m); void GpuMat_ConvertTo(GpuMat m, GpuMat dst, int type, Stream s); +void GpuMat_ConvertToWithParams(GpuMat m, GpuMat dst, int type, float alpha, float beta, Stream s); void GpuMat_CopyTo(GpuMat m, GpuMat dst, Stream s); GpuMat GpuMat_Reshape(GpuMat m, int cn, int rows); int GpuMat_Cols(GpuMat m); diff --git a/cuda/cuda_test.go b/cuda/cuda_test.go index 0ed1805a..90c72285 100644 --- a/cuda/cuda_test.go +++ b/cuda/cuda_test.go @@ -72,6 +72,29 @@ func TestNewGpuMatWithSize(t *testing.T) { } } +func TestConvertToWithParams(t *testing.T) { + src1 := gocv.IMRead("../images/gocvlogo.jpg", gocv.IMReadColor) + if src1.Empty() { + t.Error("Invalid read of Mat in ConvertToWithParams test") + } + defer src1.Close() + + var cimg1, dimg = NewGpuMat(), NewGpuMat() + defer cimg1.Close() + defer dimg.Close() + + cimg1.Upload(src1) + + dest := gocv.NewMat() + defer dest.Close() + + cimg.ConvertToWithParams(&dimg, cimg.Type(), 1.0, 10.0) + dimg.Download(&dest) + if dest.Empty() || src1.Rows() != dest.Rows() || src1.Cols() != dest.Cols() { + t.Error("Invalid ConvertToWithParams test") + } +} + func TestGetCudaEnabledDeviceCount(t *testing.T) { if GetCudaEnabledDeviceCount() < 1 { t.Fatal("expected atleast one cuda enabled device") diff --git a/dnn.go b/dnn.go index 979d68b3..e32691bd 100644 --- a/dnn.go +++ b/dnn.go @@ -522,7 +522,7 @@ func (l *Layer) OutputNameToIndex(name string) int { // // 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) { +func NMSBoxes(bboxes []image.Rectangle, scores []float32, scoreThreshold float32, nmsThreshold float32, indices []int, count *int) { bboxesRectArr := []C.struct_Rect{} for _, v := range bboxes { bbox := C.struct_Rect{ @@ -563,6 +563,7 @@ func NMSBoxes(bboxes []image.Rectangle, scores []float32, scoreThreshold float32 for i := 0; i < int(indicesVector.length); i++ { indices[i] = int(ptr[i]) } + *count = int(indicesVector.length) return } diff --git a/dnn_test.go b/dnn_test.go index e4474bf7..3851cfd1 100644 --- a/dnn_test.go +++ b/dnn_test.go @@ -594,11 +594,13 @@ func TestNMSBoxes(t *testing.T) { indices := make([]int, 10) scoreThreshold := float32(0.5) nmsThreshold := float32(0.4) + var count int - NMSBoxes(bboxes, scores, scoreThreshold, nmsThreshold, indices) - - if indices[0] != 3 { - t.Errorf("Invalid NMSBoxes test indices: %v", indices) + NMSBoxes(bboxes, scores, scoreThreshold, nmsThreshold, indices, &count) + for i := count - 1; i >= 0; i-- { + if indices[i] != 3 { + t.Errorf("Invalid NMSBoxes test indices: %v", indices) + } } }