opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
79.19k stars 55.84k forks source link

Small differences in findChessboardCorners between aarch64 and amd64. #25612

Closed hgaiser closed 6 months ago

hgaiser commented 6 months ago

System Information

OpenCV python version: 4.9.0 Operating System / Platform: ArchLinux and Docker container with Debian Bullseye on aarch64 Python version: 3.12.3 on ArchLinux, 3.9.16 on Debian

Detailed description

The function findChessboardCorners produces slightly different results on the same input, depending on which system it runs on. The two systems are:

  1. Arch Linux on amd64 (also tried Debian Bullseye through Docker, which provides identical results compared to Arch Linux).
  2. Debian Bullseye on aarch64 (through Docker + QEMU)

The difference in values are minimal, but it causes a slight inconvenience with unit testing, which should pass on both systems. The current workaround is to increase the tolerance, but ideally the values will be identical.

Steps to reproduce

#!/bin/env python

import cv2 as cv

image = cv.imread('input/checkerboard1-156x200.jpg', cv.IMREAD_GRAYSCALE)
ret, corners = cv.findChessboardCorners(image, (6, 9), None)
print(corners)

On this image:

checkerboard1-156x200

Produces this result on amd64:

[[[116.       152.      ]]

 [[104.05316  157.43578 ]]

 [[ 89.27373  160.86046 ]]

 [[ 73.42442  164.32974 ]]

 [[ 56.28912  167.71883 ]]

 [[ 37.95618  171.6327  ]]

 [[116.733025 139.71585 ]]

 [[103.36687  142.51303 ]]

 [[ 88.489624 145.47571 ]]

 [[ 72.53801  148.21695 ]]

 [[ 55.036766 151.32713 ]]

 [[ 36.290966 154.68639 ]]

 [[116.30099  125.30222 ]]

 [[102.512535 127.4018  ]]

 [[ 87.41284  129.58472 ]]

 [[ 71.410835 131.84668 ]]

 [[ 53.66556  134.28918 ]]

 [[ 34.589046 137.2439  ]]

 [[115.82055  110.38164 ]]

 [[101.55869  112.00066 ]]

 [[ 86.59523  113.49139 ]]

 [[ 69.960175 115.4587  ]]

 [[ 52.253532 117.37025 ]]

 [[ 32.674736 119.366325]]

 [[115.2452    95.45381 ]]

 [[100.91742   96.47863 ]]

 [[ 85.55637   97.43438 ]]

 [[ 68.91743   98.45021 ]]

 [[ 50.714634  99.43973 ]]

 [[ 30.889784 100.77024 ]]

 [[114.497444  79.98196 ]]

 [[ 99.982635  80.46384 ]]

 [[ 84.65953   80.76845 ]]

 [[ 67.58158   81.20551 ]]

 [[ 49.27256   81.43089 ]]

 [[ 28.949272  81.96722 ]]

 [[113.73747   64.11611 ]]

 [[ 99.113495  63.873646]]

 [[ 83.5419    63.707794]]

 [[ 66.39293   63.332623]]

 [[ 47.58178   63.23925 ]]

 [[ 27.160378  62.571144]]

 [[113.283356  48.3624  ]]

 [[ 98.42366   47.36708 ]]

 [[ 82.49639   46.42087 ]]

 [[ 65.23059   45.23791 ]]

 [[ 46.17502   44.469604]]

 [[ 25.319508  43.12276 ]]

 [[112.40482   31.658096]]

 [[ 97.35009   29.622128]]

 [[ 81.50612   28.636871]]

 [[ 63.575867  26.428997]]

 [[ 44.673893  24.946121]]

 [[ 23.525173  22.709963]]]

And this result on aarch64:

[[[116.       152.      ]]

 [[104.05312  157.43579 ]]

 [[ 89.27373  160.86046 ]]

 [[ 73.42442  164.32974 ]]

 [[ 56.28912  167.71883 ]]

 [[ 37.95616  171.63269 ]]

 [[116.73302  139.71587 ]]

 [[103.36687  142.51303 ]]

 [[ 88.489624 145.47571 ]]

 [[ 72.53801  148.21695 ]]

 [[ 55.036743 151.32712 ]]

 [[ 36.29096  154.68639 ]]

 [[116.30099  125.30222 ]]

 [[102.512535 127.4018  ]]

 [[ 87.41284  129.58472 ]]

 [[ 71.410835 131.84668 ]]

 [[ 53.665546 134.28918 ]]

 [[ 34.589043 137.2439  ]]

 [[115.82054  110.38164 ]]

 [[101.55869  112.00066 ]]

 [[ 86.59523  113.49139 ]]

 [[ 69.96014  115.458694]]

 [[ 52.253532 117.37025 ]]

 [[ 32.67473  119.36633 ]]

 [[115.24519   95.45381 ]]

 [[100.91737   96.47863 ]]

 [[ 85.55637   97.43438 ]]

 [[ 68.91738   98.45021 ]]

 [[ 50.71462   99.439735]]

 [[ 30.889767 100.77024 ]]

 [[114.497444  79.98196 ]]

 [[ 99.98259   80.46383 ]]

 [[ 84.65953   80.76845 ]]

 [[ 67.58158   81.20551 ]]

 [[ 49.27256   81.43089 ]]

 [[ 28.949228  81.96721 ]]

 [[113.737465  64.11611 ]]

 [[ 99.11349   63.873646]]

 [[ 83.5419    63.707794]]

 [[ 66.39293   63.332623]]

 [[ 47.58178   63.23925 ]]

 [[ 27.160357  62.571144]]

 [[113.283356  48.3624  ]]

 [[ 98.42366   47.36708 ]]

 [[ 82.49639   46.42087 ]]

 [[ 65.230576  45.23791 ]]

 [[ 46.175     44.469604]]

 [[ 25.319508  43.12276 ]]

 [[112.40482   31.658102]]

 [[ 97.35008   29.622128]]

 [[ 81.50611   28.636871]]

 [[ 63.575863  26.428991]]

 [[ 44.67389   24.946123]]

 [[ 23.525173  22.709963]]]

For example the second to last row has values [[ 44.67389 24.946123]] on aarch64 and [[ 44.673893 24.946121]] on amd64. These differences are minimal, but they affect downstream computations like intrinsic calibration, which exacerbates the effect.

Issue submission checklist

asmorkalov commented 6 months ago

According to provided log the difference is in the last or last two decimal digits. The difference may appear due to compiler optimization or slightly different operations order for floats/doubles. There is nothing to fix.

hgaiser commented 6 months ago

Thanks for your response, I was worried that'd be the case. Good to have verified though :+1: