; Author: Zian Choy ; Software License: GPLv3 ; Contact Information & Website: http://www.zianchoy.com ; Copyright 2011 Zian Choy ; This program is free software: you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version. ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; You should have received a copy of the GNU General Public License ; along with this program. If not, see . #RequireAdmin ; 1. Check to make sure we don't already have the latest version installed. :) ; 2. Detect if they have VS 2008 or 2010. (if they have both, ask if they going to use Visual Studio 2008, 2010, or both) ; 3. Prompt the user to hit the button to launch a browser and go to http://sourceforge.net/projects/emgucv/files/emgucv/2.2.1/libemgucv-windows-x86-2.3.0.1416.exe/download ; and download the file. ; 4. Install EmguCV to the default location ; 5. Get OpenCV (either install it or find it) ; 6. Copy the right set of DLLs over to EmguCV. ; 7. Launch a non-blocking browser instance to a video/instructions for setting up a VS 2008 (or 2010...) project in C# and VB .Net that uses EmguCV. Global Const $latestEmguCVVersion = "2.3.0.1416" Global Const $screencastURL = "http://www.youtube.com/watch?v=_bXMOC-63iM" Global $visualStudioVersion If MsgBox(4, "License Agreements", "Do you agree to the conditions of the GPL version 3 with regards to this installer and EmguCV?" & @LF & @LF & "The GPL version 3 license may be read at .") <> 6 Then Exit ElseIf RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\emgucv-windows-x86\", "DisplayVersion") = $latestEmguCVVersion Then MsgBox(0, "EmguCV Already Installed", "You already have EmguCV version " & $latestEmguCVVersion & " installed." & @LF & "Hooray!") ElseIf @OSArch <> "X86" Then MsgBox(0, "Cannot Install On Your Computer", "This installer can only run on 32-bit operating systems.") ElseIf GetVisualStudioVersion() = "" Then MsgBox(0,"Visual Studio Not Installed", "Install Visual Studio 2008 or 2010 before installing EmguCV.") ElseIf StringInStr(@ProgramsDir, "C:\") = 0 Then MsgBox(64, "Must Install To Local Drives", "This installer only works when the default drive for storing programs is C:\.") Else ; We already know that we'll get something back this time :) $visualStudioVersion = GetVisualStudioVersion() If DownloadAndInstallEmguCV() = 1 Then If FindOrGetOpenCV() = True Then If MsgBox(4, "Finished Installing EmguCV", "EmguCV and OpenCV are ready for use." & @LF & @LF & "The OpenCV DLLs for your Visual Studio projects have been copied to C:\Emgu\emgucv-windows-x86 2.3.0.1416\OpenCV DLLs." & @LF & @LF & "Do you want to watch a screencast to learn how to create a Hello World project with EmguCV and Visual Studio?") = 6 Then ShellExecute($screencastURL) EndIf Else MsgBox(64, "Could Not Finish Installing", "The necessary OpenCV files could not be found, installed, or both." & @LF & "Your web browser will be launched to show you how to copy the DLLs manually.") ShellExecute("http://www.emgu.com/wiki/index.php/Download_And_Installation#Have_you_copied_the_OpenCV_dlls_to_the_execution_directory.3F") EndIf Else MsgBox(64, "Could Not Finish Installing", "There was a problem copying a file." & @LF & "Your web browser will be launched to show you how to install EmguCV manually.") ShellExecute("http://www.emgu.com/wiki/index.php/Download_And_Installation") EndIf EndIf Func FindOrGetOpenCV() ; EmguCV 1.2.2.0 was released when OpenCV version 1.0 was state of the art. We assume that EmguCV remains compatible with all OpenCV versions from that OpenCV version onwards. Local $openCVFolder; Local $openCVFoundAndFinished = false If MsgBox(4, "Finding OpenCV", "Is OpenCV installed on this computer?" & @LF & "Select No if you aren't sure.") = 6 Then $openCVFolder = FileSelectFolder("Select the OpenCV folder", "") If $openCVFolder = "" Then If MsgBox(4, "Finding OpenCV", "Couldn't find OpenCV inside " & $openCVFolder & "." & @LF & "Do you want to download and install the latest version of OpenCV?") = 6 Then $openCVFoundAndFinished = GetOpenCVAndCopyDLLs() EndIf Else $openCVFoundAndFinished = CopyOpenCVDLLs($openCVFolder) If $openCVFoundAndFinished = false Then If MsgBox(4, "Finding OpenCV", "Couldn't find OpenCV inside " & $openCVFolder & "." & @LF & "Do you want to download and install the latest version of OpenCV?") = 6 Then $openCVFoundAndFinished = GetOpenCVAndCopyDLLs() EndIf EndIf EndIf Else $openCVFoundAndFinished = GetOpenCVAndCopyDLLs() EndIf Return $openCVFoundAndFinished EndFunc Func CopyOpenCVDLLs($openCVFolder) Local $result = false Local $destinationFolder = "C:\Emgu\emgucv-windows-x86 2.3.0.1416\OpenCV DLLs" Local $originalDestinationFolder = $destinationFolder Local $counter = 0 If FileExists($destinationFolder) = 1 Then While (FileExists($destinationFolder) = 0) $destinationFolder = $originalDestinationFolder & $counter $counter = $counter + 1 WEnd EndIf DirCreate($destinationFolder) If CopyDLL($openCVFolder & "\bin\", "opencv_calib3d", $destinationFolder) = "success" Then If CopyDLL($openCVFolder & "\bin\", "opencv_contrib", $destinationFolder) = "success" Then If CopyDLL($openCVFolder & "\bin\", "opencv_core", $destinationFolder) = "success" Then If CopyDLL($openCVFolder & "\bin\", "opencv_features2d", $destinationFolder) = "success" Then If CopyDLL($openCVFolder & "\bin\", "opencv_highgui", $destinationFolder) = "success" Then If CopyDLL($openCVFolder & "\bin\", "opencv_imgproc", $destinationFolder) = "success" Then If CopyDLL($openCVFolder & "\bin\", "opencv_legacy", $destinationFolder) = "success" Then ;BUG REPORT HERE for EmguCV :) If CopyDLL($openCVFolder & "\bin\", "opencv_objdetect", $destinationFolder) = "success" Then If CopyDLL($openCVFolder & "\bin\", "opencv_video", $destinationFolder) = "success" Then $result = true EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf Return $result EndFunc Func CopyDLL($openCVFolder, $dll, $destinationFolder) Local $result = "failed" Local $searchHandle = FileFindFirstFile($openCVFolder & $dll & "*.dll") Local $dllToCopy If $searchHandle <> -1 Then $dllToCopy = $openCVFolder & "\" & FileFindNextFile($searchHandle) While (@error <> 1) FileCopy($dllToCopy, $destinationFolder) $dllToCopy = $openCVFolder & "\" & FileFindNextFile($searchHandle) WEnd FileClose($searchHandle) $result = "success" Else MsgBox(0, "", $openCVFolder & ", " & $dll & ", " & $destinationFolder) EndIf Return $result EndFunc Func GetOpenCVAndCopyDLLs() Local $installPath = "C:\OpenCV For EmguCV" Local $originalInstallPath = $installPath Local $counter = 0 Local $success = false; MsgBox(0, "Download OpenCV", "Your browser will appear and go to the download page for OpenCV." & @LF & "Download the file and save it to the same place as this installer." & @LF & "Click OK to launch your browser.") ShellExecute("http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.3.1/OpenCV-2.3.1-win-superpack.exe/download") While FileExists("OpenCV-2.3.1-win-superpack.exe") = 0 Sleep(3000) WEnd RemoveZoneIdentifier("OpenCV-2.3.1-win-superpack.exe") If FileExists($installPath) = 1 Then While (FileExists($installPath) = 0) $installPath = $originalInstallPath & $counter $counter = $counter + 1 WEnd EndIf ; extract the files ("Enter") ; Copy the entire folder ; Set the installpath to OpenCV2.3\build\x86\vc[XX] ; Silently installs it ShellExecute("OpenCV-2.3.1-win-superpack.exe") WinWait("7-Zip self-extracting archive") WinActivate("7-Zip self-extracting archive") Send("{ENTER}") ProcessWaitClose("OpenCV-2.3.1-win-superpack.exe") DirCreate($installPath) DirCopy(@ScriptDir & "\OpenCV2.3", $installPath, 1) While True Sleep (10) If DirGetSize(@ScriptDir & "\OpenCV2.3") = DirGetSize($installPath) Then ExitLoop EndIf WEnd If $visualStudioVersion = "2008" Then $installPath = $installPath & "\build\x86\vc9" ElseIf $visualStudioVersion = "2010" Then $installPath = $installPath & "\build\x86\vc10" EndIf If $visualStudioVersion = "2008" Or $visualStudioVersion = "2010" Then $success = CopyOpenCVDlls($installPath) EndIf Return $success EndFunc Func DownloadAndInstallEmguCV() Local Const $redistWindowTitle = "Microsoft Visual C++ 2008 Redistributable Setup" Local Const $debuggerVisualizerTitle = "emgucv-windows-x86 2.3.0.1416 Setup" Local $extractResult = FileInstall("libemgucv-windows-x86-2.3.0.1416.exe", @TempDir & "\libemgucv-windows-x86-2.3.0.1416.exe", 1) Local $success = false If $extractResult = 1 Then ; Silently installs it ShellExecute(@TempDir & "\libemgucv-windows-x86-2.3.0.1416.exe", "/S") ProcessWait("vcredist_x86.exe") ProcessWait("install.exe") If WinWait($redistWindowTitle, "", 60) <> 0 Then If ControlCommand($redistWindowTitle,"", 289, "IsEnabled") = 0 Then ; Click Cancel, and then Yes WinActivate($redistWindowTitle) ControlClick($redistWindowTitle, "", 2) WinWait($redistWindowTitle) ControlClick($redistWindowTitle, "", 6) WinWait($redistWindowTitle) ControlClick($redistWindowTitle, "", 2) EndIf ProcessWaitClose("vcredist_86.exe") EndIf If WinWait($debuggerVisualizerTitle, "", 60) <> 0 Then Sleep(3000) WinActivate($debuggerVisualizerTitle) ControlClick($debuggerVisualizerTitle, "", 6) EndIf $success = true EndIf Return $success EndFunc Func GetVisualStudioVersion() Local $version = "" If RegRead("HKCR\VisualStudio.DTE.10.0", "") = "" and RegRead("HKCR\VisualStudio.DTE.9.0", "") <> "" Then $version = "2008" ElseIf RegRead("HKCR\VisualStudio.DTE.10.0", "") <> "" Then $version = "2010" ElseIf RegRead("HKCR\VisualStudio.DTE.10.0", "") <> "" and RegRead("HKCR\VisualStudio.DTE.9.0", "") <> "" then $version = "2008" If StringInStr(InputBox("Select Visual Studio Version", "Enter the name of the Visual Studio version you wish to use EmguCV with.", "Visual Studio 2010"), "2008") Then $version = "2010" EndIf EndIf Return $version EndFunc Func NumberOfSubkeys($registryKey) Local $counter = 1 While True RegEnumKey ($registryKey, $counter) If @error <> 0 Then ExitLoop EndIf $counter = $counter + 1 WEnd Return $counter - 1 EndFunc Func RemoveZoneIdentifier($filepath) FileClose(FileOpen($filepath & ":" & "Zone.Identifier",2)) EndFunc