我有一个IplImage,我在Matrix中转换,现在我想逐个单元地迭代。
CvMat mtx = new CvMat(iplUltima);
for (int i = 0; i < 100; i++) {
//I need something like mtx[0][i] = someValue;
}
答案 0 :(得分:3)
我发了!!我分享一下:
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);
其中i = row且j = column
答案 1 :(得分:1)
首先,您需要从JavaCV导入以下内容:
import com.googlecode.javacv.cpp.opencv_core.CvMat;
import static com.googlecode.javacv.cpp.opencv_core.CV_32F;
主程序:
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");
}
答案 2 :(得分:-1)
我没有安装Java,我无法检查此解决方案,但我认为它应该可以正常工作。
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是有关javaCV中像素访问的参考。