How to iterate over cvMat matrix in JavaCV?

I have an IplImage that I have converted to a Matrix, and now I want to iterate the cell through cell.

CvMat mtx = new CvMat(iplUltima); for (int i = 0; i < 100; i++) { //I need something like mtx[0][i] = someValue; } 
+4
source share
3 answers

I DID! I share this:

 CvMat mtx = new CvMat(iplUltima); for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { opencv_core.cvSet2D(mtx, i, j, CvScalar.ONE); } } iplUltima = new IplImage (mtx); 

Where i = row and j = column

+3
source

First you need to import the following from JavaCV:

import com.googlecode.javacv.cpp.opencv_core.CvMat;

import static com.googlecode.javacv.cpp.opencv_core.CV_32F;

The main program:

 int rows = 2; int cols = 2; CvMat Tab = CvMat.create( rows, cols, CV_32F ); // Manually fill the table Tab.put(0, 0, 1); Tab.put(0, 1, 2); Tab.put(1, 0, -3); Tab.put(1, 1, 4); // Iterate through its elements and print them for(int i=0;i<rows;i++){ for (int j =0;j<cols;j++){ System.out.print(" "+ Tab.get(i,j) ); } System.out.println("\n"); } 
+1
source

I do not have Java installed, I can not check this solution, but I think that it should work fine.

 CvMat mtx = new CvMat(iplUltima); val n = mtx.rows * mtx.cols * mtx.channels for (i <- 0 until n) { // Put your pixel value, for example 200 mtx.put(i, 200) } 

Here is a link to access pixels in javaCV.

-1
source

Source: https://habr.com/ru/post/1413044/


All Articles