1. Go to this page and download the library: Download alkauni/planogrid library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Alkauni\Planogrid\PlanogramProcessor;
use Alkauni\Planogrid\DTO\PlanogramTemplate;
use Alkauni\Planogrid\DTO\PlanogramRow;
use Alkauni\Planogrid\DTO\PlanogramItem;
use Alkauni\Planogrid\Strategies\VerticalIoUStrategy;
// 1. Define Target Planogram Template (Ideal Grid Layout)
$expectedTemplate = new PlanogramTemplate([
// Row 1 (Top Shelf)
new PlanogramRow([
new PlanogramItem('Product Alpha 250ml'),
new PlanogramItem('Product Beta 500ml'),
]),
// Row 2 (Bottom Shelf)
new PlanogramRow([
new PlanogramItem('Product Gamma 1L'),
new PlanogramItem('Product Delta 100g'),
]),
]);
// 2. Load Input Photo Binary
$imageBinary = file_get_contents('shelf_photo.jpg');
// 3. Execute Complete Verification Workflow
$processor = new PlanogramProcessor();
$evaluation = $processor
->setRowStrategy(new VerticalIoUStrategy())
->setThresholdScore(100.0) // Compliance score threshold (100%)
->verify(
imageBinary: $imageBinary,
customLabels: $customLabels,
expectedTemplate: $expectedTemplate,
imageWidth: 1000,
imageHeight: 1000
);
// 4. Inspect Verification Results
echo "Status: " . $evaluation->getStatus(); // "correct" or "incorrect"
echo "Compliance Score: " . $evaluation->getComplianceScore() . "%";
echo "Matched Items: " . $evaluation->getMatchedCount() . " of " . $evaluation->totalExpected;
// 5. Save Annotated Output PNG Image
file_put_contents('output_annotated.png', $evaluation->getAnnotatedImage());
use Alkauni\Planogrid\DTO\ImageAnnotationConfig;
$config = new ImageAnnotationConfig(
matchColor: '#00d400', // Green for match
mismatchColor: '#ff0000', // Red for mismatch
lowConfidenceColor: '#ffcc00', // Yellow for low confidence
confidenceThreshold: 85.0, // Items with < 85% confidence get yellow box
fontPath: '/path/to/Inter.ttf', // Custom TTF Font
fontSize: 14,
borderThickness: 2,
adaptiveFontSize: true,
showConfidenceText: true
);
$processor->setImageConfig($config);
new ImageAnnotationConfig(
string $matchColor = '#00d400', // HEX color for matched items
string $mismatchColor = '#ff0000', // HEX color for mismatched/competitor items
string $lowConfidenceColor = '#ffcc00', // HEX color for low confidence score items
float $confidenceThreshold = 85.0, // Confidence score threshold (%)
?string $fontPath = null, // Path to custom TrueType font (.ttf) file
int $fontSize = 12, // Base font size
int $borderThickness = 2, // Bounding box border line thickness (px)
bool $adaptiveFontSize = true, // Auto font sizing based on product name length
bool $showConfidenceText = true // Render confidence score percentage text tag
);
use Alkauni\Planogrid\PlanogramProcessor;
class PlanogramController extends Controller
{
public function verify(Request $request, PlanogramProcessor $processor)
{
$evaluation = $processor->verify(
imageBinary: $request->file('photo')->get(),
customLabels: $request->input('custom_labels'),
expectedTemplate: $expectedTemplate
);
return response()->json($evaluation->toArray());
}
}