Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

615
Vistas
Is there any way of converting OpenCV.Mat to array in JavaScript?

I'm working on Mat in OpenCV. However, I need to manually calculate the Mat by myself. Is there is a way of accessing Mat likes 2D array?

const myMat = cv.matFromArray(cv, 3, 3, cv.CV_64F, [
      [1, 2, 3],
      [4, 5, 6],
      [7, 8, 9],
    ])
const newMat = someProcessThatReturnMat(myMat)

/* OpenCV in JS cannot access Mat like this */
const result = someProcess(newMat[1][2], newMat[2][0])

Thank you in advance

Updated: The problem is cv.matFromArray cannot convert 2D array to Mat. You have to use it as 1D array. That's why it never return the correct values. For example:

const myMat = cv.matFromArray(3, 3, cv.CV_64F, [1,2,3,4,5,6,7,8,9])

And then, you can access the value

const value = myMat.doubleAt(1, 2) // row 1, col 2
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to use the doubleAt(y,x) method.

It's double because the mat's content is CV_64F, not because you want doubles.

You can also use .data64F to access a flat Float64Array of the Mat's data.

OpenCV.js is... rough. It originated from someone's Google Summer of Code and hasn't received significant care since. Documentation amounts to some tutorials; API docs seem to be missing entirely. The "Mat" interface emulated the at() method from C++, badly, instead of looking at numpy (python) or making this access feel "native" to javascript. Overloading the [] operator is possible using a Proxy but that was not implemented.

Here's an example: https://docs.opencv.org/4.x/de/d06/tutorial_js_basic_ops.html

Feel free to browse OpenCV's issues and maybe suggest some improvements.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda