Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

fix for opencv4 #13559

Closed
wants to merge 1 commit into from
Closed

fix for opencv4 #13559

wants to merge 1 commit into from

Conversation

daleydeng
Copy link

@daleydeng daleydeng commented Dec 6, 2018

Description

Fix compatibility for opencv 4 with flags started with cv namespace.

@szha: resolves #13288

@nswamy nswamy added the pr-awaiting-review PR is waiting for code review label Dec 7, 2018
@larroy
Copy link
Contributor

larroy commented Dec 7, 2018

I checked the docs from opencv the older flags are enums, are we sure the ones in the namespace are compatible it was not clear to me from a quick look to the documentation even though CI agrees.

Do we fail now when compiling with opencv 4?

@szha
Copy link
Member

szha commented Dec 8, 2018

@larroy the flags are used in conjunction with the opencv function calls, so even if the value changes, as long as the input/output remains the same, it should still work.

@szha szha requested a review from zhreshold December 8, 2018 05:53
@zhreshold
Copy link
Member

LGTM, but not sure if every single ENUM is covered in this PR, is this process still conducted by eyes?

@daleydeng
Copy link
Author

i have compiled successfully. you can use grep to found every instances of cv flags

@Roshrini
Copy link
Member

@larroy @zhreshold Is this PR good to go?

@wkcn
Copy link
Member

wkcn commented Dec 27, 2018

The current source of MXNet is not compatible with OpenCV4, and this PR fixes the issue.

In Arch Linux, The package name of OpenCV4 has been changed to opencv4 rather than opencv, so I change the Makefile L138~L145:

# setup opencv
ifeq ($(USE_OPENCV), 1)
	CFLAGS += -DMXNET_USE_OPENCV=1 $(shell pkg-config --cflags opencv4)
	LDFLAGS += $(filter-out -lopencv_ts, $(shell pkg-config --libs opencv4))
	BIN += bin/im2rec
else
	CFLAGS+= -DMXNET_USE_OPENCV=0
endif

@szha
Copy link
Member

szha commented Dec 27, 2018

@wkcn mxnet doesn't use all modules in opencv, and only a subset of what pkgconfig returns for opencv is needed. As of opencv 3.4.2 the modules needed are core, imgcodecs, and imgproc.

@wkcn
Copy link
Member

wkcn commented Dec 28, 2018

@szha Yes.
However, In Arch Linux, ‘pkg-config --cflags opencv’ will raise the error ‘package opencv not found’ after installing OpenCV4, and ‘pkg-config --cflags opencv4’ fixes the issue.
I don’t know whether does the error also occur on other operating systems like Ubuntu.

@gigasquid
Copy link
Member

I was just trying to setup a new mac and now brew install opencv gives you 4.0 with no way (through brew) to get opencv3 :(

So this PR is pretty important to tested/merged

@@ -479,14 +479,14 @@ class DefaultImageAugmenter : public ImageAugmenter {
}
if (i == 1) {
// contrast
cvtColor(res, temp_, CV_RGB2GRAY);
cvtColor(res, temp_, cv::COLOR_RGB2GRAY);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use macros to define these constants based on the opencv version? This should hopefully make it easier to be compatible with multiple versions of opencv.

@gigasquid
Copy link
Member

gigasquid commented Jan 10, 2019

on OSX - I cannot do a make without errors due to `package opencv not found’.

Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

and

      [this](OprExecStat *stat) {}, name_.c_str(), dev_type_, dev_id_,
       ^
In file included from src/io/image_aug_default.cc:31:
src/io/./image_augmenter.h:31:10: fatal error: 'opencv2/opencv.hpp' file not found
#include <opencv2/opencv.hpp>

This is because as @wkcn said above the pkg name has changed to opencv4 from opencv

ls -l /usr/local/lib/pkgconfig
opencv4.pc -> ../../Cellar/opencv/4.0.1/lib/pkgconfig/opencv4.pc

If I make the changes to the Makefile that @wkcn suggested to change it to opencv4, everything works - however we would also need to change all the CI files to bump opencv as well as coordinate changing building of nightly distributions
cc @marcoabreu @lanking520

Maybe we could put a switch in the Makefile or another config to specify what version of opencv you have? That way we could make the upgrade path easier.

Could the makefile somehow detect what version of opencv you have?

@chinakook
Copy link
Contributor

Manjaro(based on Arch) system should be supported because it's widely used and opencv 4 is the default version on Manjaro/Arch.

@marcoabreu
Copy link
Contributor

Yeah I'd be in favour if you upgrade to OpenCV4 in our Ci while you're at it.

@lanking520
Copy link
Member

lanking520 commented Jan 23, 2019

Do we still have OpenCV 2 and 3 support if we switch the namespace? Since CI now are using CV2 and publish using CV3

If not, we should made the same changes on these parts as well

@vandanavk
Copy link
Contributor

what are the next steps on this PR?

@ankkhedia
Copy link
Contributor

@daleydeng Could you please take a look into the comments above?

@wkcn
Copy link
Member

wkcn commented Mar 1, 2019

Thanks for your contribution! @daleydeng

@szha @zhreshold @anirudh2290
Hi! Is it available to merge this PR? Thanks!

@zhreshold
Copy link
Member

I see there's comment not addressed yet?

@wkcn wkcn mentioned this pull request Mar 4, 2019
7 tasks
@vandanavk
Copy link
Contributor

@mxnet-label-bot update [pr-awaiting-response]

@marcoabreu marcoabreu added pr-awaiting-response PR is reviewed and waiting for contributor to respond and removed pr-awaiting-review PR is waiting for code review labels Mar 4, 2019
@szha
Copy link
Member

szha commented Mar 5, 2019

The issues in this PR are being fixed in #14313

@wkcn
Copy link
Member

wkcn commented Mar 7, 2019

Sorry that I submited another PR, which supports multiple versions of OpenCV.
#14313

Thanks for your contribution!

@wkcn wkcn closed this Mar 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-awaiting-response PR is reviewed and waiting for contributor to respond
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenCV 4.0 Compatibility