| 
<?php
 // Load OpenCV extension
 if (!extension_loaded('opencv')) {
 dl('opencv.so'); // Load the OpenCV extension dynamically
 }
 
 // Load the image
 $imagePath = 'path/to/your/image.jpg'; // Change this to the actual path of your image
 $image = cv\imread($imagePath, cv\IMREAD_COLOR);
 
 if ($image === null) {
 die('Could not load image');
 }
 
 // Convert the image to grayscale
 $grayImage = cv\cvtColor($image, cv\COLOR_BGR2GRAY);
 
 // Save the grayscale image
 $grayImagePath = 'path/to/save/gray_image.jpg'; // Change this to the desired path for the output image
 cv\imwrite($grayImagePath, $grayImage);
 
 echo 'Image processed and saved as grayscale.';
 
 |