title: PHP opencv Parse error: syntax error, unexpected '{',
body: <p>i downloaded php opencv library but i get the following error;</p>
  <p>[08-Dec-2020 19:31:29 Europe/Istanbul] PHP Fatal error:  Uncaught Error: Call to undefined function CV\imread() in /home/yusufkar/opencv.yusufkarakaya.com.tr/detect_objects_by_dnn_mobilenet.php:11
  Stack trace:
  #0 {main}
  thrown in /home/yusufkar/opencv.yusufkarakaya.com.tr/detect_objects_by_dnn_mobilenet.php on line 11</p>
  <p>php file;</p>
  <pre><code>&lt;?php
  
  use CV\Scalar;
  use function CV\imread;
  use function CV\cvtColor;
  
  //$categories = explode(&quot;\n&quot;, file_get_contents('models/ssd_mobilenet_v1_coco/classes.txt'));
  $categories = explode(&quot;\n&quot;, file_get_contents('models/ssdlite_mobilenet_v2_coco/classes.txt'));
  
  $src = imread(&quot;images/objects.jpg&quot;); // opencv loads image to matrix with BGR order
  //var_export($src);
  
  $blob = \CV\DNN\blobFromImage($src, 0.017, new \CV\Size(300,300), new Scalar(127.5, 127.5, 127.5), true, false); // convert image to 4 dimensions matrix
  //var_export($blob);
  
  //$net = \CV\DNN\readNetFromTensorflow('models/ssd_mobilenet_v2_coco/frozen_inference_graph.pb', 'models/ssd_mobilenet_v2_coco/ssd_mobilenet_v2_coco.pbtxt');
  //$net = \CV\DNN\readNetFromTensorflow('models/ssd_mobilenet_v1_coco/frozen_inference_graph.pb', 'models/ssd_mobilenet_v1_coco/ssd_mobilenet_v1_coco.pbtxt');
  $net = \CV\DNN\readNetFromTensorflow('models/ssdlite_mobilenet_v2_coco/frozen_inference_graph.pb', 'models/ssdlite_mobilenet_v2_coco/ssdlite_mobilenet_v2_coco.pbtxt');
  $net-&gt;setInput($blob, &quot;&quot;);
  
  $r = $net-&gt;forward();
  var_export($r);
  
  $rectangles = [];
  for ($i = 0; $i &lt; $r-&gt;shape[2]; $i++) {
      $classId = $r-&gt;atIdx([0,0,$i,1]);
      $confidence = intval($r-&gt;atIdx([0,0,$i,2]) * 100);
      if ($classId &amp;&amp; $confidence &gt; 30) {
          $startX = $r-&gt;atIdx([0,0,$i,3]) * $src-&gt;cols;
          $startY = $r-&gt;atIdx([0,0,$i,4]) * $src-&gt;rows;
          $endX = $r-&gt;atIdx([0,0,$i,5]) * $src-&gt;cols;
          $endY = $r-&gt;atIdx([0,0,$i,6]) * $src-&gt;rows;
  
          $scalar = new Scalar(0, 0, 255);
          \CV\rectangle($src, $startX, $startY, $endX, $endY, $scalar, 2);
  
          $text = &quot;{$categories[$classId]} $confidence%&quot;;
          \CV\rectangle($src, $startX, $startY + 10, $startX + 20 * strlen($text), $startY - 30, new Scalar(255,255,255), -2);
          \CV\putText($src, &quot;{$categories[$classId]} $confidence%&quot;, new \CV\Point($startX, $startY - 2), 0, 1.5, new Scalar(), 2);
      }
  }
  
  \CV\imwrite(&quot;results/_detect_objects_by_dnn_mobilenet.png&quot;, $src);
  </code></pre>
  <p>Github php opencv: <a href="https://github.com/php-opencv/php-opencv-examples" rel="nofollow noreferrer">https://github.com/php-opencv/php-opencv-examples</a></p>