Skip to content

Moved barcode from opencv_contrib#23666

Merged
asmorkalov merged 6 commits intoopencv:4.xfrom
mshabunin:barcode-move
Jun 14, 2023
Merged

Moved barcode from opencv_contrib#23666
asmorkalov merged 6 commits intoopencv:4.xfrom
mshabunin:barcode-move

Conversation

@mshabunin
Copy link
Copy Markdown
Contributor

@mshabunin mshabunin commented May 24, 2023

Merge with opencv/opencv_contrib#3497

TODO
  • Documentation (bib)
  • Tutorial (references)
  • Sample app (refactored)
  • Java (test passes)
  • Python (test passes)
  • Build without DNN
allow_multiple_commits=1
force_builders=Custom
build_image:Docs=docs-js:18.04
build_image:Custom=javascript
buildworker:Custom=linux-1,linux-4

@mshabunin
Copy link
Copy Markdown
Contributor Author

mshabunin commented May 26, 2023

I've met several issues which need to be resolved before finishing the move, @asmorkalov , @opencv-alalek , @vpisarev , please take a look.


A) Dependency on opencv_dnn

Currently objdetect optionally depends on opencv_dnn, so that algorithms using DNN will print warnings when OpenCV has not been built with DNN support. Barcode module also can optionally use neural network for super-resolution (same as in wechat_qrcode module), but it also uses dnn::NMSBoxes function for detection directly. I see two options here:

  1. move NMSBoxes to the opencv_core imgproc
  2. make objdetect dependency on dnn obligatory

B) Inconvenient module API

Barcode class returns results into a three vectors which have to be iterated together afterwards:

bool detectAndDecode(
    InputArray img,
    CV_OUT std::vector<std::string> &decoded_info, // decoded strings - NUM items
    CV_OUT std::vector<BarcodeType> &decoded_type, // code type (e.g. EAN-13), basically a vector of ints - NUM items
    OutputArray points = noArray()) const; // corners - 4*NUM items

I think it will be better to refactor this interface to look sililar to wechat_qrcode, so that it will be possible to unify all interfaces later:

std::vector<std::string> detectAndDecode(InputArray img, OutputArrayOfArrays points = noArray());

Note: code type can be encoded in the first one or two symbols of returned string or returned in a separate vector or tied to each string using a pair or packed in a special structure

Note: I took a look at the #23264 and it also has slight inconsistency between single and multi interfaces:

std::string detectAndDecode(
    InputArray img,
    OutputArray points=noArray(),
    OutputArray straight_qrcode = noArray());
// but
bool detectAndDecodeMulti(
    InputArray img, 
    CV_OUT std::vector<std::string>& decoded_info,
    OutputArray points = noArray(),
    OutputArrayOfArrays straight_qrcode = noArray()) const;

C) Algorithm separation

Currently there are two algorithms used internally in the barcode implementation which can be moved outside:

  • special binarization can be moved to other binarization methods (imgproc, cv::threshold, cv::adaptiveThreshold)
  • DNN-based super-resolution is copied from wechat_qrcode and can be moved to the dnn module, similar to FaceDetectorYN.

@mshabunin
Copy link
Copy Markdown
Contributor Author

Created #23711 which moves NMSBoxes from dnn to imgproc, thus we will be able to move barcode detector to objdetect while keeping its OPTIONAL dependency on dnn.

@opencv-alalek opencv-alalek added feature category: contrib Target patches to **opencv_contrib** repository: https://github.com/opencv/opencv_contrib category: objdetect RFC labels Jun 2, 2023
@asmorkalov asmorkalov added this to the 4.8.0 milestone Jun 5, 2023
@mshabunin mshabunin force-pushed the barcode-move branch 2 times, most recently from 7e75daf to b374071 Compare June 9, 2023 18:10
@mshabunin mshabunin marked this pull request as ready for review June 9, 2023 18:47
@mshabunin mshabunin removed the RFC label Jun 9, 2023
Copy link
Copy Markdown
Contributor

@opencv-alalek opencv-alalek left a comment

Choose a reason for hiding this comment

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

Well done! LGTM 👍

(need to merge opencv_contrib PR first)


#### Initialization

User can construct BarcodeDetector with super resolution model which should be downloaded automatically to `<opencv_build_dir>/downloads/barcode`. If not, please download them from https://github.com/WeChatCV/opencv_3rdparty/tree/wechat_qrcode or choose not to use super resolution.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not downloaded automatically.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


User can construct BarcodeDetector with super resolution model which should be downloaded automatically to `<opencv_build_dir>/downloads/barcode`. If not, please download them from https://github.com/WeChatCV/opencv_3rdparty/tree/wechat_qrcode or choose not to use super resolution.

@snippet ./samples/barcode.cpp initialize
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Barcode sample is located in wrong place: modules/objdetect/samples/barcode.cpp, but should be in samples/cpp/barcode.cpp.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Technically OpenCV supports module-specific samples (like in OpenCV contrib). I decided to put it there because it demonstrates objdetect module functionality. Perhaps we can continue moving C++ samples to their respective modules to reduce this list:

set(OPENCV_CPP_SAMPLES_REQUIRED_DEPS
opencv_core
opencv_imgproc
opencv_flann
opencv_imgcodecs
opencv_videoio
opencv_highgui
opencv_ml
opencv_video
opencv_objdetect
opencv_photo
opencv_features2d
opencv_calib3d
opencv_stitching
opencv_dnn
opencv_gapi
${OPENCV_MODULES_PUBLIC}
${OpenCV_LIB_COMPONENTS})
ocv_check_dependencies(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})

If you think it is better to move it to others (samples/cpp) I will do it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's very unusual for main opencv repo and users do not search for samples in modules source code. I propose to put it to expected places and introduce new practice later globally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, done!

@asmorkalov asmorkalov mentioned this pull request Jun 14, 2023
6 tasks
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

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

👍

@asmorkalov asmorkalov merged commit 463cd09 into opencv:4.x Jun 14, 2023
@mshabunin mshabunin deleted the barcode-move branch June 14, 2023 20:22
@asmorkalov asmorkalov mentioned this pull request Jul 12, 2023
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
Moved barcode from opencv_contrib opencv#23666

Merge with opencv/opencv_contrib#3497

##### TODO
- [x] Documentation (bib)
- [x] Tutorial (references)
- [x] Sample app (refactored)
- [x] Java (test passes)
- [x] Python (test passes)
- [x] Build without DNN
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
Moved barcode from opencv_contrib opencv#23666

Merge with opencv/opencv_contrib#3497

##### TODO
- [x] Documentation (bib)
- [x] Tutorial (references)
- [x] Sample app (refactored)
- [x] Java (test passes)
- [x] Python (test passes)
- [x] Build without DNN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: contrib Target patches to **opencv_contrib** repository: https://github.com/opencv/opencv_contrib category: objdetect feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants