Run the opencv-based program on another machine-instance

Source: Internet
Author: User

ArticleThe solution is as follows:


Scenario 1:Will be able to run on your computer based on opencvEngineeringCopy the file to someone else's (mainly a teacher) computer, avoiding the need for other people to configure library files, directory files, and Lib.

Scenario 2:Will be able to run on your computer based on opencvProgram(Exe)Copy to a computer without a CV library for demonstration.


1. First, let's take a look at your specific configuration process: the configuration principle can be found in the previous blogHttp://blog.csdn.net/lanbing510/article/details/8806602.

1. Copy the include folder under the \ opencv \ build directory and the bin and Lib folders under \ opencv \ build \ x86 \ VC10 to the directory where the project is located (and C ++ project or stdafx. h ).

2. Add a directory. In order to implement scenario 1, you need to use a relative path. First, use the relative path to perform the popular science program,'.\'Represents the current directory,'..\'Indicates the parent directory. Note:'\'It is a VC reserved word, so you need to use '\' instead of '\' when writing a program. Use '/' for the network path '/'. The specific configuration is as follows:



The link configuration is as usual. You only need to add these commonly used Lib:

Opencv_nonfree243d.lib
Opencv_legacy243d.lib
Opencv_imgproc243d.lib
Opencv_core243d.lib
Opencv_highgui243d.lib
Opencv_video243d.lib
Opencv_ml243d.lib
Opencv_features2d243d.lib


2. After compilation, put the corresponding DLL file in the directory where the EXE is located. However, if there are too many DLL files, it looks very bloated and you want to put different folders in the DLL file set, then let the program be selected when running the program. One way is to set the environment variable, but the problem arises.The instructor asks you to configure the environment variables on the spot. If the other party does not have the corresponding library, let alone the corresponding environment variable settings.

The solution is to make the following configuration (the premise is that the bin of the DLL folder has been copied to the project directory in step 1 ):



That is, set path in the Environment option, so that you can also use the DLL in Multiple folders. Concise and clear.

3. Compile and run the above configurations.


2. Make a simple prompt on Case 2.

If the recipient does not needSource codeAnd project, only used for display, you can directly copy the bin folder to the directory where the EXE file is located (vs generally asks the debug or release folder), but you will find that, double-click EXE and you will not be able to run normally. Instead, you will be prompted that you cannot find the DLL, as mentioned above, it is impossible for you to run the program without configuring environment variables or placing the DLL file in the directory at the same level as the exe. However, to do a demonstration, it cannot be too ugly. an EXE attachment contains various DLL files, there are two ways to do this:


1. Use the batch processing method, that is, to write a bat, setpath first, and then run your EXE, but it is still not beautiful. When you run a BAT file instead of EXE for everyone to see.

2. For details, refer to method 2. You can write a shell and use ShellExecuteCall exe. Very easy, very short command.

Paste the shell program I wrote below

 

# Include <windows. h> # include <iostream> using namespace STD; # define exename _ T ("motion_ds.exe") # define dllpath _ T (". \ bin ") int _ tmain (INT argc, _ tchar * argv []) {try {ShellExecute (null, null, exename, null, dllpath, sw_show );} catch (...) {STD: cout <"exception occurred. Check the source program" <exename <STD: Endl;} return 0 ;}


Put shell.exe behind the compilation and operationMotion_ds.EXEDirectory, SetMotion_ds.Put exein the binfolder. During demonstration, you only need to double-click shell.exe.

Parameters and common instances attached with ShellExecute

---------------------------------------------------------------------------

ShellExecute (hwnd: hwnd; {Specify parent window handle} Operation: pchar; {Specified action, such as open and print} Filename: pchar; {Specify the file or program to open} Parameters: pchar; {Specify parameters for the program to be opened; if the file is opened, it should be nil} Directory: pchar; {Default directory} Showcmd: integer {Open option} ): Hinst; {If the execution succeeds, the application handle is returned. If the value is <= 32, the execution error is returned}  // Possible errors returned include: = 0  {Insufficient memory} Error_file_not_found = 2 ; {File name error} Error_path_not_found = 3 ; {Path name error} Error_bad_format = 11 ; {The EXE file is invalid} Se_err_share = 26 ; {Shared error} Se_err_associncomplete = 27 ;{The file name is incomplete or invalid} Se_err_ddetimeout = 28 ; {Timeout} Se_err_ddefail = 29 ; {DDE Transaction Failed} Se_err_ddebusy = 30 ; {Another DDE transaction is being processed, but this DDE transaction cannot be completed} Se_err_noassoc = 31 ; {No associated applications}  // Showcmd parameter value options: Sw_hide = 0 ; {Hide} Sw_shownormal = 1 ; {Display with the nearest size and position, activate} Sw_normal = 1 ; {Same as sw_shownormal} Sw_showminimized = 2 ; {Minimize, activate} Sw_showmaximized = 3 ; {Maximize, activate} Sw_maximize = 3 ; {Same as sw_showmaximized} Sw_shownoactivate = 4 ; {Display with the nearest size and position, not activated} Sw_show = 5 ; {Same as sw_shownormal} Sw_minimize = 6 ;{Minimized, not activated} Sw_showminnoactive = 7 ; {Same as sw_minimize} Sw_showna = 8 ; {Same as sw_shownoactivate} Sw_restore = 9 ; {Same as sw_shownormal} Sw_showdefault = 10 ; {Same as sw_shownormal} Sw_max = 10 ; {Same as sw_shownormal} 
// Example to illustrate more issues (don't forget uses shellapi ;):{For example, open a file in Notepad}BeginShellExecute (handle,'Open','Notepad.exe','C: \ windows \ schedlgu. txt',Nil, Sw_shownormal );End;
 
{The first parameter is used as the parent window of the error Prompt window. It cannot be nil or 0 (desktop window )}BeginShellExecute (0,'Open','Notepad.exe','C: \ windows \ schedlgu. txt',Nil, Sw_shownormal );End;
{If the second parameter is nil, the default value is open}BeginShellExecute (0,Nil,'Notepad.exe','C: \ windows \ schedlgu. txt',Nil, Sw_shownormal );End;
 
{File path can be placed in parameter 5}BeginShellExecute (0,Nil,'Notepad.exe','Schedlgu. txt','C: \ Windows', Sw_shownormal );End;
{Specify parameter 3 as the file to be opened. The file will be opened using the corresponding default program. Number of times parameter 4 should be nil}BeginShellExecute (0,Nil,'Schedlgu. txt',Nil,'C: \ Windows', Sw_shownormal );End;
 
{If the file is in the program directory/current directory/system32/Windows/PATH environment variable, parameter 5 can also be nil}BeginShellExecute (0,Nil,'Schedlgu. txt',Nil,Nil, Sw_shownormal );End;
{If parameter 3 is a file, run parameter 2 to print it}BeginShellExecute (0,'Print','Schedlgu. txt',Nil,Nil,1);End;
 
{Open web page with IE}BeginShellExecute (handle,'Open','Iw.e. EXE','About: blank',Nil, Sw_shownormal );End;
{Open a webpage with Firefox}BeginShellExecute (handle,'Open','Firefox.exe','About: blank',Nil, Sw_shownormal );End;
 
{Open the webpage with the default browser}BeginShellExecute (handle,'Open','Assumer.exe','About: blank',Nil, Sw_shownormal );End;
  {use the default browser to open the webpage}  begin  ShellExecute (0,  nil , 'HTTP: // del.cnblogs.com ',  nil ,  nil , 1), and  end ;  

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.