$count) { echo " {$size}: {$count} rectangles\n"; } // Check for white background $whiteRects = array_filter($matches, fn($m) => $m[5] === 'white'); if (count($whiteRects) > 0) { $firstWhite = $whiteRects[array_key_first($whiteRects)]; echo "\nWhite background:\n"; echo " Size: {$firstWhite[3]}x{$firstWhite[4]}\n"; echo " Position: ({$firstWhite[1]}, {$firstWhite[2]})\n"; } // Check if coordinates are consistent echo "\n=== Coordinate Analysis ===\n"; $xs = []; $ys = []; foreach ($matches as $m) { if ($m[5] === 'black') { $xs[(float)$m[1]] = true; $ys[(float)$m[2]] = true; } } sort($xs); sort($ys); echo "Unique X coordinates: " . count($xs) . "\n"; echo "Unique Y coordinates: " . count($ys) . "\n"; // Check if coordinates form a grid $xsArray = array_keys($xs); $ysArray = array_keys($ys); if (count($xsArray) > 1) { $xStep = $xsArray[1] - $xsArray[0]; echo "X step: {$xStep}\n"; // Check if all X coordinates are multiples of the step $xErrors = 0; foreach ($xsArray as $x) { $remainder = fmod($x, $xStep); if (abs($remainder) > 0.01) { $xErrors++; } } if ($xErrors === 0) { echo "✅ X coordinates form a regular grid\n"; } else { echo "❌ {$xErrors} X coordinates don't align with grid\n"; } } if (count($ysArray) > 1) { $yStep = $ysArray[1] - $ysArray[0]; echo "Y step: {$yStep}\n"; $yErrors = 0; foreach ($ysArray as $y) { $remainder = fmod($y, $yStep); if (abs($remainder) > 0.01) { $yErrors++; } } if ($yErrors === 0) { echo "✅ Y coordinates form a regular grid\n"; } else { echo "❌ {$yErrors} Y coordinates don't align with grid\n"; } } // Check for potential issues echo "\n=== Potential Issues ===\n"; // Check if all black rectangles have same size $blackSizes = []; foreach ($matches as $m) { if ($m[5] === 'black') { $key = "{$m[3]}x{$m[4]}"; $blackSizes[$key] = ($blackSizes[$key] ?? 0) + 1; } } if (count($blackSizes) === 1) { echo "✅ All black modules have same size\n"; } else { echo "❌ Black modules have different sizes!\n"; foreach ($blackSizes as $size => $count) { echo " {$size}: {$count} rectangles\n"; } } // Check quiet zone $minX = min(array_map(fn($m) => (float)$m[1], array_filter($matches, fn($m) => $m[5] === 'black'))); $minY = min(array_map(fn($m) => (float)$m[2], array_filter($matches, fn($m) => $m[5] === 'black'))); echo "\nFirst black module position: ({$minX}, {$minY})\n"; if ($minX > 0 && $minY > 0) { echo "✅ Quiet zone present (minimum {$minX}px)\n"; } else { echo "❌ No quiet zone! QR code starts at edge\n"; }