Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

304
Visualizações
opencv.js Mat multiplication with Scalar

I am new to OpenCV and trying to do some detection on a camera with opencv.js I was following some tutorials based on python code and adapting it to javascript/typescript (my page is running in an angular application).

I capture frames from a camera in fullhd resolution, then in order to increase the performance and have a more smooth selection, I scale the frame to a smaller size. I then change the image to grayscale, add a gaussian blur and apply a threshold to it. At this stage I call the findContours function to detect the contours of the shapes detected by the camera.

In the sample I am following the next step is to iterate on each found contour, then multiply the Mat with the ratio from the original frame and small frame in order to display the contour on the original image.

cnt *= ratio

unfortunately doing so changes my Mat object cnt into NaN. I assume the * operator is not working on Mat with opencv.js and am trying to find another solution.

I did several experimentation, with no avail. I found the mul() function and got somewhat results with a basic object. the function requires another Mat, then a ratio.

I did the following test.

let mat1 = cv.matFromArray(3,3,cv.CV_32FC1,[1,2,3,4,5,6,7,8,9]);
const temp = new cv.Mat.ones(c.rows, c.cols, cv.CV_32FC1);
let dst = mat1.mul(temp,10); 
console.log("dst::" + dst.data32F);//dst::10,20,30,40,50,60,70,80,90

so it looks like promising. but when trying to apply it to my contour, I have the following problem. In order to generate the dummy temp Mat, I need to specify the type of the matrix. In the test I set it to cv.CV_32FC1 But when trying with my contour object

cnt.type() returns 12 Checking the documentation it seems it translates to CV_8UC130, as it is not a defined value, in C++ or python you would have to use the function CV_8UC(130) but it doesn't seems to be in the opencv.js version. Thus I am unable to create my Mat and continue my process.

Is there something I am missing? I feel a lot of steps are necessary for an operation which should be simple. What would be the easiest step to scale my contour?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

With the comment above, I was able to solve my problem with the following code. Posting it here if someone else is having trouble.

...
let cnt = contours.get(i);
let ones = new cv.Mat(cnt.rows, cnt.cols, cv.CV_32SC2, new cv.Scalar(1,1,1,1));
let cnt2 = cnt.mul(ones,ratio);
ones.delete();
...
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda