jloyd / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

Pointers? #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
Many thanks Samuel, I knew I must have missed something! :D

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