Ask Your Question
1

How to translate this to Java?

asked 2012-08-01 07:37:58 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Now I am studying openCV with Java(not so familier to Java and C++ though...), following C++ documentations online as well as textbooks of C++. I am trying to make a "fisheye lens effect" following the C++ code in a textbook, but I stuck completely.

How to translate the following code to Java?

Especially, I don't exactly understand the part around <uchar>. That seems like pointer but in Java version, I never found this kind of part...

for (int y=0; y<srcMat.rows; y++){
  for (int x=0; x<srcMat.cols; x++){
    for(int i=0;i<=2; i++){
         // vx and vy are int that represent other positions
         dstMat.at<uchar>(y, 3*x+i) = srcMat.at<uchar>(vy, 3*vx+i) 
    }
  }
}
edit retag flag offensive close merge delete

Comments

&lt;uchar&gt; is a template parameter for a template function. uchar means probably unsigned char as a typedef. Search for more info about c++ template functions.

TimK gravatar imageTimK ( 2013-08-03 03:30:34 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2012-08-01 08:28:56 -0600

Daniil Osokin gravatar image

updated 2012-08-02 01:18:50 -0600

Here is an excellent explanation: How to get and modify the pixel of Mat in Java? In your case code can be like:


// assume, that Mats with one channel
byte[] sourceBuffer = new byte[srcMat.total()];
byte[] destinationBuffer = new byte[dstMat.total()];
srcMat.get(0, 0, sourceBuffer);
int cols = srcMat.cols();
int rows = srcMat.rows();
for (int y = 0; y < rows; y++){
  for (int x = 0; x < cols; x++){
    for (int i = 0; i <= 2; i++){
          destinationBuffer[y * cols + 3 * x + i] = sourceBuffer(vy * cols + 3 * vx + i) 
    }
  }
}
dstMat.put(0, 0, destinationBuffer);
edit flag offensive delete link more

Comments

1

Thanks a lot for your quite fast comments and fruitful info! They help me a lot. Im trying that way and also checking the link. If I need any other help, please let me ask you again.
Thanks again,

graffage

GRAFFAGE gravatar imageGRAFFAGE ( 2012-08-01 12:44:55 -0600 )edit

Hi @Daniil Osokin, i have a problem, i still dont have bright idea in converting code like this aamTexture.<Vec3b>at(pointsInsideHull.get(i))[0] into java, do you have any tutorial about it?

orochi gravatar imageorochi ( 2013-06-10 11:03:18 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2012-08-01 07:37:58 -0600

Seen: 2,331 times

Last updated: Aug 02 '12