我有一個IplImage,我在矩陣中轉換,現在我想逐個單元格迭代。如何迭代JavaCV中的cvMat矩陣?
CvMat mtx = new CvMat(iplUltima);
for (int i = 0; i < 100; i++) {
//I need something like mtx[0][i] = someValue;
}
我有一個IplImage,我在矩陣中轉換,現在我想逐個單元格迭代。如何迭代JavaCV中的cvMat矩陣?
CvMat mtx = new CvMat(iplUltima);
for (int i = 0; i < 100; i++) {
//I need something like mtx[0][i] = someValue;
}
我幹了!我分享:
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 =行和j =列
請告訴如何將其更改爲CvScalar.RED或其他意味着0-255。我這樣做,但沒有改變成綠色或紅色任何顏色我想要的 – GPrathap
嗨!抱歉!我再也沒有回到這個技術的程序,所以我不記得太多。不過,我記得一本好書:http://books.google.com.ar/books?id=seAgiOfu2EIC&pg=PA209&lpg=PA209&dq=cvSet2D+opencv&source=bl&ots=hTE6bmeCMi&sig=Y8BwgDQOmtzcOuTLga2S0mkDFak&hl=es-419&sa=X&ei=zbdwVL-WHMKkgwT35YOIDQ&ved= 0CFMQ6AEwBg#v = onepage&q = cvSet2D%20opencv&f = false – gal007
謝謝,我會弄明白 – GPrathap
首先,你需要導入從JavaCV如下:
進口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");
}
這可能會幫助您:http://stackoverflow.com/questions/9920449/converting-opencv-matrix-looping-to-javacv –
謝謝!但是在這個例子中迭代了一個FloatBuffer而不是CvMat。 Wath是否需要爲矩陣位置賦值? – gal007