Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0532db7

Browse files
committed
debug
1 parent 7a4ee0b commit 0532db7

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

‎src/InstallCommand.php

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class InstallCommand extends Command
1515
{
1616

1717
const EXTENSION_NAME = 'opencv';
18+
const OPENCV_VERSION = '4.0.0';
1819

1920
/**
2021
* Configure the command options.
@@ -26,13 +27,19 @@ protected function configure()
2627
$this
2728
->setName('install')
2829
->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')
3032
// ->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')
3236
;
3337
}
3438

3539

40+
/**
41+
* 检测安装环境
42+
*/
3643
protected function buildEnvDetection()
3744
{
3845
$process = new Process(['./opencv-install-environment-detection.sh']);//给予当前用户
@@ -44,32 +51,59 @@ protected function buildEnvDetection()
4451
}
4552

4653
/**
54+
* 克隆OpenCV项目
55+
* @author hihozhou
56+
*
4757
* @param string $directory
4858
*/
4959
protected function cloneOpenCV(string $directory)
5060
{
61+
$version = self::OPENCV_VERSION;
5162
$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";
5364
$process = new Process($command, $directory, null, null, null);//给予当前用户
5465
$process->setTty(Process::isTtySupported());//检查TTY支持
5566
try {
5667
$process->mustRun();
5768
} catch (\Exception $e) {
58-
throw new RuntimeException($process->getErrorOutput());
69+
throw new RuntimeException('Aborting.');
5970
}
6071
}
6172

6273

74+
/**
75+
* 克隆opencv_contrib项目
76+
* @author hihozhou
77+
*
78+
* @param string $directory
79+
*/
6380
protected function cloneOpenCVContrib(string $directory)
6481
{
82+
$version = self::OPENCV_VERSION;
6583
$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";
6785
$process = new Process($command, $directory, null, null, null);//给予当前用户
6886
$process->setTty(Process::isTtySupported());//检查TTY支持
6987
try {
7088
$process->mustRun();
7189
} 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.');
73107
}
74108
}
75109

@@ -93,8 +127,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
93127
throw new RuntimeException('The OpenCV PHP extension is installed.');
94128
}
95129
$this->buildEnvDetection();
130+
$this->findExistOpenCV($output);
131+
96132
//创建目录
97-
$directory = $input->getArgument('opencv_build_path');
133+
$directory = $input->getOption('path');
98134
$output->writeln("Compile the directory of opencv with {$directory}.");
99135
if (!file_exists($directory)) {
100136
$output->writeln("Create {$directory} of the directory");
@@ -108,6 +144,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
108144
}
109145
$this->cloneOpenCV($directory);
110146
$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';
111156
//编译安装
112157
$output->writeln('<comment>Application ready! Build something amazing.</comment>');
113158
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /