Compare OPENCV programs with C + + and Python development?

Source: Internet
Author: User
What is the difference between developing OPENCV programs in C + + and Python? Let's make a comparison!
—————————— below asked by Liu Shovel ——————————
Develop OPENCV in C + + and Python,
1. Which is easier to get started with?
2. Is the efficiency of the code running wide gap?
3. Is there a different library for the OpenCV in two languages?
4. For non-programmer researchers, want to develop a visual product, which is better to choose?

Reply content:

My graduation design is to write with OpenCV 2, the early use of C + + wrote a demo, the final product is written in Python 2.
The main difference between the two is the interface and efficiency.

In fact, Python and C + + OpenCV interface is almost the same, the difference is in C + + words, the matrix is used in the Cv::mat,python Numpy.array, usage and interface are different, but the document is rich, the use is very convenient, the principle is similar.

In terms of efficiency, Python's interface is actually just a layer of binding, and ultimately a function called libopencv_*.so, so in OpenCV this layer of efficiency is exactly the same as C + +. The only difference is its numpy.array and Cv::mat. The NumPy is also written using the C extension method, but the Python interface needs to convert the NumPy data into an acceptable input to the OpenCV C interface compared to the C + + version of the OpenCV interface.
The actual program written by Python is slower, but it's not as slow as the test data can support.

Writing in Python is not actually much faster than C + + development, because interfaces are the same, and I don't recommend writing directly in C + +.

I chose Python in the back to actually just try out the Python interface. 1. A urine sex, the library itself is not very different.

2. Because they are the library of the tune, the difference is still small. Say with Numpy.array, is not the only choice, actually still have mat class, you can also use directly, do not must use Numpy.array. Frankly speaking, from the efficiency point of view, because NumPy has Numba artifact, it is more likely than CV. Mat faster. However, the limitation lies in the speed limit of the Gil and non-library operations. For example, if you want to write several for loops rather than using Array/mat's related function operators, there is no way to slow down. Due to the existence of Gil, OpenCV on the py running a single process is charged in the single core, multithreading is basically no use, improve efficiency is often more process, skillful skill may not be the efficiency gap, too rare may write slow more than 10 times times more things.

3. The library is actually the same PYOPENCV is just a layer of encapsulation.

4. Python writes fast But the pit is actually a lot. If you say that the "product" is working in a production environment and your own knowledge of Python is not deep enough, then choosing C + + will be better. If you are familiar with Python, or mainly do rapid prototyping verification ideas and other work, Python has the advantage of saving time and effort, after all, dynamic type provides a lot of convenience, familiar words will not step on the pit/not the idea of how convenient how to come. Simply say two words, choose Python or C + +, consider the following questions

1. Where is the performance pressure? Python's Gil makes multithreading not multicore parallel, must be multi-process, and inherently python is slower than C + +. Therefore, if it is CPU intensive, it is recommended to use C + +, if io-intensive, Python is not that great disadvantage.

2. High cost of development or high operating costs, a developer one months how much money, a server one months how much money, usually the former more and more expensive and the latter, the tradeoff between the pros and cons, C + + development is slower than Python, in the case of performance standards, if the cost savings can offset the development costs, in C + + , and vice versa with Python. Usually python do experiments, debugging what, after training in C + + wrote 1, almost, the basic call parameters are the same, the format conforms to the respective language specifications.
2, in my development program Python than CPP obviously there is a gap, but to work with the computer on this gap is good to see, so, hardware configuration, with Python do real-time is also no problem. Outside, the same function python is slower than CPP, although it says that the python is also lib.
3, basically the same. (Python may be slightly less than 2.4. Version 8 has a function not found in Python, but that one)
4,python is relatively simple, and development may be faster (mainly because other parts of the software may be easier to develop). I think Python is good. The main benefit is that it has too many support libraries. Understanding algorithms is very helpful for developing prototype products.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.