Ask Your Question
0

What is the java equivalent?

asked 2017-09-27 08:44:41 -0600

Tarcisioflima gravatar image

updated 2017-09-27 08:59:01 -0600

I'm trying to implement the below piece of code in JAVA; however, I cannot find a replacement for Vec3f. Any hint on it?

Mat samples( img.rows * img.cols, 3, CV_32FC1 );

int index = 0;
for( int y = 0; y < img.rows; y++ ) {
    Vec3f * row = float_img.ptr(y);
    for( int x = 0; x < img.cols; x++ )
        samples.at<Vec3f>(index++, 0) = row[x];
}
return samples;

Thank you!

edit retag flag offensive close merge delete

Comments

you probably should not attempt do do anything per-pixel from java.

what is the context of this ? what is it doing ?

(maybe wecan help you to find a more "high-level" replacement.)

berak gravatar imageberak ( 2017-09-27 08:49:02 -0600 )edit
1

I'm trying to generate a Mat from my RGB image to train EM algorithm. Thus, it is creating a sample vector.

Tarcisioflima gravatar imageTarcisioflima ( 2017-09-27 08:54:13 -0600 )edit

could you add, how "samples" is initialized ?

berak gravatar imageberak ( 2017-09-27 08:57:15 -0600 )edit
1

I added it on the code.

Tarcisioflima gravatar imageTarcisioflima ( 2017-09-27 08:59:20 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-09-27 09:38:40 -0600

berak gravatar image

you can use reshape for this:

img.convertTo(img, CvType.CV_32F);
Mat samples = img.reshape(1, img.total()); // 1 channel, each pixel is a row of 3 elements now
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-09-27 08:44:41 -0600

Seen: 386 times

Last updated: Sep 27 '17