PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Ahmed Abdulla   PHP Grayscale Image with OpenCV   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Main Code
Class: PHP Grayscale Image with OpenCV
Convert an image to a grayscale using OpenCV
Author: By
Last change:
Date: 5 months ago
Size: 678 bytes


Class file image Download

// Load OpenCV extension
if (!extension_loaded('opencv')) {
dl(''); // 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) {
'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);

'Image processed and saved as grayscale.';