[Opencv] Run the opencv program on a computer without opencv installed

Source: Internet
Author: User
Exercise every Monday from opencv · China:

When we are working on a project, we usually need to run programs that depend on opencv, vs (for example, vs2005), or VC (for example, vc6.0) on computers that do not have the relevant environment installed. So what methods can be used to get rid of these dependencies? (10 points for providing feasible suggestions)

Http://www.opencvchina.com/thread-1368-1-1.html

The above kids shoes are fully spoken. I will try again to understand them ~

Opencv Installation

The downloaded opencv installation package generally includes the source code, examples, documents, and compiled dynamic link library (in the past, opencv may need to be compiled by itself. After opencv2.3.1, there is a build folder, compiled mingw, vc9, and VC10 versions ).
If we write code to call the opencv function, we need to add additional dependencies:
Include directories:C: \ opencv \ OpenCV-2.4.2 \ build \ include
Library diractories:C: \ opencv \ OpenCV-2.4.2 \ build \ x86 \ VC10 \ Lib
Then you needLinker-> input-> additional dependenciesXX. Lib, xxd. Lib
There are also two bin folders:
C: \ opencv \ OpenCV-2.4.2 \ build \ x86 \ VC10 \ bin
C: \ opencv \ OpenCV-2.4.2 \ build \ common \ TBB \ ia32 \ VC10
AddSystem environment directory
Some installation tutorials also teach us how to add the opencv source code file in source directories, which is not required. Because the actual call of functions in opencv is the DLL implicit call method.

DLL call

Implicit call is generally required:

Declare the. h file of the function interface-- Include contents in the folder
Link the. Lib file of the dynamic library-- Content in the Lib folder and XX. Lib added by input-> additional dependencies
Dynamic Link Library. dll file-- Bin folder content
The bin folder is in the system environment directory, so the Execution Code can be found in the EXE file. You can also copy the required DLL files to the same folder of the EXE file.
Therefore, if you copy an unpublished project to a computer without opencv, you only need to pass the. H,. Lib, And. DLL files related to the function you need.

Another way to call the DLL is to display the call:

It is shown that the. lib and. H files are not required for calling. Only DLL files are used.

However, you need to "display" the function to be used in the code. For example:

Hinstance hdll = NULL; // hdll = loadlibrary ("opencv_core242d.dll"); // load dllhmat myimread = (hmat) getprocaddress (hdll, "imread "); // use the functions in the DLL

In this way, only the DLL files used can be copied during project copying.
However, this code is very difficult to write, and there are many changes to DLL name versions and so on, which are generally not used much.

Static compiled exe program

If you only give others an EXE program with static links, such as a demo, you do not need to run the program.

The most common method is to copy the EXE and DLL files together to the target computer:
That is, copy the required DLL files to the EXE folder, and copy XX. dll from release and xxd. dll from debug.
(So we should try not to write the additional dependencies, so there will be fewer DLL copies ~)

Another method is to compile the opencv source code together with the executable file mentioned above.

When writing code, you need to add the source file of opencv to the project. That is, add the. cpp file directory used to the source directories item.
Compile the header file and you may encounter errors such as "cannot find the end of the file". In the project attribute category, select "precompiled headers" and "not using precompiled headers.

In this way, the project does not call the DLL files compiled by opencv, but uses opencv as the files you write.

You only need to copy the final EXE file on the computer where opencv is not installed. No DLL file is required, but the generated exe will be large ~

Reprinted please indicate the source: http://blog.csdn.net/xiaowei_cqu/article/details/8066329

Related Article

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.