How to Access rows and columns of Vector<Mat> Images on Open cv for Android?

Sisay picture Sisay · Jun 9, 2013 · Viewed 22.8k times · Source

I was going through some code on open cv using Android.Can any one show me how I am gonna access the rows and columns of a vector Mat of image?Its declared and the columns and rows are accessed as given below but i am having errors like and .

vector<Mat> images;//Vector of Mat image declared
...
int im_width = images[0].cols;//its trying to access column of images matrix
int im_height = images[0].rows;//trying to access rows of Mat images

If this is not the right way to access the columns and rows of a vector Image, then what is it? When it says images[0] its trying to access the index 0 of the vector of Mat images.I am not sure if this is right or not.

Answer

Zaw Lin picture Zaw Lin · Jun 9, 2013
Mat m;
m.row(i);
m.col(i);

ref: http://opencv.willowgarage.com/wiki/Welcome?action=AttachFile&do=get&target=opencv_cheatsheet.pdf

edit: the following works and produces expected output. perhaps you should describe your errors?

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
    vector<Mat> vectors;
    Mat img1 = imread( "C:/test/1.jpg");
    Mat img2 = imread( "C:/test/2.jpg");
    vectors.push_back(img1);
    vectors.push_back(img2);
    cout<<vectors[0].rows<<endl;
    cout<<vectors[0].cols<<endl;
    cin.ignore(1);
    return 0;
}