Possible bug with MatrixOfPoint2f fromList (Bug #1808)


Added by Rui Marques almost 13 years ago. Updated almost 13 years ago.


Status:Done Start date:2012-04-16
Priority:Normal Due date:
Assignee:Andrey Pavlenko % Done:

0%

Category:android
Target version:2.4.0
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

I am using OpenCV4Android, I tried the following:

1MatOfPoint2f mObjPoints = new MatOfPoint2f();
2mObjPoints.fromList(currentObjectPoints); //currentObjectPoints is an ArrayList<Point> - not empty

Error:

04-16 11:22:58.129: E/AndroidRuntime(32280): FATAL EXCEPTION: Thread-9
04-16 11:22:58.129: E/AndroidRuntime(32280): java.lang.NullPointerException
04-16 11:22:58.129: E/AndroidRuntime(32280):     at java.util.ArrayList.toArray(ArrayList.java:518)
04-16 11:22:58.129: E/AndroidRuntime(32280):     at org.opencv.core.MatOfPoint2f.fromList(MatOfPoint2f.java:66)
04-16 11:22:58.129: E/AndroidRuntime(32280):     at [myclass](Sample1View.java:648)
04-16 11:22:58.129: E/AndroidRuntime(32280):     at [mypackadge].processFrame(Sample1View.java:183)
04-16 11:22:58.129: E/AndroidRuntime(32280):     at [mypackadge].SampleViewBase.run(SampleViewBase.java:182)
04-16 11:22:58.129: E/AndroidRuntime(32280):     at java.lang.Thread.run(Thread.java:1096)

Upon inspect method that gives this error:

1file: MatOfPoint2f.java
2
3public void fromList(List<Point> lp) {
4        Point ap[] = lp.toArray(null);
5        fromArray(ap);
6}

Somehow the problem is with that toArray(null), i think.
I would say this is probably java version dependent, so here is my version:

$ java -version
java version "1.6.0_20" 
OpenJDK Runtime Environment (IcedTea6 1.9.13) (6b20-1.9.13-0ubuntu1~10.04.1)
OpenJDK Server VM (build 19.0-b09, mixed mode)

I did the following work around that seems to work, i created a local fromList instead of the OpenCV one:

1   private MatOfPoint2f hackFromList(List<Point> lp) {
2       Point ap[] = lp.toArray(new Point[0]); // the only difference is here
3
4       MatOfPoint2f tmpMat = new MatOfPoint2f();
5       tmpMat.fromArray(ap);
6
7       return tmpMat;
8   }

Associated revisions

Revision 2513f5d3
Added by Andrey Pavlenko almost 13 years ago

fixing #1808, Java API improvements

Revision f5ded410
Added by Roman Donchenko over 11 years ago

Merge pull request #1808 from alalek:ocl_fix_cvtcolor_xyz

History

Updated by Andrey Kamaev almost 13 years ago

  • Target version set to 2.4.0
  • Description changed from I am using OpenCV4Android, I tried the following: <pre> MatOfPoint2f m... to I am using OpenCV4Android, I tried the following: <pre><code class=... More
  • Category set to android
  • Assignee set to Andrey Pavlenko

Updated by Andrey Pavlenko almost 13 years ago

  • Status changed from Open to Done

Also available in: Atom PDF