diff --git a/Dockerfile.opencv-openvino b/Dockerfile.opencv-openvino index c16e8d2e..0f34278c 100644 --- a/Dockerfile.opencv-openvino +++ b/Dockerfile.opencv-openvino @@ -5,10 +5,11 @@ 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 \ + git build-essential cmake pkg-config unzip libgtk2.0-dev libgtk-3-0 \ 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 && \ + libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libcanberra-gtk-module \ + libcanberra-gtk3-module && \ rm -rf /var/lib/apt/lists/* ARG OPENCV_VERSION="4.6.0" @@ -39,7 +40,6 @@ RUN curl -Lo opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSIO -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 && \ diff --git a/dnn.cpp b/dnn.cpp index 3cfde57a..6cca38bb 100644 --- a/dnn.cpp +++ b/dnn.cpp @@ -111,15 +111,38 @@ void Net_GetUnconnectedOutLayers(Net net, IntVector* res) { 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(); + size_t totalStrLen = 0; + for (cv::String str : cstrs) { + totalStrLen += str.size(); + } + + // Compute 1D buffer size required to store + // 2D array of null-terminated strings + size_t numStrings = cstrs.size(); + size_t bufferLen = numStrings * sizeof(char*) + (totalStrLen + numStrings) * sizeof(char); + + const char **strs = (const char**)new char[bufferLen]; + memset(strs, 0, bufferLen); + + char* it = (char*)(strs + cstrs.size()); + const char* end = (char*)(strs) + bufferLen; + + for (size_t i = 0; i < numStrings; ++i, ++it) { + strs[i] = it; + size_t strlen = cstrs[i].size(); + + // Avoid buffer overrun + if(end < it + strlen + 1) { + break; + } + + memcpy(it, cstrs[i].c_str(), strlen); + it += strlen; } names->length = cstrs.size(); names->strs = strs; - return; } Mat Net_BlobFromImage(Mat image, double scalefactor, Size size, Scalar mean, bool swapRB, diff --git a/dnn_test.go b/dnn_test.go index e4474bf7..1d690976 100644 --- a/dnn_test.go +++ b/dnn_test.go @@ -56,8 +56,27 @@ func checkNet(t *testing.T, net Net) { t.Errorf("Invalid len layer names in ReadNet test: %d\n", len(lnames)) } - if len(lnames) == 142 && lnames[1] != "conv1/relu_7x7" { - t.Errorf("Invalid layer name in ReadNet test: %s\n", lnames[1]) + m := map[int]string{ + 0: "conv1/7x7_s2", + 10: "inception_3a/1x1", + 20: "inception_3a/pool", + 30: "inception_3b/5x5_reduce", + 40: "inception_4a/relu_1x1", + 50: "inception_4a/pool_proj", + 60: "inception_4b/relu_5x5_reduce", + 70: "inception_4c/relu_3x3_reduce", + 80: "inception_4c/output", + 90: "inception_4d/relu_5x5", + 100: "inception_4e/relu_3x3", + 110: "inception_5a/1x1", + 120: "inception_5a/pool", + 130: "inception_5b/5x5_reduce", + 140: "loss3/classifier"} + + for k, v := range m { + if lnames[k] != v { + t.Errorf("Invalid layer name in ReadNet test: \"%s\" (expected=\"%s\")\n", lnames[k], v) + } } prob := net.ForwardLayers([]string{"prob"})