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

Clean Objdetect module #25004

Closed
vpisarev opened this issue Feb 12, 2024 · 9 comments
Closed

Clean Objdetect module #25004

vpisarev opened this issue Feb 12, 2024 · 9 comments
Assignees
Labels
cleanup Code cleanup (e.g, drop legacy C-API, legacy unmaintained code) feature
Milestone

Comments

@vpisarev
Copy link
Contributor

vpisarev commented Feb 12, 2024

Describe the feature and motivation

object detection is one of the key computer vision tasks where machine learning was used long before deep learning era. Nowadays, with deep learning, the problem is largely solved, at least for common cases.

But objdetect module in OpenCV still contains 'ancient' algorithms. We need to clean it up in OpenCV 5:

  • Move HaarCascadeClassifier to opencv_contrib/xobjdetect.
  • Move HOGDescriptor to opencv_contrib/xobjdetect.
  • Move all Haar/LBP models (opencv/data/*) to opencv_contrib.
  • Move/add Yolo postprocessing functions and DetectionModel from dnn to objdetect.
  • Possibly move Macbeth color chart detector from opencv_contrib/mcc to this module.
  • Maybe add deep learning-based detectors of basic geometric objects like circles and lines instead of traditional algorithms based on Hough transform (which we suggest to remove from Imgproc).

Additional context

No response

@vpisarev vpisarev added feature cleanup Code cleanup (e.g, drop legacy C-API, legacy unmaintained code) labels Feb 12, 2024
@vpisarev vpisarev added this to the 5.0 milestone Feb 12, 2024
@LaurentBerger
Copy link
Contributor

Finally I like mediapipe classification :
image

@vpisarev
Copy link
Contributor Author

@LaurentBerger, looks good, but it's probably too much to have a dedicated OpenCV module for each of those tasks. Various image improvements and stylizations can possibly be put to 'photo' module. Detection-related things can be put to 'objdetect'. Image classification and semantic segmentation now belong to dnn module.

@LaurentBerger
Copy link
Contributor

May be :
DNN (4.0) -> DNNCore (5.0)
Objdetect (4.0) -> DNNModels (5.0) with subfolder as in mediapipe

@vpisarev
Copy link
Contributor Author

@LaurentBerger, we have a dedicated repository opencv_zoo that plays the role of DNNModels :)

@Dhanwanth1803
Copy link
Contributor

@vpisarev Can I work on this? Because I am not sure if only members are working on this.

@TonyCongqianWang
Copy link

While I fully support moving the data/ folder, which had no reason to be there at the root. I can not fully agree on the decision to move the CascadeClassifier to the contrib repo. The CascadeClassifier is still much faster than the YN implementation on cpu especially when running on a raspberry pi. The improved frontal face cascade does offer a reasonable accuracy to be useful for simple tasks.

I can understand the move out of the main repository since it's more of a legacy feature, but it is still used and matured which doesn't fit well with the more unstable and experimental nature of the contrib repository. While building certain contrib modules is still, having to install the contrib python package is somewhat bad

@TonyCongqianWang
Copy link

As a side note or rather feature request:
While the current YN implementation is much slower than the cascade, it could be similarly fast if there was a quantizes version. If someone would add the, the cascade would become truly obsolete

@kaingwade
Copy link
Contributor

@TonyCongqianWang There's a detailed comparison OpenCV Face Detection: Cascade Classifier vs. YuNet. YuNet actually isn't much slower than Cascade.

The OpenCV Model Zoo provides both the fp32 and quantized YuNet (and many other popular deep learning models too), which can both be run with DNN. You can have a try.

@TonyCongqianWang
Copy link

TonyCongqianWang commented Jul 13, 2024

@kaingwade Thanks for the information! I was not aware that opencv hat an implementation for quantized networks and will definitely check it out. In particular, the fact that the model also outputs keypoints is very interesting for my application.

The report is indeed detailed but I have some problems: In particular, in the report, the outdated haar cascaded was used instead of the improved lbp cascade which is both (a lot) faster and more accurate. In my experience the lbp cascade runs in a few ms on 320x320 images instead of the reported 20+ms.

Additionally, only one x86 platform was used for the test, when both quantized and lbp features really shine on arm architecture. I will be happy to rerun the experiment on a raspberry pi with more configurations (cascades: haar, lbp, lbp_improved, YuNet: fp32, uint8) and report back the results if there is any interest on your side!

Lastly: even if the cascade is mostly obsolete I still disagree with moving it to the contrib repository. The contrib repository contains a lot of unmaintened, unfinished code which is very prone to breaking. The cascade module on the other hand is matured and at least right now works well with the rest of the opencv repository without needed maintenance.
Moving the current objectdetect into a legace module within the main repository would have very little cost while having a big advantage of not completely breaking any existing code that still uses cascade classifiers. Especially when custom trained models are used. While retraining with YuNet is possible, it is still a lot of work. The only other possibilities would be to either stay on 4.x or install the opencv_contrib package. Both options have significant disadvantages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code cleanup (e.g, drop legacy C-API, legacy unmaintained code) feature
Projects
Status: Done
Development

No branches or pull requests

5 participants