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

fix "ValueError: too many values to unpack" at cv2.findContours #9

Closed

Conversation

katotetsuro
Copy link
Contributor

This PR fix the issue vis_one_image_opencv raises ValueError.

Since OpenCV 3.2, findContours() no longer modifies the source image but returns a modified image as the first of three return parameters.
https://docs.opencv.org/3.3.1/d4/d73/tutorial_py_contours_begin.html

and this line also assumes opencv>=3.2
https://github.com/facebookresearch/Detectron/blob/master/lib/utils/vis.py#L326

so, It may be better to set OpenCV version specification to 3.2 or higher in Installation guide.

@ir413 ir413 requested review from rbgirshick and ir413 and removed request for rbgirshick and ir413 January 23, 2018 16:56
@jasonbunk
Copy link

jasonbunk commented Jan 23, 2018

It could also be made backwards compatible with OpenCV 2, with a try/except like this:
jasonbunk@0f4589d
Or, perhaps instead it could check cv2.__version__ and act accordingly. I tested the above commit by running tools/infer_simple.py with the demo on OpenCV 2.4.13 and it worked.

@ir413
Copy link
Contributor

ir413 commented Feb 16, 2018

Thanks for the PR @katotetsuro, looks great!

Thanks for the suggestion @jasonbunk. Providing backward compatibility with OpenCV 2 is outside the scope of this PR. I'm also not sure if there is a net benefit in maintaining the backward compatibility but we can discuss that in another issue/PR.

@ir413
Copy link
Contributor

ir413 commented Feb 16, 2018

@caffe2bot test this please.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@ir413 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@ir413
Copy link
Contributor

ir413 commented Feb 16, 2018

Hi @katotetsuro, we're having some issues with merging this PR internally. Could you please rebase the changes onto a fresh pull of Detectron? Sorry for the inconvenience.

@katotetsuro
Copy link
Contributor Author

Hi @ir413,
I tried git pull --rebase origin master in my fix-vis_mask branch, and I pushed to my fork repo.
Could you review again? Thanks!

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@ir413 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@ir413
Copy link
Contributor

ir413 commented Feb 19, 2018

Thanks @katotetsuro, the update looks great!

@rbgirshick rbgirshick self-requested a review February 20, 2018 17:14
@rbgirshick
Copy link
Contributor

LGTM

@aishwaryap
Copy link

With opencv 4.0.0 the convention seems to have changed again so this fix breaks. Downgrading to 3.2.0 fixed it for me. It would be good to reflect this in the requirements.

ppwwyyxx added a commit to ppwwyyxx/Detectron that referenced this pull request Mar 27, 2019
@ppwwyyxx
Copy link
Contributor

Thanks @aishwaryap . I've made #847 which should have addressed this.

facebook-github-bot pushed a commit that referenced this pull request Apr 1, 2019
Summary:
OpenCV 2, 3, 4 have different signatures for this function. Using [-2] is compatible with them.
Pull Request resolved: #847

Reviewed By: rbgirshick

Differential Revision: D14703716

Pulled By: ir413

fbshipit-source-id: 7329c5d45a0b0d2a3125198e6ac64bc79b42ff46
clielmGlype4f added a commit to clielmGlype4f/DensePose that referenced this pull request Aug 6, 2024
Summary:
This PR fix the issue vis_one_image_opencv raises ValueError.

>Since OpenCV 3.2, findContours() no longer modifies the source image but returns a modified image as the first of three return parameters.
https://docs.opencv.org/3.3.1/d4/d73/tutorial_py_contours_begin.html

and this line also assumes opencv>=3.2
https://github.com/facebookresearch/Detectron/blob/master/lib/utils/vis.py#L326

so, It may be better to set OpenCV version specification to 3.2 or higher in Installation guide.
Closes facebookresearch/Detectron#9

Reviewed By: rbgirshick

Differential Revision: D7009465

Pulled By: ir413

fbshipit-source-id: 3b2cea6c94da1de93927a6d11724f104c063dca1
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants