I have an IplImage that I converted in a Matrix, and now I want to iterate cell by cell.
CvMat mtx = new CvMat(iplUltima);
for (int i = 0; i < 100; i++) {
//I need something like mtx[0][i] = someValue;
}
I have an IplImage that I converted in a Matrix, and now I want to iterate cell by cell.
CvMat mtx = new CvMat(iplUltima);
for (int i = 0; i < 100; i++) {
//I need something like mtx[0][i] = someValue;
}
¡¡I DID IT!! I share it:
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
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;
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");
}
I don't have Java installed, I can't check this solution, but I think 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 the reference about pixel access in javaCV.