Ask Your Question
0

opencv c++ equivalent for arraylist in java

asked 2017-10-10 04:06:40 -0600

Vahid Dnt gravatar image

Whats the equivalent of the following lines in open cv c++? The first lines have written with java language.

  1. ArrayList<integer> x = new ArrayList<integer>(); is this its correct equivalent? std::vector< int > x = std::vector<int>();

  2. x.add(i); is this its correct equivalent? x.push_back(i);

  3. Mat[] m = new Mat[mCount]; is this its correct equivalent? std::vector<cv::mat> m = std::vector<cv::mat> (mCount);

  4. float[] fl = new float[flLength]; is this its correct equivalent? std::vector< float > fl = std::vector< float >(flLength);

  5. A.get(0, 0, ALists); is this its correct equivalent? ALists.push_back((float)A.at< float >(0,0));

  6. cv::Mat cropped = rotated.submat(offset, offset + cropSize, offset, offset + cropSize); is this its correct equivalent?
    cv::Mat tmpMat0 = rotated.rowRange(offset,offset + cropSize).colRange(offset,offset + cropSize); cv::Mat cropped; tmpMat0.copyTo(cropped);

Thanks for your help

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-10-10 04:36:59 -0600

berak gravatar image

updated 2017-10-10 04:39:05 -0600

first: bookmark this ! , and, ofc. this, too !

then we have:

  1. yes, but you'd rather just skip the assignment, std::vector< int > x; is all you need.
  2. yes ;)
  3. similar to 1., just use: std::vector<cv::Mat> m(mCount);
  4. see 3.
  5. now here it gets difficult. if you need a single pixel: float v = A.at< float >(row,col); note that is this is only valid IF the type of the Mat is float, usually, for a bgr image it would look like: Vec3b pixel = A.at<Vec3b>(r,c); you have to carefully adjust the type in the brackets (and the return value) to that. all in all, code that uses this for the whole image should be avoided !
  6. well that's plain wrong. luckily, cv::Mat has an overloaded () operator, that can be used quite similar to your java code: cv::Mat cropped = rotated(yoffset, yoffset + cropSize, xoffset, xoffset + cropSize);
edit flag offensive delete link more

Comments

@berak how convert arraylist<integer> to Mat ??

rainY gravatar imagerainY ( 2018-08-27 21:58:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-10-10 04:06:40 -0600

Seen: 499 times

Last updated: Oct 10 '17