How to Develop opencv programs using C ++ and python?
Source: Internet
Author: User
What is the difference between developing opencv programs using C ++ and python? Let's make a comparison! ---------- The following is a question from Liu shovel ---------- using C ++ and python to develop opencv. 1. Which one is easier to use? 2. Is there a big gap in code running efficiency? 3. Are the libraries of openCV corresponding to the two languages different? 4. Which of the following is better choice for non-programmers who want to develop a visual product? What is the difference between developing opencv programs using C ++ and python? Let's make a comparison!
---------- Question ----------
Using C ++ and python to develop opencv,
1. Which one is easier to use?
2. Is there a big gap in code running efficiency?
3. Are the libraries of openCV corresponding to the two languages different?
4. Which of the following is better choice for non-programmers who want to develop a visual product? Reply: my graduation project was written in OpenCV 2. I used C ++ to write a Demo in the early stage, and the final product was written in Python 2.
The main difference between the two lies in the interface and efficiency.
In fact, Python is almost the same as the C ++ OpenCV interface. If C ++ is used, the matrix uses cv: Mat, and numpy is used in Python. array. Its usage and interface are different, but the document is rich, convenient to use, and the principle is similar.
In terms of efficiency, the Python interface is actually only a Binding layer, and the function in libopencv _ *. so is finally called. Therefore, the efficiency of OpenCV layer is exactly the same as that of C ++. The only difference is its numpy. array and cv: Mat. Numpy is written using the C Extension method at the underlying layer. However, compared with the OpenCV interface of C ++, the Python interface needs to convert Numpy data into acceptable input of the C interface of OpenCV.
It is slow to test the program written in Python, but the specific slowness is not supported by the test data.
Writing in Python is actually not much faster than developing in C ++, because the interfaces are the same. I suggest writing in C ++ directly.
I chose Python later, but I just wanted to try the Python interface.1. There is no big difference between databases in a single urine.
2. Because all databases are called, the difference is still not big. Numpy. array is not the only choice. In fact, there is still a Mat class. You can also use it directly, not necessarily numpy. array. Frankly speaking, in terms of efficiency, numpy may be faster than cv. Mat because it has numba artifacts. However, the limit lies in the speed limit in GIL and non-database operations. For example, if you want to write a few for loops instead of using array/Mat related function operators, it is impossible to slow down. Due to the existence of GIL, OpenCV runs a single process on py and is controlled in a single core. multithreading is basically useless. To improve efficiency, multiple processes are often required. However, there may be little difference in efficiency because of the skillful technique, it is too uncommon to write a program that is slow for more than a dozen times.
3. The Library is actually the same. PyOpenCV is only a layer of encapsulation.
4. Python is fast, but it is actually a lot of pitfalls. If you say that the "product" works in a production environment and you do not have a deep understanding of python, it would be better to select C ++. If you are familiar with python, or are mainly engaged in fast prototyping and verification ideas, Python has the advantage of saving time and effort in writing. After all, dynamic types provide much convenience, if you are familiar with it, you will not step on it/if you don't care about it, then how can it be convenient. To put it simply, select python or C ++. Consider the following questions:
1. Where is the performance pressure? The GIL of python makes multithreading not multi-core parallel. It must use multiple processes, and python is slower than c ++. Therefore, if it is cpu-intensive, C ++ is recommended. If it is IO-intensive, python is not that bad.
2. high development costs, high operation costs, how much a developer spends a month, and how much a server costs a month. Generally, the former is more expensive, and the latter is vice versa. weigh the advantages and disadvantages, C ++ development is slower than python development. If the performance is up to standard, C ++ is used to offset the development cost if the server cost is saved. Otherwise, python is used. Generally, Python is used for experiment and debugging. Once finalized, C ++ is used to write 1, which is similar. Basically, the call parameters are the same. The format complies with the respective language specifications.
2. There is a significant difference between python and cpp in the program I developed, but the gap between python and cpp is good for working computers. so, the hardware is better configured, there is no problem with using python for real-time processing. In addition, the python function is slower than cpp, although the underlying python function is also lib.
3, basically the same. (Python may be slightly less functional than 2.4.8. A function is not found in python, but that is the same)
4. python is relatively simple and development may be faster (Other parts of the software may be easier to develop ). I think PYTHON is good. The main advantage is that there are too many supported libraries. Understanding algorithms is very helpful for developing prototype products.
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