1

OpenCV.js vs OpenCV Python image imread rgb difference

I'm trying to understand why open cv give me different results in JS and Python during imread operation. Just for illustration two screenshots from opencvjs site and colab where I extracting rgb (or brg) data for one jpg image and summarize all values just to see that there is a difference.

import cv2
img = cv2.imread("/content/player3.jpg")
print(img.sum())

VS

let src = cv.imread('canvasInput');
let dst = new cv.Mat();

cv.cvtColor(src, dst, cv.COLOR_RGBA2BGR, 0);

let sum = dst.data.reduce((acc,i)=> acc=acc+i)
console.log('sum of the values',sum)

Result:50950421 vs 50949889

Any ideas how to get in JS same result as in the Python? see JS vs Python screenshot

Submitted May 01st 2021 by Admin

Answers
0

  1. could you, please, try add start value, like it's done in documentation of reduce https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce

  2. I'm not sure what dst should return, but just to be sure, you can try to make strong convert to number, just in case

Try this out

let src = cv.imread('canvasInput');
let dst = new cv.Mat(); cv.cvtColor(src, dst, cv.COLOR_RGBA2BGR, 0); let sum = dst.data.reduce((acc,i)=> acc=acc+(+i), 0)
console.log('sum of the values',sum)

Admin | 4 months ago



Relevant Questions