about cvCalEigenObjects(...)

45 views
Skip to first unread message

June

unread,
Jun 25, 2011, 10:33:05 PM6/25/11
to javacv
I'm building doPCA(). The problem is that new
IplImage.PointerByReference(faceImgArr).getPointer() is not working.
The Eclipse does not recognize it and shows the red mark. Does anyone
know how to fix??

float[] outputEigenValues = new float[nTrainFaces];
cvCalcEigenObjects(nTrainFaces,
new IplImage.PointerByReference(faceImgArr).getPointer(),
new
IplImage.PointerByReference(eigenVectArr).getPointer(),
CV_EIGOBJ_NO_CALLBACK,
0,
null,
calcLimit,
pAvgTrainImg,
outputEigenValues);

Samuel Audet

unread,
Jun 26, 2011, 12:07:06 AM6/26/11
to jav...@googlegroups.com
Hello,

That's the old JNA syntax, the new JavaCPP syntax is:
new PointerPointer(faceImgArr)

Samuel

June

unread,
Jun 27, 2011, 12:00:09 AM6/27/11
to javacv
I got this weird error. Do you know what went wrong here?? I think I
set every thing up right...... still cvCalcEigenObjects() is a
problem. thanks.

OpenCV Error: One of arguments' values is out of range (index is out
of range) in cvPtr2D, file /opt/local/var/macports/build/
_opt_local_var_macports_sources_rsync.macports.org_release_ports_graphics_opencv/
work/OpenCV-2.2.0/modules/core/src/array.cpp, line 1795
Exception in thread "main" java.lang.RuntimeException: /opt/local/var/
macports/build/
_opt_local_var_macports_sources_rsync.macports.org_release_ports_graphics_opencv/
work/OpenCV-2.2.0/modules/core/src/array.cpp:1795: error: (-211) index
is out of range in function cvPtr2D

at com.googlecode.javacv.cpp.opencv_legacy.cvCalcEigenObjects(Native
Method)
at Eigenface.doPCA(Eigenface.java:155)
at Eigenface.learn(Eigenface.java:73)
at Eigenface.main(Eigenface.java:57)



static void doPCA() {
CvSize faceImgSize = new CvSize(25);
// set the number of eigenvalues to use
nEigens = nTrainFaces;

eigenVectArr = new IplImage[nEigens];
for (int i = 0; i < nEigens; i++)
eigenVectArr[i] = cvCreateImage(faceImgSize, IPL_DEPTH_32F, 1);

// allocate the eigenvalue array
eigenValMat = cvCreateMat( 1, nEigens, CV_32FC1 );

// allocate the averaged image
pAvgTrainImg = cvCreateImage(faceImgSize, IPL_DEPTH_32F, 1);

// set the PCA termination criterion
CvTermCriteria calcLimit = cvTermCriteria( CV_TERMCRIT_ITER,
nEigens, 1);

float[] outputEigenValues = new float[nTrainFaces];
cvCalcEigenObjects(nTrainFaces,
new PointerPointer(faceImgArr),
new PointerPointer(eigenVectArr),
CV_EIGOBJ_NO_CALLBACK,
0,
null,
calcLimit,
pAvgTrainImg,
outputEigenValues);

cvNormalize(eigenValMat, eigenValMat);

Samuel Audet

unread,
Jun 27, 2011, 4:27:06 AM6/27/11
to jav...@googlegroups.com
On 2011-06-27 13:00, June wrote:
> CvSize faceImgSize = new CvSize(25);

Why do you need an array of 25 CvSize?

June

unread,
Jun 27, 2011, 5:56:53 PM6/27/11
to javacv
I wanted to minimize the size to run fast. Could you tell me what
size would be right if that is a problem?? thanks.

June

unread,
Jun 27, 2011, 6:39:27 PM6/27/11
to javacv
The problem is that if I don't set up the size consistent, it throws
an error like image size is different.

Besides, I found that

eigenValMat = cvCreateMat( 1, nEigens, CV_32FC1 );
System.out.println(eigenValMat.data.fl().opacity()) -----> 0

Is this right one?? I think because of this, it throws that error I
mentioned in the first thread. thanks.

June

unread,
Jun 28, 2011, 1:15:04 AM6/28/11
to javacv
I fixed the error. It was due to sizes of images. Now I got another
error: Invalid memory access of location 0x90 rip=0x10d0d86d6.

This error definitely happens at cvCalcEigenObjects(...). Do you have
any idea?? thanks.
Reply all
Reply to author
Forward
0 new messages