Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pointers? #17

Closed
GoogleCodeExporter opened this issue May 27, 2015 · 2 comments
Closed

Pointers? #17

GoogleCodeExporter opened this issue May 27, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

Is there a way to implement something like this piece of code written in C++ to 
Java?

IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3);
((uchar *)(img->imageData + i*img->widthStep))[j*img->nChannels + 0]=111;

where i,j are image coordinates. Code found at: 
http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/index.html

Since this makes use of pointers, I was wondering if it is possible to do it in 
Java. It may be a simple fix (I'm missing something) or it may not be possible 
to do.

What I'm trying to do is access the colour channels of a particular pixel. I 
have got it working with the cvGet2D method but the program got quite slow when 
looping this method. Maybe using this new method will be faster (that is the 
case in C++).

Thanks in advance

Original issue reported on code.google.com by josephps...@gmail.com on 27 Aug 2010 at 9:03

@GoogleCodeExporter
Copy link
Author

As mentionned in the README.txt file, you can get a ByteBuffer by calling 
getByteBuffer():
    ByteBuffer bb = img.getByteBuffer();
And then you use the ByteBuffer like any other standard Java NIO ByteBuffer.. 
Your operation above would look something like:
    bb.put(i*img.widthStep + j*img.nChannels + 0, (byte)111);

Original comment by samuel.a...@gmail.com on 28 Aug 2010 at 2:56

  • Changed state: Done

@GoogleCodeExporter
Copy link
Author

Many thanks Samuel, I knew I must have missed something! :D

Original comment by josephps...@gmail.com on 28 Aug 2010 at 6:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant