Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable nonfree feature ? #16

Open
mh-cbon opened this issue Oct 29, 2019 · 1 comment
Open

enable nonfree feature ? #16

mh-cbon opened this issue Oct 29, 2019 · 1 comment

Comments

@mh-cbon
Copy link

mh-cbon commented Oct 29, 2019

How can i enable non free feature ? https://github.com/hybridgroup/gocv/blob/a897c364055ad1328c2162830747da556a8a9aa2/contrib/README.md

It is weird, the build stage appears to include contrib stuff, but this is my output

$ make run
docker run -it \
	-v /home/mh-cbon/gow/src/test/opencv:/go/src/opencv\
	gocv
2019/10/29 19:37:24 [370 265]
2019/10/29 19:37:24 [195 320]
2019/10/29 19:37:24 0.527027027027027 1 0.527027027027027
2019/10/29 19:37:24 [103 169]
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.0.1) /tmp/opencv/opencv_contrib-4.0.1/modules/xfeatures2d/src/sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create'

the related code is

	si := contrib.NewSIFT()
	kp := si.Detect(matTemplate)
	gocv.DrawKeyPoints(matTemplate, kp,
		&matTemplate,
		color.RGBA{R: 0, B: 0, G: 0},
		gocv.DrawDefault)
@mh-cbon
Copy link
Author

mh-cbon commented Oct 29, 2019

i cooked a docker file then build it, it worked. Would be great to have env variable to enable it.


FROM denismakogon/gocv-alpine:4.0.1-buildstage as build-stage

ENV OPENCV_VERSION=4.0.1
ENV BUILD="ca-certificates \
         git \
         build-base \
         musl-dev \
         alpine-sdk \
         make \
         gcc \
         g++ \
         libc-dev \
         linux-headers \
         libjpeg-turbo \
         libpng \
         libwebp \
         libwebp-dev \
         tiff \
         libavc1394 \
         jasper-libs \
         openblas \
         libgphoto2 \
         gstreamer \
         gst-plugins-base"

ENV DEV="clang clang-dev cmake pkgconf \
         openblas-dev gstreamer-dev gst-plugins-base-dev \
         libgphoto2-dev libjpeg-turbo-dev libpng-dev \
         tiff-dev jasper-dev libavc1394-dev"


RUN apk update && \
    apk add --no-cache ${BUILD} ${DEV}

RUN mkdir /tmp/opencv && \
    cd /tmp/opencv && \
    wget -O opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
    unzip opencv.zip && \
    wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
    unzip opencv_contrib.zip && \
    mkdir /tmp/opencv/opencv-${OPENCV_VERSION}/build && cd /tmp/opencv/opencv-${OPENCV_VERSION}/build && \
    cmake \
    -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D OPENCV_EXTRA_MODULES_PATH=/tmp/opencv/opencv_contrib-${OPENCV_VERSION}/modules \
    -D WITH_FFMPEG=YES \
    -D OPENCV_ENABLE_NONFREE=YES \
    -D INSTALL_C_EXAMPLES=NO \
    -D INSTALL_PYTHON_EXAMPLES=NO \
    -D BUILD_ANDROID_EXAMPLES=NO \
    -D BUILD_DOCS=NO \
    -D BUILD_TESTS=NO \
    -D BUILD_PERF_TESTS=NO \
    -D BUILD_EXAMPLES=NO \
    -D BUILD_opencv_java=NO \
    -D BUILD_opencv_python=NO \
    -D BUILD_opencv_python2=NO \
    -D BUILD_opencv_python3=NO \
    -D OPENCV_GENERATE_PKGCONFIG=YES .. && \
    make -j4 && \
    make install && \
    cd && rm -rf /tmp/opencv

RUN apk del ${DEV_DEPS} && \
    rm -rf /var/cache/apk/*

ENV PKG_CONFIG_PATH /usr/local/lib64/pkgconfig
ENV LD_LIBRARY_PATH /usr/local/lib64
ENV CGO_CPPFLAGS -I/usr/local/include
ENV CGO_CXXFLAGS "--std=c++1z"
ENV 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 -lopencv_plot -lopencv_tracking"

FROM build-stage

RUN go get -u -d gocv.io/x/gocv
RUN cd $GOPATH/src/gocv.io/x/gocv && go build -o $GOPATH/bin/gocv-version ./cmd/version/main.go

RUN go env

RUN mkdir -p /go/src/opencv
WORKDIR /go/src/opencv
COPY . .

ENTRYPOINT ["go", "run", "main.go"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant