@@ -12,7 +12,7 @@ |
||
| 12 | 12 | |
| 13 | 13 | $server = new Swoole\WebSocket\Server("0.0.0.0", 8080); |
| 14 | 14 | |
| 15 | -$server->on("start", function (Swoole\WebSocket\Server $server) { |
|
| 15 | +$server->on("start", function(Swoole\WebSocket\Server $server) { |
|
| 16 | 16 | echo "Swoole WebSocket Server is started at ws://0.0.0.0:8080\n"; |
| 17 | 17 | }); |
| 18 | 18 | |
@@ -57,9 +57,9 @@ |
||
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | $server = IoServer::factory( |
| 60 | - new HttpServer( |
|
| 61 | - new WsServer( |
|
| 62 | - new reactApp() |
|
| 63 | - ) |
|
| 64 | - ),8080,'0.0.0.0'); |
|
| 60 | + new HttpServer( |
|
| 61 | + new WsServer( |
|
| 62 | + new reactApp() |
|
| 63 | + ) |
|
| 64 | + ),8080,'0.0.0.0'); |
|
| 65 | 65 | $server->run(); |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -require __DIR__.'/../vendor/autoload.php'; |
|
| 2 | +require __DIR__ . '/../vendor/autoload.php'; |
|
| 3 | 3 | |
| 4 | 4 | use Ratchet\MessageComponentInterface; |
| 5 | 5 | use Ratchet\ConnectionInterface; |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | public function onMessage(ConnectionInterface $from, $msg) { |
| 35 | 35 | foreach ($this->client as $client) { |
| 36 | - if($from !== $client) { |
|
| 37 | - if(!is_null($msg)){ |
|
| 38 | - $this->objDetc->remotePR($client,$msg); |
|
| 36 | + if ($from !== $client) { |
|
| 37 | + if (!is_null($msg)) { |
|
| 38 | + $this->objDetc->remotePR($client, $msg); |
|
| 39 | 39 | } |
| 40 | 40 | else { |
| 41 | 41 | $data = ['id' => $from->resourceId, 'msg' => $msg]; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | protected function yolo() { |
| 54 | - return $this->objDetc = new core(core::MOBILE_NET_V2_VOC,core::DATA_VOC); |
|
| 54 | + return $this->objDetc = new core(core::MOBILE_NET_V2_VOC, core::DATA_VOC); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | } |
@@ -61,5 +61,5 @@ discard block |
||
| 61 | 61 | new WsServer( |
| 62 | 62 | new reactApp() |
| 63 | 63 | ) |
| 64 | - ),8080,'0.0.0.0'); |
|
| 64 | + ), 8080, '0.0.0.0'); |
|
| 65 | 65 | $server->run(); |
@@ -36,8 +36,7 @@ |
||
| 36 | 36 | if($from !== $client) { |
| 37 | 37 | if(!is_null($msg)){ |
| 38 | 38 | $this->objDetc->remotePR($client,$msg); |
| 39 | - } |
|
| 40 | - else { |
|
| 39 | + } else { |
|
| 41 | 40 | $data = ['id' => $from->resourceId, 'msg' => $msg]; |
| 42 | 41 | $client->send(json_encode($data)); |
| 43 | 42 | } |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | use darknet\core; |
| 6 | 6 | $lib = '/home/ghost/bin/c-lib/darknet/data/'; |
| 7 | -$img = ['dog.jpg','eagle.jpg','giraffe.jpg','horses.jpg','person.jpg','kite.jpg','gp.jpg']; |
|
| 7 | +$img = ['dog.jpg', 'eagle.jpg', 'giraffe.jpg', 'horses.jpg', 'person.jpg', 'kite.jpg', 'gp.jpg']; |
|
| 8 | 8 | $dn = new core(core::YOLOFASTEST); |
| 9 | 9 | foreach ($img as $value) { |
| 10 | - $dn->detect($lib.$value); |
|
| 10 | + $dn->detect($lib . $value); |
|
| 11 | 11 | } |
@@ -14,17 +14,17 @@ discard block |
||
| 14 | 14 | class core { |
| 15 | 15 | |
| 16 | 16 | protected const LIBDIR = '/home/ghost/bin/c-lib/darknet/'; |
| 17 | - protected const CFG_FASTEST_YOLO = __DIR__.'/cfg/yolo-fastest.cfg'; |
|
| 18 | - protected const WEIGHT_FASTEST_YOLO = __DIR__.'/weight/yolo-fastest.weights'; |
|
| 19 | - protected const CFG_FASTEST_YOLO_XL = __DIR__.'/cfg/yolo-fastest-xl.cfg'; |
|
| 20 | - protected const WEIGHT_FASTEST_YOLO_XL = __DIR__.'/weight/yolo-fastest-xl.weights'; |
|
| 21 | - protected const CFG_MOBILENET_V2_LITE = self::LIBDIR.'cfg/MobileNetV2-YOLOv3-Lite-coco.cfg'; |
|
| 22 | - protected const WEIGHT_MOBILENET_V2_LITE = self::LIBDIR.'backup/MobileNetV2-YOLOv3-Lite-coco.weights'; |
|
| 23 | - protected const CFG_MOBILENET_V2_VOC = self::LIBDIR.'cfg/MobileNetV2-yolo-Fastest-voc-v2.cfg'; |
|
| 24 | - protected const WEIGHT_MOBILENET_V2_VOC = self::LIBDIR.'backup/MobileNetV2-YOLO-Fastest-voc-v2.weights'; |
|
| 25 | - protected const CFG_VOC_TINY_2 = self::LIBDIR.'cfg/yolov2-tiny-voc.cfg'; |
|
| 26 | - protected const WEIGHT_VOC_TINY_2 = self::LIBDIR.'backup/yolov2-tiny-voc.weights'; |
|
| 27 | - protected const CFG_TINY_2 = self::LIBDIR.'cfg/yolov2-tiny.cfg'; |
|
| 17 | + protected const CFG_FASTEST_YOLO = __DIR__ . '/cfg/yolo-fastest.cfg'; |
|
| 18 | + protected const WEIGHT_FASTEST_YOLO = __DIR__ . '/weight/yolo-fastest.weights'; |
|
| 19 | + protected const CFG_FASTEST_YOLO_XL = __DIR__ . '/cfg/yolo-fastest-xl.cfg'; |
|
| 20 | + protected const WEIGHT_FASTEST_YOLO_XL = __DIR__ . '/weight/yolo-fastest-xl.weights'; |
|
| 21 | + protected const CFG_MOBILENET_V2_LITE = self::LIBDIR . 'cfg/MobileNetV2-YOLOv3-Lite-coco.cfg'; |
|
| 22 | + protected const WEIGHT_MOBILENET_V2_LITE = self::LIBDIR . 'backup/MobileNetV2-YOLOv3-Lite-coco.weights'; |
|
| 23 | + protected const CFG_MOBILENET_V2_VOC = self::LIBDIR . 'cfg/MobileNetV2-yolo-Fastest-voc-v2.cfg'; |
|
| 24 | + protected const WEIGHT_MOBILENET_V2_VOC = self::LIBDIR . 'backup/MobileNetV2-YOLO-Fastest-voc-v2.weights'; |
|
| 25 | + protected const CFG_VOC_TINY_2 = self::LIBDIR . 'cfg/yolov2-tiny-voc.cfg'; |
|
| 26 | + protected const WEIGHT_VOC_TINY_2 = self::LIBDIR . 'backup/yolov2-tiny-voc.weights'; |
|
| 27 | + protected const CFG_TINY_2 = self::LIBDIR . 'cfg/yolov2-tiny.cfg'; |
|
| 28 | 28 | protected const WEIGHT_TINY_2 = self::LIBDIR . 'backup/yolov2-tiny.weights'; |
| 29 | 29 | protected const CFG_TINY_3 = self::LIBDIR . 'cfg/yolov3-tiny.cfg'; |
| 30 | 30 | protected const WEIGHT_TINY_3 = self::LIBDIR . 'backup/yolov3-tiny.weights'; |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | if ($remote) { |
| 94 | 94 | $msg = $this->drawBbox($res); |
| 95 | 95 | echo PHP_EOL; |
| 96 | - echo "FPS:{$this->fps($time)}".PHP_EOL; |
|
| 96 | + echo "FPS:{$this->fps($time)}" . PHP_EOL; |
|
| 97 | 97 | echo "Execution time:" . $this->consumedTime($time) . PHP_EOL; |
| 98 | 98 | unlink($img); |
| 99 | 99 | $this->freeImage($this->image); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | unset($res); |
| 106 | 106 | } |
| 107 | 107 | echo PHP_EOL; |
| 108 | - echo "FPS:{$this->fps($time)}".PHP_EOL; |
|
| 108 | + echo "FPS:{$this->fps($time)}" . PHP_EOL; |
|
| 109 | 109 | echo "Execution time:" . $this->consumedTime($time) . PHP_EOL; |
| 110 | 110 | $this->freeImage($this->image); |
| 111 | 111 | $this->freeDetections($this->dets, $this->numBox); |
@@ -236,11 +236,11 @@ discard block |
||
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | protected function detectObject(FFI\CData $det, $key, $val) { |
| 239 | - return (object) ['label' => $val, 'confidence' => $det->prob[$key], 'box' => $this->bbox2obj($det->bbox)]; |
|
| 239 | + return (object)['label' => $val, 'confidence' => $det->prob[$key], 'box' => $this->bbox2obj($det->bbox)]; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | protected function bbox2Obj(FFI\CData $t) { |
| 243 | - return (object) ['x' => $t->x, 'y' => $t->y, 'w' => $t->w, 'h' => $t->h]; |
|
| 243 | + return (object)['x' => $t->x, 'y' => $t->y, 'w' => $t->w, 'h' => $t->h]; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | protected function gbBox(object $b) { |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | $w = $b->w / 2; |
| 249 | 249 | $x = $b->x; |
| 250 | 250 | $y = $b->y; |
| 251 | - return (object) ['x1' => $x - $w, 'y1' => $y - $h, 'x2' => $x + $w, 'y2' => $y + $h]; |
|
| 251 | + return (object)['x1' => $x - $w, 'y1' => $y - $h, 'x2' => $x + $w, 'y2' => $y + $h]; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | protected function drawBbox($inp, $outFile = null) { |
@@ -537,13 +537,13 @@ discard block |
||
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | protected function fps($startTime) { |
| 540 | - return (1.0/(microtime(true) - $startTime)); |
|
| 540 | + return (1.0 / (microtime(true) - $startTime)); |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | protected function imgInfo($img) { |
| 544 | 544 | list($w, $h) = getimagesize($img); |
| 545 | 545 | $info = pathinfo($img); |
| 546 | - return $this->imgInfo = (object) ['w' => $w, 'h' => $h, 'name' => $info['basename'], 'type' => $info['extension'], 'dir' => $info['dirname']]; |
|
| 546 | + return $this->imgInfo = (object)['w' => $w, 'h' => $h, 'name' => $info['basename'], 'type' => $info['extension'], 'dir' => $info['dirname']]; |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | protected function imgResizeGD($img, $w = 416, $h = 416) { |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare (strict_types=1); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | if (!extension_loaded('swoole')) { |
| 4 | 4 | dl('swoole.so'); |
| 5 | 5 | } |
@@ -8,20 +8,20 @@ discard block |
||
| 8 | 8 | use Swoole\Http\Request; |
| 9 | 9 | use Swoole\WebSocket\Frame; |
| 10 | 10 | |
| 11 | -$wbs = new Server("0.0.0.0",8080); |
|
| 12 | -$wbs->on('start', function(Server $wbs){ |
|
| 11 | +$wbs = new Server("0.0.0.0", 8080); |
|
| 12 | +$wbs->on('start', function(Server $wbs) { |
|
| 13 | 13 | |
| 14 | 14 | }); |
| 15 | 15 | |
| 16 | -$wbs->on('open', function(Server $wbs, Request $req){ |
|
| 16 | +$wbs->on('open', function(Server $wbs, Request $req) { |
|
| 17 | 17 | |
| 18 | 18 | }); |
| 19 | 19 | |
| 20 | -$wbs->on('message', function(Server $wbs, Frame $frame){ |
|
| 20 | +$wbs->on('message', function(Server $wbs, Frame $frame) { |
|
| 21 | 21 | |
| 22 | 22 | }); |
| 23 | 23 | |
| 24 | -$wbs->on('close', function(Server $server, int $fd){ |
|
| 24 | +$wbs->on('close', function(Server $server, int $fd) { |
|
| 25 | 25 | |
| 26 | 26 | }); |
| 27 | 27 | |