@@ -15,6 +15,7 @@ class InstallCommand extends Command
15
15
{
16
16
17
17
const EXTENSION_NAME = 'opencv ' ;
18
+ const OPENCV_VERSION = '4.0.0 ' ;
18
19
19
20
/**
20
21
* Configure the command options.
@@ -26,13 +27,19 @@ protected function configure()
26
27
$ this
27
28
->setName ('install ' )
28
29
->setDescription ('Automatic installation of the php-opencv extension, including automatic installation of opencv (if no opencv is installed) ' )
29
- ->addArgument ('opencv_build_path ' , InputArgument::OPTIONAL , 'Automatically install the opencv directory ' , '/opt/opencv ' )
30
+ // ->addArgument('opencv_build_path', InputArgument::OPTIONAL, 'Automatically install the opencv directory', '/opt/opencv')
31
+ // ->addArgument('version', InputArgument::OPTIONAL, 'Automatically install the opencv directory', '/opt/opencv')
30
32
// ->addOption('dev', null, InputOption::VALUE_NONE, 'Installs the latest "development" release')
31
- // ->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces install even if the directory already exists')
33
+ // ->addOption('edition', 'e', InputOption::VALUE_REQUIRED, 'Automatically install the opencv directory', '/opt/opencv')// ->addOption('php-opencv-version', 'pov', InputOption::VALUE_NONE, 'Specify the installed php-opencv version')
34
+ ->addOption ('path ' , 'p ' , InputOption::VALUE_REQUIRED , 'Automatically install the opencv directory ' , '/opt/opencv ' )// ->addOption('php-opencv-version', 'pov', InputOption::VALUE_NONE, 'Specify the installed php-opencv version')
35
+ // ->addOption('enable-contrib', null, InputOption::VALUE_REQUIRED, 'Automatically install the opencv directory', false)// ->addOption('php-opencv-version', 'pov', InputOption::VALUE_NONE, 'Specify the installed php-opencv version')
32
36
;
33
37
}
34
38
35
39
40
+ /**
41
+ * 检测安装环境
42
+ */
36
43
protected function buildEnvDetection ()
37
44
{
38
45
$ process = new Process (['./opencv-install-environment-detection.sh ' ]);//给予当前用户
@@ -44,32 +51,59 @@ protected function buildEnvDetection()
44
51
}
45
52
46
53
/**
54
+ * 克隆OpenCV项目
55
+ * @author hihozhou
56
+ *
47
57
* @param string $directory
48
58
*/
49
59
protected function cloneOpenCV (string $ directory )
50
60
{
61
+ $ version = self ::OPENCV_VERSION ;
51
62
$ opencvUrl = 'https://github.com/opencv/opencv.git ' ;
52
- $ command = "sudo git clone {$ opencvUrl } --depth 1 " ;
63
+ $ command = "sudo git clone {$ opencvUrl } --branch { $ version } -- depth 1 " ;
53
64
$ process = new Process ($ command , $ directory , null , null , null );//给予当前用户
54
65
$ process ->setTty (Process::isTtySupported ());//检查TTY支持
55
66
try {
56
67
$ process ->mustRun ();
57
68
} catch (\Exception $ e ) {
58
- throw new RuntimeException ($ process -> getErrorOutput () );
69
+ throw new RuntimeException (' Aborting. ' );
59
70
}
60
71
}
61
72
62
73
74
+ /**
75
+ * 克隆opencv_contrib项目
76
+ * @author hihozhou
77
+ *
78
+ * @param string $directory
79
+ */
63
80
protected function cloneOpenCVContrib (string $ directory )
64
81
{
82
+ $ version = self ::OPENCV_VERSION ;
65
83
$ opencvContribUrl = 'https://github.com/opencv/opencv_contrib.git ' ;
66
- $ command = "sudo git clone {$ opencvContribUrl } --depth 1 " ;
84
+ $ command = "sudo git clone {$ opencvContribUrl } --branch { $ version } -- depth 1 " ;
67
85
$ process = new Process ($ command , $ directory , null , null , null );//给予当前用户
68
86
$ process ->setTty (Process::isTtySupported ());//检查TTY支持
69
87
try {
70
88
$ process ->mustRun ();
71
89
} catch (\Exception $ e ) {
72
- throw new RuntimeException ($ process ->getErrorOutput ());
90
+ throw new RuntimeException ('Aborting. ' );
91
+ }
92
+ }
93
+
94
+
95
+ protected function findExistOpenCV (OutputInterface $ output )
96
+ {
97
+ $ output ->writeln ('Try to find the installed OpenCV on the system via pkg-config... ' );
98
+ $ process = new Process ('pkg-config --modversion opencv4 ' );//给予当前用户
99
+ try {
100
+ $ process ->mustRun ();
101
+ $ existOpencvVersion = $ process ->getOutput ();
102
+ $ output ->writeln ('Found, opencv version is ' . $ existOpencvVersion );
103
+
104
+ } catch (\Exception $ e ) {
105
+ //没有检测到opencv
106
+ $ output ->writeln ('Did not find opencv installed on the system. ' );
73
107
}
74
108
}
75
109
@@ -93,8 +127,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
93
127
throw new RuntimeException ('The OpenCV PHP extension is installed. ' );
94
128
}
95
129
$ this ->buildEnvDetection ();
130
+ $ this ->findExistOpenCV ($ output );
131
+
96
132
//创建目录
97
- $ directory = $ input ->getArgument ( ' opencv_build_path ' );
133
+ $ directory = $ input ->getOption ( ' path ' );
98
134
$ output ->writeln ("Compile the directory of opencv with {$ directory }. " );
99
135
if (!file_exists ($ directory )) {
100
136
$ output ->writeln ("Create {$ directory } of the directory " );
@@ -108,6 +144,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
108
144
}
109
145
$ this ->cloneOpenCV ($ directory );
110
146
$ this ->cloneOpenCVContrib ($ directory );
147
+ //
148
+ $ commands = [
149
+ 'cd opencv '
150
+ ];
151
+ $ cloneOpenCVDirectory = $ directory . '/opencv ' ;
152
+ $ commands = [
153
+ 'mkdir build '
154
+ ];
155
+ $ command = 'mkidr && cd build ' ;
111
156
//编译安装
112
157
$ output ->writeln ('<comment>Application ready! Build something amazing.</comment> ' );
113
158
}
0 commit comments