w43322

Kuku's blog desu

Zensoku zenshin... Yousoro!
github
twitter
steam
email
telegram
bilibili
discord server

Recording an experience of contributing code to OpenCV: Why did a syntax error appear in the official documentation (my fault)

Background#

At the beginning of the year, I interned at an internet company, where we used the Guided Filter from OpenCV in an Android scenario. One day, my boss asked me to implement the Fast Guided Filter and see how much faster it would be compared to the Guided Filter.

Preparation#

After a brief investigation, I found that OpenCV did not integrate the Fast Guided Filter. There were some "plugins" available online for OpenCV to use the Fast Guided Filter, but they required importing a lot of third-party code, which I didn't find elegant:

Screenshot 2024-09-02 00.56.41

Then I read the paper on the Fast Guided Filter and found that the only difference between it and the Guided Filter was the addition of downsampling and upsampling processes during the processing. The implementation of the Guided Filter in OpenCV appeared earlier than the Fast Guided Filter, so it didn't include it, which is understandable. However, it's strange that after so many years, no one has provided this capability to OpenCV.

Process#

Code Submission in 2024.01#

Screenshot 2024-09-02 01.00.37

So I directly added a parameter scale to the OpenCV Guided Filter interface, which represents the resampling factor. The code was quickly modified, and after testing, the results were as expected. The time complexity of the entire algorithm was reduced from O(N)O(N) to O(N/s2)O(N/s^2).

So on that day, I submitted a Pull Request to the OpenCV GitHub repository. I ran a few pipelines, and they all passed, so I naturally put this matter aside.

Review in 2024.02#

Screenshot 2024-09-02 01.04.51

A week later, I saw that there was no progress on the PR, so I looked at a few other people's PRs. I found that their PRs had new pipelines running, but my pipeline timed out during the rerun process, which made me a little jealous (my INFP personality kicked in), so I mentioned the person who started the pipeline.

Screenshot 2024-09-02 01.05.20

Another week passed. During the Spring Festival, someone finally replied to me. They made a few simple suggestions, and I quickly made the changes. The main difficulty was implementing the unit tests because it was challenging to have a quantifiable means to check if the generated images met the expectations.

Screenshot 2024-09-02 01.07.48

Screenshot 2024-09-02 01.08.04

After thinking for a long time, I finally used a compromise approach: using the variance of the image after applying the Laplacian operator as the evaluation criterion. The result of the Fast Guided Filter should be larger than the result of directly downsampling and upsampling (i.e., the Fast Guided Filter retains more details than the Naive method). Additionally, the result of the Fast Guided Filter should not differ too much from the result of the Guided Filter (i.e., it should not lose too many details). Here, adjusting the parameter was actually a random choice after numerous failed attempts... Luckily, the reviewer didn't dig deeper into it.

Merge in 2024.05#

Screenshot 2024-09-02 01.19.56

After several months without any response, I forgot about this matter. One day in May, this PR was suddenly merged. So I went to the official website to check the latest documentation and found a syntax error:

Screenshot 2024-09-02 01.23.55

Screenshot 2024-09-02 01.27.50

Oh my goodness, how did I make a mistake in describing the scale and wrote to speeds up? Oh, it turns out I initially wrote speeds up, then reconsidered and wanted to change it to to speed up, but I didn't change it completely... It's really frustrating. The maintainers of OpenCV are mostly Russian, so they probably didn't notice this detail.

Result#

So now OpenCV has the Fast Guided Filter available, and there's no need to import third-party code from unknown sources anymore. Hooray! Let me praise OpenCV's documentation system here. As long as you write appropriate comments in the CPP source code, the corresponding documentation will be automatically generated, even including the Python API documentation. I don't even know what magical tool they're using.

Overall, this experience was quite good. The only downside was that the PR took a while to be merged, and in the end, there was a typo in the official documentation. However, it seems that the maintainers of OpenCV are understaffed, so it's understandable.

Screenshot 2024-09-02 01.32.29

So now I also have the Contributor tag in OpenCV!!!

I'm so happy~

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.