Modified java wrapping mechanism

This commit is contained in:
Maksim Shabunin
2015-02-19 16:17:19 +03:00
parent 5850a9b8c3
commit 457123027e
167 changed files with 376 additions and 1254 deletions

View File

@@ -0,0 +1,4 @@
include/opencv2/core/base.hpp
include/opencv2/core.hpp
include/opencv2/core/utility.hpp
misc/java/src/cpp/core_manual.hpp

View File

@@ -0,0 +1,21 @@
#define LOG_TAG "org.opencv.core.Core"
#include "common.h"
#include "core_manual.hpp"
#include "opencv2/core/utility.hpp"
static int quietCallback( int, const char*, const char*, const char*, int, void* )
{
return 0;
}
namespace cv {
void setErrorVerbosity(bool verbose)
{
if(verbose)
cv::redirectError(0);
else
cv::redirectError((cv::ErrorCallback)quietCallback);
}
}

View File

@@ -0,0 +1,33 @@
#pragma once
#include "opencv2/core.hpp"
namespace cv
{
CV_EXPORTS_W void setErrorVerbosity(bool verbose);
}
#if 0
namespace cv
{
CV_EXPORTS_W void add(InputArray src1, Scalar src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1);
CV_EXPORTS_W void subtract(InputArray src1, Scalar src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1);
CV_EXPORTS_W void multiply(InputArray src1, Scalar src2, OutputArray dst, double scale=1, int dtype=-1);
CV_EXPORTS_W void divide(InputArray src1, Scalar src2, OutputArray dst, double scale=1, int dtype=-1);
CV_EXPORTS_W void absdiff(InputArray src1, Scalar src2, OutputArray dst);
CV_EXPORTS_W void compare(InputArray src1, Scalar src2, OutputArray dst, int cmpop);
CV_EXPORTS_W void min(InputArray src1, Scalar src2, OutputArray dst);
CV_EXPORTS_W void max(InputArray src1, Scalar src2, OutputArray dst);
}
#endif //0

View File

@@ -0,0 +1,15 @@
package org.opencv.core;
public class CvException extends RuntimeException {
private static final long serialVersionUID = 1L;
public CvException(String msg) {
super(msg);
}
@Override
public String toString() {
return "CvException [" + super.toString() + "]";
}
}

View File

@@ -0,0 +1,136 @@
package org.opencv.core;
public final class CvType {
// type depth constants
public static final int
CV_8U = 0, CV_8S = 1,
CV_16U = 2, CV_16S = 3,
CV_32S = 4,
CV_32F = 5,
CV_64F = 6,
CV_USRTYPE1 = 7;
// predefined type constants
public static final int
CV_8UC1 = CV_8UC(1), CV_8UC2 = CV_8UC(2), CV_8UC3 = CV_8UC(3), CV_8UC4 = CV_8UC(4),
CV_8SC1 = CV_8SC(1), CV_8SC2 = CV_8SC(2), CV_8SC3 = CV_8SC(3), CV_8SC4 = CV_8SC(4),
CV_16UC1 = CV_16UC(1), CV_16UC2 = CV_16UC(2), CV_16UC3 = CV_16UC(3), CV_16UC4 = CV_16UC(4),
CV_16SC1 = CV_16SC(1), CV_16SC2 = CV_16SC(2), CV_16SC3 = CV_16SC(3), CV_16SC4 = CV_16SC(4),
CV_32SC1 = CV_32SC(1), CV_32SC2 = CV_32SC(2), CV_32SC3 = CV_32SC(3), CV_32SC4 = CV_32SC(4),
CV_32FC1 = CV_32FC(1), CV_32FC2 = CV_32FC(2), CV_32FC3 = CV_32FC(3), CV_32FC4 = CV_32FC(4),
CV_64FC1 = CV_64FC(1), CV_64FC2 = CV_64FC(2), CV_64FC3 = CV_64FC(3), CV_64FC4 = CV_64FC(4);
private static final int CV_CN_MAX = 512, CV_CN_SHIFT = 3, CV_DEPTH_MAX = (1 << CV_CN_SHIFT);
public static final int makeType(int depth, int channels) {
if (channels <= 0 || channels >= CV_CN_MAX) {
throw new java.lang.UnsupportedOperationException(
"Channels count should be 1.." + (CV_CN_MAX - 1));
}
if (depth < 0 || depth >= CV_DEPTH_MAX) {
throw new java.lang.UnsupportedOperationException(
"Data type depth should be 0.." + (CV_DEPTH_MAX - 1));
}
return (depth & (CV_DEPTH_MAX - 1)) + ((channels - 1) << CV_CN_SHIFT);
}
public static final int CV_8UC(int ch) {
return makeType(CV_8U, ch);
}
public static final int CV_8SC(int ch) {
return makeType(CV_8S, ch);
}
public static final int CV_16UC(int ch) {
return makeType(CV_16U, ch);
}
public static final int CV_16SC(int ch) {
return makeType(CV_16S, ch);
}
public static final int CV_32SC(int ch) {
return makeType(CV_32S, ch);
}
public static final int CV_32FC(int ch) {
return makeType(CV_32F, ch);
}
public static final int CV_64FC(int ch) {
return makeType(CV_64F, ch);
}
public static final int channels(int type) {
return (type >> CV_CN_SHIFT) + 1;
}
public static final int depth(int type) {
return type & (CV_DEPTH_MAX - 1);
}
public static final boolean isInteger(int type) {
return depth(type) < CV_32F;
}
public static final int ELEM_SIZE(int type) {
switch (depth(type)) {
case CV_8U:
case CV_8S:
return channels(type);
case CV_16U:
case CV_16S:
return 2 * channels(type);
case CV_32S:
case CV_32F:
return 4 * channels(type);
case CV_64F:
return 8 * channels(type);
default:
throw new java.lang.UnsupportedOperationException(
"Unsupported CvType value: " + type);
}
}
public static final String typeToString(int type) {
String s;
switch (depth(type)) {
case CV_8U:
s = "CV_8U";
break;
case CV_8S:
s = "CV_8S";
break;
case CV_16U:
s = "CV_16U";
break;
case CV_16S:
s = "CV_16S";
break;
case CV_32S:
s = "CV_32S";
break;
case CV_32F:
s = "CV_32F";
break;
case CV_64F:
s = "CV_64F";
break;
case CV_USRTYPE1:
s = "CV_USRTYPE1";
break;
default:
throw new java.lang.UnsupportedOperationException(
"Unsupported CvType value: " + type);
}
int ch = channels(type);
if (ch <= 4)
return s + "C" + ch;
else
return s + "C(" + ch + ")";
}
}

View File

@@ -0,0 +1,61 @@
package org.opencv.core;
//C++: class DMatch
/**
* Structure for matching: query descriptor index, train descriptor index, train
* image index and distance between descriptors.
*/
public class DMatch {
/**
* Query descriptor index.
*/
public int queryIdx;
/**
* Train descriptor index.
*/
public int trainIdx;
/**
* Train image index.
*/
public int imgIdx;
// javadoc: DMatch::distance
public float distance;
// javadoc: DMatch::DMatch()
public DMatch() {
this(-1, -1, Float.MAX_VALUE);
}
// javadoc: DMatch::DMatch(_queryIdx, _trainIdx, _distance)
public DMatch(int _queryIdx, int _trainIdx, float _distance) {
queryIdx = _queryIdx;
trainIdx = _trainIdx;
imgIdx = -1;
distance = _distance;
}
// javadoc: DMatch::DMatch(_queryIdx, _trainIdx, _imgIdx, _distance)
public DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance) {
queryIdx = _queryIdx;
trainIdx = _trainIdx;
imgIdx = _imgIdx;
distance = _distance;
}
/**
* Less is better.
*/
public boolean lessThan(DMatch it) {
return distance < it.distance;
}
@Override
public String toString() {
return "DMatch [queryIdx=" + queryIdx + ", trainIdx=" + trainIdx
+ ", imgIdx=" + imgIdx + ", distance=" + distance + "]";
}
}

View File

@@ -0,0 +1,83 @@
package org.opencv.core;
import org.opencv.core.Point;
//javadoc: KeyPoint
public class KeyPoint {
/**
* Coordinates of the keypoint.
*/
public Point pt;
/**
* Diameter of the useful keypoint adjacent area.
*/
public float size;
/**
* Computed orientation of the keypoint (-1 if not applicable).
*/
public float angle;
/**
* The response, by which the strongest keypoints have been selected. Can
* be used for further sorting or subsampling.
*/
public float response;
/**
* Octave (pyramid layer), from which the keypoint has been extracted.
*/
public int octave;
/**
* Object ID, that can be used to cluster keypoints by an object they
* belong to.
*/
public int class_id;
// javadoc:KeyPoint::KeyPoint(x,y,_size,_angle,_response,_octave,_class_id)
public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id)
{
pt = new Point(x, y);
size = _size;
angle = _angle;
response = _response;
octave = _octave;
class_id = _class_id;
}
// javadoc: KeyPoint::KeyPoint()
public KeyPoint()
{
this(0, 0, 0, -1, 0, 0, -1);
}
// javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response, _octave)
public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave)
{
this(x, y, _size, _angle, _response, _octave, -1);
}
// javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response)
public KeyPoint(float x, float y, float _size, float _angle, float _response)
{
this(x, y, _size, _angle, _response, 0, -1);
}
// javadoc: KeyPoint::KeyPoint(x, y, _size, _angle)
public KeyPoint(float x, float y, float _size, float _angle)
{
this(x, y, _size, _angle, 0, 0, -1);
}
// javadoc: KeyPoint::KeyPoint(x, y, _size)
public KeyPoint(float x, float y, float _size)
{
this(x, y, _size, -1, 0, 0, -1);
}
@Override
public String toString() {
return "KeyPoint [pt=" + pt + ", size=" + size + ", angle=" + angle
+ ", response=" + response + ", octave=" + octave
+ ", class_id=" + class_id + "]";
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,79 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfByte extends Mat {
// 8UC(x)
private static final int _depth = CvType.CV_8U;
private static final int _channels = 1;
public MatOfByte() {
super();
}
protected MatOfByte(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfByte fromNativeAddr(long addr) {
return new MatOfByte(addr);
}
public MatOfByte(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfByte(byte...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(byte...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public byte[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
byte[] a = new byte[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Byte> lb) {
if(lb==null || lb.size()==0)
return;
Byte ab[] = lb.toArray(new Byte[0]);
byte a[] = new byte[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Byte> toList() {
byte[] a = toArray();
Byte ab[] = new Byte[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@@ -0,0 +1,83 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
import org.opencv.core.DMatch;
public class MatOfDMatch extends Mat {
// 32FC4
private static final int _depth = CvType.CV_32F;
private static final int _channels = 4;
public MatOfDMatch() {
super();
}
protected MatOfDMatch(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat: " + toString());
//FIXME: do we need release() here?
}
public static MatOfDMatch fromNativeAddr(long addr) {
return new MatOfDMatch(addr);
}
public MatOfDMatch(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat: " + toString());
//FIXME: do we need release() here?
}
public MatOfDMatch(DMatch...ap) {
super();
fromArray(ap);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(DMatch...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
float buff[] = new float[num * _channels];
for(int i=0; i<num; i++) {
DMatch m = a[i];
buff[_channels*i+0] = m.queryIdx;
buff[_channels*i+1] = m.trainIdx;
buff[_channels*i+2] = m.imgIdx;
buff[_channels*i+3] = m.distance;
}
put(0, 0, buff); //TODO: check ret val!
}
public DMatch[] toArray() {
int num = (int) total();
DMatch[] a = new DMatch[num];
if(num == 0)
return a;
float buff[] = new float[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
a[i] = new DMatch((int) buff[_channels*i+0], (int) buff[_channels*i+1], (int) buff[_channels*i+2], buff[_channels*i+3]);
return a;
}
public void fromList(List<DMatch> ldm) {
DMatch adm[] = ldm.toArray(new DMatch[0]);
fromArray(adm);
}
public List<DMatch> toList() {
DMatch[] adm = toArray();
return Arrays.asList(adm);
}
}

View File

@@ -0,0 +1,79 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfDouble extends Mat {
// 64FC(x)
private static final int _depth = CvType.CV_64F;
private static final int _channels = 1;
public MatOfDouble() {
super();
}
protected MatOfDouble(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfDouble fromNativeAddr(long addr) {
return new MatOfDouble(addr);
}
public MatOfDouble(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfDouble(double...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(double...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public double[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
double[] a = new double[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Double> lb) {
if(lb==null || lb.size()==0)
return;
Double ab[] = lb.toArray(new Double[0]);
double a[] = new double[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Double> toList() {
double[] a = toArray();
Double ab[] = new Double[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@@ -0,0 +1,79 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfFloat extends Mat {
// 32FC1
private static final int _depth = CvType.CV_32F;
private static final int _channels = 1;
public MatOfFloat() {
super();
}
protected MatOfFloat(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfFloat fromNativeAddr(long addr) {
return new MatOfFloat(addr);
}
public MatOfFloat(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfFloat(float...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(float...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public float[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
float[] a = new float[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Float> lb) {
if(lb==null || lb.size()==0)
return;
Float ab[] = lb.toArray(new Float[0]);
float a[] = new float[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Float> toList() {
float[] a = toArray();
Float ab[] = new Float[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@@ -0,0 +1,79 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfFloat4 extends Mat {
// 32FC4
private static final int _depth = CvType.CV_32F;
private static final int _channels = 4;
public MatOfFloat4() {
super();
}
protected MatOfFloat4(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfFloat4 fromNativeAddr(long addr) {
return new MatOfFloat4(addr);
}
public MatOfFloat4(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfFloat4(float...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(float...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public float[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
float[] a = new float[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Float> lb) {
if(lb==null || lb.size()==0)
return;
Float ab[] = lb.toArray(new Float[0]);
float a[] = new float[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Float> toList() {
float[] a = toArray();
Float ab[] = new Float[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@@ -0,0 +1,79 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfFloat6 extends Mat {
// 32FC6
private static final int _depth = CvType.CV_32F;
private static final int _channels = 6;
public MatOfFloat6() {
super();
}
protected MatOfFloat6(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfFloat6 fromNativeAddr(long addr) {
return new MatOfFloat6(addr);
}
public MatOfFloat6(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfFloat6(float...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(float...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public float[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
float[] a = new float[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Float> lb) {
if(lb==null || lb.size()==0)
return;
Float ab[] = lb.toArray(new Float[0]);
float a[] = new float[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Float> toList() {
float[] a = toArray();
Float ab[] = new Float[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@@ -0,0 +1,80 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfInt extends Mat {
// 32SC1
private static final int _depth = CvType.CV_32S;
private static final int _channels = 1;
public MatOfInt() {
super();
}
protected MatOfInt(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfInt fromNativeAddr(long addr) {
return new MatOfInt(addr);
}
public MatOfInt(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfInt(int...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(int...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public int[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
int[] a = new int[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Integer> lb) {
if(lb==null || lb.size()==0)
return;
Integer ab[] = lb.toArray(new Integer[0]);
int a[] = new int[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Integer> toList() {
int[] a = toArray();
Integer ab[] = new Integer[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@@ -0,0 +1,80 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfInt4 extends Mat {
// 32SC4
private static final int _depth = CvType.CV_32S;
private static final int _channels = 4;
public MatOfInt4() {
super();
}
protected MatOfInt4(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfInt4 fromNativeAddr(long addr) {
return new MatOfInt4(addr);
}
public MatOfInt4(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfInt4(int...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(int...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public int[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
int[] a = new int[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Integer> lb) {
if(lb==null || lb.size()==0)
return;
Integer ab[] = lb.toArray(new Integer[0]);
int a[] = new int[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Integer> toList() {
int[] a = toArray();
Integer ab[] = new Integer[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@@ -0,0 +1,86 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
import org.opencv.core.KeyPoint;
public class MatOfKeyPoint extends Mat {
// 32FC7
private static final int _depth = CvType.CV_32F;
private static final int _channels = 7;
public MatOfKeyPoint() {
super();
}
protected MatOfKeyPoint(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfKeyPoint fromNativeAddr(long addr) {
return new MatOfKeyPoint(addr);
}
public MatOfKeyPoint(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfKeyPoint(KeyPoint...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(KeyPoint...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
float buff[] = new float[num * _channels];
for(int i=0; i<num; i++) {
KeyPoint kp = a[i];
buff[_channels*i+0] = (float) kp.pt.x;
buff[_channels*i+1] = (float) kp.pt.y;
buff[_channels*i+2] = kp.size;
buff[_channels*i+3] = kp.angle;
buff[_channels*i+4] = kp.response;
buff[_channels*i+5] = kp.octave;
buff[_channels*i+6] = kp.class_id;
}
put(0, 0, buff); //TODO: check ret val!
}
public KeyPoint[] toArray() {
int num = (int) total();
KeyPoint[] a = new KeyPoint[num];
if(num == 0)
return a;
float buff[] = new float[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
a[i] = new KeyPoint( buff[_channels*i+0], buff[_channels*i+1], buff[_channels*i+2], buff[_channels*i+3],
buff[_channels*i+4], (int) buff[_channels*i+5], (int) buff[_channels*i+6] );
return a;
}
public void fromList(List<KeyPoint> lkp) {
KeyPoint akp[] = lkp.toArray(new KeyPoint[0]);
fromArray(akp);
}
public List<KeyPoint> toList() {
KeyPoint[] akp = toArray();
return Arrays.asList(akp);
}
}

View File

@@ -0,0 +1,78 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfPoint extends Mat {
// 32SC2
private static final int _depth = CvType.CV_32S;
private static final int _channels = 2;
public MatOfPoint() {
super();
}
protected MatOfPoint(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfPoint fromNativeAddr(long addr) {
return new MatOfPoint(addr);
}
public MatOfPoint(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfPoint(Point...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(Point...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
int buff[] = new int[num * _channels];
for(int i=0; i<num; i++) {
Point p = a[i];
buff[_channels*i+0] = (int) p.x;
buff[_channels*i+1] = (int) p.y;
}
put(0, 0, buff); //TODO: check ret val!
}
public Point[] toArray() {
int num = (int) total();
Point[] ap = new Point[num];
if(num == 0)
return ap;
int buff[] = new int[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
ap[i] = new Point(buff[i*_channels], buff[i*_channels+1]);
return ap;
}
public void fromList(List<Point> lp) {
Point ap[] = lp.toArray(new Point[0]);
fromArray(ap);
}
public List<Point> toList() {
Point[] ap = toArray();
return Arrays.asList(ap);
}
}

View File

@@ -0,0 +1,78 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfPoint2f extends Mat {
// 32FC2
private static final int _depth = CvType.CV_32F;
private static final int _channels = 2;
public MatOfPoint2f() {
super();
}
protected MatOfPoint2f(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfPoint2f fromNativeAddr(long addr) {
return new MatOfPoint2f(addr);
}
public MatOfPoint2f(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfPoint2f(Point...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(Point...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
float buff[] = new float[num * _channels];
for(int i=0; i<num; i++) {
Point p = a[i];
buff[_channels*i+0] = (float) p.x;
buff[_channels*i+1] = (float) p.y;
}
put(0, 0, buff); //TODO: check ret val!
}
public Point[] toArray() {
int num = (int) total();
Point[] ap = new Point[num];
if(num == 0)
return ap;
float buff[] = new float[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
ap[i] = new Point(buff[i*_channels], buff[i*_channels+1]);
return ap;
}
public void fromList(List<Point> lp) {
Point ap[] = lp.toArray(new Point[0]);
fromArray(ap);
}
public List<Point> toList() {
Point[] ap = toArray();
return Arrays.asList(ap);
}
}

View File

@@ -0,0 +1,79 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfPoint3 extends Mat {
// 32SC3
private static final int _depth = CvType.CV_32S;
private static final int _channels = 3;
public MatOfPoint3() {
super();
}
protected MatOfPoint3(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfPoint3 fromNativeAddr(long addr) {
return new MatOfPoint3(addr);
}
public MatOfPoint3(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfPoint3(Point3...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(Point3...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
int buff[] = new int[num * _channels];
for(int i=0; i<num; i++) {
Point3 p = a[i];
buff[_channels*i+0] = (int) p.x;
buff[_channels*i+1] = (int) p.y;
buff[_channels*i+2] = (int) p.z;
}
put(0, 0, buff); //TODO: check ret val!
}
public Point3[] toArray() {
int num = (int) total();
Point3[] ap = new Point3[num];
if(num == 0)
return ap;
int buff[] = new int[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
ap[i] = new Point3(buff[i*_channels], buff[i*_channels+1], buff[i*_channels+2]);
return ap;
}
public void fromList(List<Point3> lp) {
Point3 ap[] = lp.toArray(new Point3[0]);
fromArray(ap);
}
public List<Point3> toList() {
Point3[] ap = toArray();
return Arrays.asList(ap);
}
}

View File

@@ -0,0 +1,79 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfPoint3f extends Mat {
// 32FC3
private static final int _depth = CvType.CV_32F;
private static final int _channels = 3;
public MatOfPoint3f() {
super();
}
protected MatOfPoint3f(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfPoint3f fromNativeAddr(long addr) {
return new MatOfPoint3f(addr);
}
public MatOfPoint3f(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfPoint3f(Point3...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(Point3...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
float buff[] = new float[num * _channels];
for(int i=0; i<num; i++) {
Point3 p = a[i];
buff[_channels*i+0] = (float) p.x;
buff[_channels*i+1] = (float) p.y;
buff[_channels*i+2] = (float) p.z;
}
put(0, 0, buff); //TODO: check ret val!
}
public Point3[] toArray() {
int num = (int) total();
Point3[] ap = new Point3[num];
if(num == 0)
return ap;
float buff[] = new float[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
ap[i] = new Point3(buff[i*_channels], buff[i*_channels+1], buff[i*_channels+2]);
return ap;
}
public void fromList(List<Point3> lp) {
Point3 ap[] = lp.toArray(new Point3[0]);
fromArray(ap);
}
public List<Point3> toList() {
Point3[] ap = toArray();
return Arrays.asList(ap);
}
}

View File

@@ -0,0 +1,81 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfRect extends Mat {
// 32SC4
private static final int _depth = CvType.CV_32S;
private static final int _channels = 4;
public MatOfRect() {
super();
}
protected MatOfRect(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfRect fromNativeAddr(long addr) {
return new MatOfRect(addr);
}
public MatOfRect(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfRect(Rect...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(Rect...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
int buff[] = new int[num * _channels];
for(int i=0; i<num; i++) {
Rect r = a[i];
buff[_channels*i+0] = (int) r.x;
buff[_channels*i+1] = (int) r.y;
buff[_channels*i+2] = (int) r.width;
buff[_channels*i+3] = (int) r.height;
}
put(0, 0, buff); //TODO: check ret val!
}
public Rect[] toArray() {
int num = (int) total();
Rect[] a = new Rect[num];
if(num == 0)
return a;
int buff[] = new int[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
a[i] = new Rect(buff[i*_channels], buff[i*_channels+1], buff[i*_channels+2], buff[i*_channels+3]);
return a;
}
public void fromList(List<Rect> lr) {
Rect ap[] = lr.toArray(new Rect[0]);
fromArray(ap);
}
public List<Rect> toList() {
Rect[] ar = toArray();
return Arrays.asList(ar);
}
}

View File

@@ -0,0 +1,68 @@
package org.opencv.core;
//javadoc:Point_
public class Point {
public double x, y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public Point() {
this(0, 0);
}
public Point(double[] vals) {
this();
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
x = vals.length > 0 ? vals[0] : 0;
y = vals.length > 1 ? vals[1] : 0;
} else {
x = 0;
y = 0;
}
}
public Point clone() {
return new Point(x, y);
}
public double dot(Point p) {
return x * p.x + y * p.y;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Point)) return false;
Point it = (Point) obj;
return x == it.x && y == it.y;
}
public boolean inside(Rect r) {
return r.contains(this);
}
@Override
public String toString() {
return "{" + x + ", " + y + "}";
}
}

View File

@@ -0,0 +1,79 @@
package org.opencv.core;
//javadoc:Point3_
public class Point3 {
public double x, y, z;
public Point3(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public Point3() {
this(0, 0, 0);
}
public Point3(Point p) {
x = p.x;
y = p.y;
z = 0;
}
public Point3(double[] vals) {
this();
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
x = vals.length > 0 ? vals[0] : 0;
y = vals.length > 1 ? vals[1] : 0;
z = vals.length > 2 ? vals[2] : 0;
} else {
x = 0;
y = 0;
z = 0;
}
}
public Point3 clone() {
return new Point3(x, y, z);
}
public double dot(Point3 p) {
return x * p.x + y * p.y + z * p.z;
}
public Point3 cross(Point3 p) {
return new Point3(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(z);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Point3)) return false;
Point3 it = (Point3) obj;
return x == it.x && y == it.y && z == it.z;
}
@Override
public String toString() {
return "{" + x + ", " + y + ", " + z + "}";
}
}

View File

@@ -0,0 +1,82 @@
package org.opencv.core;
//javadoc:Range
public class Range {
public int start, end;
public Range(int s, int e) {
this.start = s;
this.end = e;
}
public Range() {
this(0, 0);
}
public Range(double[] vals) {
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
start = vals.length > 0 ? (int) vals[0] : 0;
end = vals.length > 1 ? (int) vals[1] : 0;
} else {
start = 0;
end = 0;
}
}
public int size() {
return empty() ? 0 : end - start;
}
public boolean empty() {
return end <= start;
}
public static Range all() {
return new Range(Integer.MIN_VALUE, Integer.MAX_VALUE);
}
public Range intersection(Range r1) {
Range r = new Range(Math.max(r1.start, this.start), Math.min(r1.end, this.end));
r.end = Math.max(r.end, r.start);
return r;
}
public Range shift(int delta) {
return new Range(start + delta, end + delta);
}
public Range clone() {
return new Range(start, end);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(start);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(end);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Range)) return false;
Range it = (Range) obj;
return start == it.start && end == it.end;
}
@Override
public String toString() {
return "[" + start + ", " + end + ")";
}
}

View File

@@ -0,0 +1,100 @@
package org.opencv.core;
//javadoc:Rect_
public class Rect {
public int x, y, width, height;
public Rect(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public Rect() {
this(0, 0, 0, 0);
}
public Rect(Point p1, Point p2) {
x = (int) (p1.x < p2.x ? p1.x : p2.x);
y = (int) (p1.y < p2.y ? p1.y : p2.y);
width = (int) (p1.x > p2.x ? p1.x : p2.x) - x;
height = (int) (p1.y > p2.y ? p1.y : p2.y) - y;
}
public Rect(Point p, Size s) {
this((int) p.x, (int) p.y, (int) s.width, (int) s.height);
}
public Rect(double[] vals) {
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
x = vals.length > 0 ? (int) vals[0] : 0;
y = vals.length > 1 ? (int) vals[1] : 0;
width = vals.length > 2 ? (int) vals[2] : 0;
height = vals.length > 3 ? (int) vals[3] : 0;
} else {
x = 0;
y = 0;
width = 0;
height = 0;
}
}
public Rect clone() {
return new Rect(x, y, width, height);
}
public Point tl() {
return new Point(x, y);
}
public Point br() {
return new Point(x + width, y + height);
}
public Size size() {
return new Size(width, height);
}
public double area() {
return width * height;
}
public boolean contains(Point p) {
return x <= p.x && p.x < x + width && y <= p.y && p.y < y + height;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(height);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(width);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Rect)) return false;
Rect it = (Rect) obj;
return x == it.x && y == it.y && width == it.width && height == it.height;
}
@Override
public String toString() {
return "{" + x + ", " + y + ", " + width + "x" + height + "}";
}
}

View File

@@ -0,0 +1,113 @@
package org.opencv.core;
//javadoc:RotatedRect_
public class RotatedRect {
public Point center;
public Size size;
public double angle;
public RotatedRect() {
this.center = new Point();
this.size = new Size();
this.angle = 0;
}
public RotatedRect(Point c, Size s, double a) {
this.center = c.clone();
this.size = s.clone();
this.angle = a;
}
public RotatedRect(double[] vals) {
this();
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
center.x = vals.length > 0 ? (double) vals[0] : 0;
center.y = vals.length > 1 ? (double) vals[1] : 0;
size.width = vals.length > 2 ? (double) vals[2] : 0;
size.height = vals.length > 3 ? (double) vals[3] : 0;
angle = vals.length > 4 ? (double) vals[4] : 0;
} else {
center.x = 0;
center.x = 0;
size.width = 0;
size.height = 0;
angle = 0;
}
}
public void points(Point pt[])
{
double _angle = angle * Math.PI / 180.0;
double b = (double) Math.cos(_angle) * 0.5f;
double a = (double) Math.sin(_angle) * 0.5f;
pt[0] = new Point(
center.x - a * size.height - b * size.width,
center.y + b * size.height - a * size.width);
pt[1] = new Point(
center.x + a * size.height - b * size.width,
center.y - b * size.height - a * size.width);
pt[2] = new Point(
2 * center.x - pt[0].x,
2 * center.y - pt[0].y);
pt[3] = new Point(
2 * center.x - pt[1].x,
2 * center.y - pt[1].y);
}
public Rect boundingRect()
{
Point pt[] = new Point[4];
points(pt);
Rect r = new Rect((int) Math.floor(Math.min(Math.min(Math.min(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
(int) Math.floor(Math.min(Math.min(Math.min(pt[0].y, pt[1].y), pt[2].y), pt[3].y)),
(int) Math.ceil(Math.max(Math.max(Math.max(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
(int) Math.ceil(Math.max(Math.max(Math.max(pt[0].y, pt[1].y), pt[2].y), pt[3].y)));
r.width -= r.x - 1;
r.height -= r.y - 1;
return r;
}
public RotatedRect clone() {
return new RotatedRect(center, size, angle);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(center.x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(center.y);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(size.width);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(size.height);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(angle);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof RotatedRect)) return false;
RotatedRect it = (RotatedRect) obj;
return center.equals(it.center) && size.equals(it.size) && angle == it.angle;
}
@Override
public String toString() {
return "{ " + center + " " + size + " * " + angle + " }";
}
}

View File

@@ -0,0 +1,90 @@
package org.opencv.core;
//javadoc:Scalar_
public class Scalar {
public double val[];
public Scalar(double v0, double v1, double v2, double v3) {
val = new double[] { v0, v1, v2, v3 };
}
public Scalar(double v0, double v1, double v2) {
val = new double[] { v0, v1, v2, 0 };
}
public Scalar(double v0, double v1) {
val = new double[] { v0, v1, 0, 0 };
}
public Scalar(double v0) {
val = new double[] { v0, 0, 0, 0 };
}
public Scalar(double[] vals) {
if (vals != null && vals.length == 4)
val = vals.clone();
else {
val = new double[4];
set(vals);
}
}
public void set(double[] vals) {
if (vals != null) {
val[0] = vals.length > 0 ? vals[0] : 0;
val[1] = vals.length > 1 ? vals[1] : 0;
val[2] = vals.length > 2 ? vals[2] : 0;
val[3] = vals.length > 3 ? vals[3] : 0;
} else
val[0] = val[1] = val[2] = val[3] = 0;
}
public static Scalar all(double v) {
return new Scalar(v, v, v, v);
}
public Scalar clone() {
return new Scalar(val);
}
public Scalar mul(Scalar it, double scale) {
return new Scalar(val[0] * it.val[0] * scale, val[1] * it.val[1] * scale,
val[2] * it.val[2] * scale, val[3] * it.val[3] * scale);
}
public Scalar mul(Scalar it) {
return mul(it, 1);
}
public Scalar conj() {
return new Scalar(val[0], -val[1], -val[2], -val[3]);
}
public boolean isReal() {
return val[1] == 0 && val[2] == 0 && val[3] == 0;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + java.util.Arrays.hashCode(val);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Scalar)) return false;
Scalar it = (Scalar) obj;
if (!java.util.Arrays.equals(val, it.val)) return false;
return true;
}
@Override
public String toString() {
return "[" + val[0] + ", " + val[1] + ", " + val[2] + ", " + val[3] + "]";
}
}

View File

@@ -0,0 +1,69 @@
package org.opencv.core;
//javadoc:Size_
public class Size {
public double width, height;
public Size(double width, double height) {
this.width = width;
this.height = height;
}
public Size() {
this(0, 0);
}
public Size(Point p) {
width = p.x;
height = p.y;
}
public Size(double[] vals) {
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
width = vals.length > 0 ? vals[0] : 0;
height = vals.length > 1 ? vals[1] : 0;
} else {
width = 0;
height = 0;
}
}
public double area() {
return width * height;
}
public Size clone() {
return new Size(width, height);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(height);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(width);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Size)) return false;
Size it = (Size) obj;
return width == it.width && height == it.height;
}
@Override
public String toString() {
return (int)width + "x" + (int)height;
}
}

View File

@@ -0,0 +1,92 @@
package org.opencv.core;
//javadoc:TermCriteria
public class TermCriteria {
/**
* The maximum number of iterations or elements to compute
*/
public static final int COUNT = 1;
/**
* The maximum number of iterations or elements to compute
*/
public static final int MAX_ITER = COUNT;
/**
* The desired accuracy threshold or change in parameters at which the iterative algorithm is terminated.
*/
public static final int EPS = 2;
public int type;
public int maxCount;
public double epsilon;
/**
* Termination criteria for iterative algorithms.
*
* @param type
* the type of termination criteria: COUNT, EPS or COUNT + EPS.
* @param maxCount
* the maximum number of iterations/elements.
* @param epsilon
* the desired accuracy.
*/
public TermCriteria(int type, int maxCount, double epsilon) {
this.type = type;
this.maxCount = maxCount;
this.epsilon = epsilon;
}
/**
* Termination criteria for iterative algorithms.
*/
public TermCriteria() {
this(0, 0, 0.0);
}
public TermCriteria(double[] vals) {
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
type = vals.length > 0 ? (int) vals[0] : 0;
maxCount = vals.length > 1 ? (int) vals[1] : 0;
epsilon = vals.length > 2 ? (double) vals[2] : 0;
} else {
type = 0;
maxCount = 0;
epsilon = 0;
}
}
public TermCriteria clone() {
return new TermCriteria(type, maxCount, epsilon);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(type);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(maxCount);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(epsilon);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof TermCriteria)) return false;
TermCriteria it = (TermCriteria) obj;
return type == it.type && maxCount == it.maxCount && epsilon == it.epsilon;
}
@Override
public String toString() {
return "{ type: " + type + ", maxCount: " + maxCount + ", epsilon: " + epsilon + "}";
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,63 @@
package org.opencv.test.core;
import org.opencv.core.CvType;
import org.opencv.test.OpenCVTestCase;
public class CvTypeTest extends OpenCVTestCase {
public void testMakeType() {
assertEquals(CvType.CV_8UC4, CvType.makeType(CvType.CV_8U, 4));
}
public void testCV_8UC() {
assertEquals(CvType.CV_8UC4, CvType.CV_8UC(4));
}
public void testCV_8SC() {
assertEquals(CvType.CV_8SC4, CvType.CV_8SC(4));
}
public void testCV_16UC() {
assertEquals(CvType.CV_16UC4, CvType.CV_16UC(4));
}
public void testCV_16SC() {
assertEquals(CvType.CV_16SC4, CvType.CV_16SC(4));
}
public void testCV_32SC() {
assertEquals(CvType.CV_32SC4, CvType.CV_32SC(4));
}
public void testCV_32FC() {
assertEquals(CvType.CV_32FC4, CvType.CV_32FC(4));
}
public void testCV_64FC() {
assertEquals(CvType.CV_64FC4, CvType.CV_64FC(4));
}
public void testChannels() {
assertEquals(1, CvType.channels(CvType.CV_64F));
}
public void testDepth() {
assertEquals(CvType.CV_64F, CvType.depth(CvType.CV_64FC3));
}
public void testIsInteger() {
assertFalse(CvType.isInteger(CvType.CV_32FC3));
assertTrue(CvType.isInteger(CvType.CV_16S));
}
public void testELEM_SIZE() {
assertEquals(3 * 8, CvType.ELEM_SIZE(CvType.CV_64FC3));
}
public void testTypeToString() {
assertEquals("CV_32FC1", CvType.typeToString(CvType.CV_32F));
assertEquals("CV_32FC3", CvType.typeToString(CvType.CV_32FC3));
assertEquals("CV_32FC(128)", CvType.typeToString(CvType.CV_32FC(128)));
}
}

View File

@@ -0,0 +1,44 @@
package org.opencv.test.core;
import org.opencv.core.DMatch;
import junit.framework.TestCase;
public class DMatchTest extends TestCase {
public void testDMatch() {
new DMatch();
}
public void testDMatchIntIntFloat() {
DMatch dm1 = new DMatch(1, 4, 4.0f);
assertEquals(1, dm1.queryIdx);
assertEquals(4, dm1.trainIdx);
assertEquals(4.0f, dm1.distance);
}
public void testDMatchIntIntIntFloat() {
DMatch dm2 = new DMatch(2, 6, -1, 8.0f);
assertEquals(2, dm2.queryIdx);
assertEquals(6, dm2.trainIdx);
assertEquals(-1, dm2.imgIdx);
assertEquals(8.0f, dm2.distance);
}
public void testLessThan() {
DMatch dm1 = new DMatch(1, 4, 4.0f);
DMatch dm2 = new DMatch(2, 6, -1, 8.0f);
assertTrue(dm1.lessThan(dm2));
}
public void testToString() {
DMatch dm2 = new DMatch(2, 6, -1, 8.0f);
String actual = dm2.toString();
String expected = "DMatch [queryIdx=2, trainIdx=6, imgIdx=-1, distance=8.0]";
assertEquals(expected, actual);
}
}

View File

@@ -0,0 +1,71 @@
package org.opencv.test.core;
import org.opencv.core.Point;
import org.opencv.core.KeyPoint;
import org.opencv.test.OpenCVTestCase;
public class KeyPointTest extends OpenCVTestCase {
private float angle;
private int classId;
private KeyPoint keyPoint;
private int octave;
private float response;
private float size;
private float x;
private float y;
@Override
protected void setUp() throws Exception {
super.setUp();
keyPoint = null;
x = 1.0f;
y = 2.0f;
size = 3.0f;
angle = 30.0f;
response = 2.0f;
octave = 1;
classId = 1;
}
public void testKeyPoint() {
keyPoint = new KeyPoint();
assertPointEquals(new Point(0, 0), keyPoint.pt, EPS);
}
public void testKeyPointFloatFloatFloat() {
keyPoint = new KeyPoint(x, y, size);
assertPointEquals(new Point(1, 2), keyPoint.pt, EPS);
}
public void testKeyPointFloatFloatFloatFloat() {
keyPoint = new KeyPoint(x, y, size, 10.0f);
assertEquals(10.0f, keyPoint.angle);
}
public void testKeyPointFloatFloatFloatFloatFloat() {
keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f);
assertEquals(1.0f, keyPoint.response);
}
public void testKeyPointFloatFloatFloatFloatFloatInt() {
keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f, 1);
assertEquals(1, keyPoint.octave);
}
public void testKeyPointFloatFloatFloatFloatFloatIntInt() {
keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f, 1, 1);
assertEquals(1, keyPoint.class_id);
}
public void testToString() {
keyPoint = new KeyPoint(x, y, size, angle, response, octave, classId);
String actual = keyPoint.toString();
String expected = "KeyPoint [pt={1.0, 2.0}, size=3.0, angle=30.0, response=2.0, octave=1, class_id=1]";
assertEquals(expected, actual);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,107 @@
package org.opencv.test.core;
import org.opencv.core.Point;
import org.opencv.core.Point3;
import org.opencv.test.OpenCVTestCase;
public class Point3Test extends OpenCVTestCase {
private Point3 p1;
private Point3 p2;
@Override
protected void setUp() throws Exception {
super.setUp();
p1 = new Point3(2, 2, 2);
p2 = new Point3(1, 1, 1);
}
public void testClone() {
Point3 truth = new Point3(1, 1, 1);
p1 = truth.clone();
assertEquals(truth, p1);
}
public void testCross() {
Point3 dstPoint = p1.cross(p2);
Point3 truth = new Point3(0, 0, 0);
assertEquals(truth, dstPoint);
}
public void testDot() {
double result = p1.dot(p2);
assertEquals(6.0, result);
}
public void testEqualsObject() {
boolean flag = p1.equals(p1);
assertTrue(flag);
flag = p1.equals(p2);
assertFalse(flag);
}
public void testHashCode() {
assertEquals(p1.hashCode(), p1.hashCode());
}
public void testPoint3() {
p1 = new Point3();
assertNotNull(p1);
assertTrue(0 == p1.x);
assertTrue(0 == p1.y);
assertTrue(0 == p1.z);
}
public void testPoint3DoubleArray() {
double[] vals = { 1, 2, 3 };
p1 = new Point3(vals);
assertTrue(1 == p1.x);
assertTrue(2 == p1.y);
assertTrue(3 == p1.z);
}
public void testPoint3DoubleDoubleDouble() {
p1 = new Point3(1, 2, 3);
assertEquals(1., p1.x);
assertEquals(2., p1.y);
assertEquals(3., p1.z);
}
public void testPoint3Point() {
Point p = new Point(2, 3);
p1 = new Point3(p);
assertEquals(2., p1.x);
assertEquals(3., p1.y);
assertEquals(0., p1.z);
}
public void testSet() {
double[] vals1 = {};
p1.set(vals1);
assertEquals(0., p1.x);
assertEquals(0., p1.y);
assertEquals(0., p1.z);
double[] vals2 = { 3, 6, 10 };
p1.set(vals2);
assertEquals(3., p1.x);
assertEquals(6., p1.y);
assertEquals(10., p1.z);
}
public void testToString() {
String actual = p1.toString();
String expected = "{2.0, 2.0, 2.0}";
assertEquals(expected, actual);
}
}

View File

@@ -0,0 +1,93 @@
package org.opencv.test.core;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.test.OpenCVTestCase;
public class PointTest extends OpenCVTestCase {
private Point p1;
private Point p2;
@Override
protected void setUp() throws Exception {
super.setUp();
p1 = new Point(2, 2);
p2 = new Point(1, 1);
}
public void testClone() {
Point truth = new Point(1, 1);
Point dstPoint = truth.clone();
assertEquals(truth, dstPoint);
}
public void testDot() {
double result = p1.dot(p2);
assertEquals(4.0, result);
}
public void testEqualsObject() {
boolean flag = p1.equals(p1);
assertTrue(flag);
flag = p1.equals(p2);
assertFalse(flag);
}
public void testHashCode() {
assertEquals(p1.hashCode(), p1.hashCode());
}
public void testInside() {
Rect rect = new Rect(0, 0, 5, 3);
assertTrue(p1.inside(rect));
Point p2 = new Point(3, 3);
assertFalse(p2.inside(rect));
}
public void testPoint() {
Point p = new Point();
assertNotNull(p);
assertEquals(0.0, p.x);
assertEquals(0.0, p.y);
}
public void testPointDoubleArray() {
double[] vals = { 2, 4 };
Point p = new Point(vals);
assertEquals(2.0, p.x);
assertEquals(4.0, p.y);
}
public void testPointDoubleDouble() {
p1 = new Point(7, 5);
assertNotNull(p1);
assertEquals(7.0, p1.x);
assertEquals(5.0, p1.y);
}
public void testSet() {
double[] vals1 = {};
p1.set(vals1);
assertEquals(0.0, p1.x);
assertEquals(0.0, p1.y);
double[] vals2 = { 6, 10 };
p2.set(vals2);
assertEquals(6.0, p2.x);
assertEquals(10.0, p2.y);
}
public void testToString() {
String actual = p1.toString();
String expected = "{2.0, 2.0}";
assertEquals(expected, actual);
}
}

View File

@@ -0,0 +1,113 @@
package org.opencv.test.core;
import org.opencv.core.Range;
import org.opencv.test.OpenCVTestCase;
public class RangeTest extends OpenCVTestCase {
Range r1;
Range r2;
Range range;
@Override
protected void setUp() throws Exception {
super.setUp();
range = new Range();
r1 = new Range(1, 11);
r2 = new Range(1, 1);
}
public void testAll() {
range = Range.all();
assertEquals(Integer.MIN_VALUE, range.start);
assertEquals(Integer.MAX_VALUE, range.end);
}
public void testClone() {
Range dstRange = new Range();
dstRange = r1.clone();
assertEquals(r1, dstRange);
}
public void testEmpty() {
boolean flag;
flag = r1.empty();
assertFalse(flag);
flag = r2.empty();
assertTrue(flag);
}
public void testEqualsObject() {
assertFalse(r2.equals(r1));
range = r1.clone();
assertTrue(r1.equals(range));
}
public void testHashCode() {
assertEquals(r1.hashCode(), r1.hashCode());
}
public void testIntersection() {
range = r1.intersection(r2);
assertEquals(r2, range);
}
public void testRange() {
range = new Range();
assertNotNull(range);
assertEquals(0, range.start);
assertEquals(0, range.end);
}
public void testRangeDoubleArray() {
double[] vals = { 2, 4 };
Range r = new Range(vals);
assertTrue(2 == r.start);
assertTrue(4 == r.end);
}
public void testRangeIntInt() {
r1 = new Range(12, 13);
assertNotNull(r1);
assertEquals(12, r1.start);
assertEquals(13, r1.end);
}
public void testSet() {
double[] vals1 = {};
r1.set(vals1);
assertEquals(0, r1.start);
assertEquals(0, r1.end);
double[] vals2 = { 6, 10 };
r2.set(vals2);
assertEquals(6, r2.start);
assertEquals(10, r2.end);
}
public void testShift() {
int delta = 1;
range = range.shift(delta);
assertEquals(r2, range);
}
public void testSize() {
assertEquals(10, r1.size());
assertEquals(0, r2.size());
}
public void testToString() {
String actual = r1.toString();
String expected = "[1, 11)";
assertEquals(expected, actual);
}
}

View File

@@ -0,0 +1,163 @@
package org.opencv.test.core;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Size;
import org.opencv.test.OpenCVTestCase;
public class RectTest extends OpenCVTestCase {
private Rect r;
private Rect rect;
@Override
protected void setUp() throws Exception {
super.setUp();
r = new Rect();
rect = new Rect(0, 0, 10, 10);
}
public void testArea() {
double area;
area = rect.area();
assertEquals(100.0, area);
}
public void testBr() {
Point p_br = new Point();
p_br = rect.br();
Point truth = new Point(10, 10);
assertEquals(truth, p_br);
}
public void testClone() {
r = rect.clone();
assertEquals(rect, r);
}
public void testContains() {
Rect rect = new Rect(0, 0, 10, 10);
Point p_inner = new Point(5, 5);
Point p_outer = new Point(5, 55);
Point p_bl = new Point(0, 0);
Point p_br = new Point(10, 0);
Point p_tl = new Point(0, 10);
Point p_tr = new Point(10, 10);
assertTrue(rect.contains(p_inner));
assertTrue(rect.contains(p_bl));
assertFalse(rect.contains(p_outer));
assertFalse(rect.contains(p_br));
assertFalse(rect.contains(p_tl));
assertFalse(rect.contains(p_tr));
}
public void testEqualsObject() {
boolean flag;
flag = rect.equals(r);
assertFalse(flag);
r = rect.clone();
flag = rect.equals(r);
assertTrue(flag);
}
public void testHashCode() {
assertEquals(rect.hashCode(), rect.hashCode());
}
public void testRect() {
r = new Rect();
assertEquals(0, r.x);
assertEquals(0, r.y);
assertEquals(0, r.width);
assertEquals(0, r.height);
}
public void testRectDoubleArray() {
double[] vals = { 1, 3, 5, 2 };
r = new Rect(vals);
assertEquals(1, r.x);
assertEquals(3, r.y);
assertEquals(5, r.width);
assertEquals(2, r.height);
}
public void testRectIntIntIntInt() {
r = new Rect(1, 3, 5, 2);
assertNotNull(rect);
assertEquals(0, rect.x);
assertEquals(0, rect.y);
assertEquals(10, rect.width);
assertEquals(10, rect.height);
}
public void testRectPointPoint() {
Point p1 = new Point(4, 4);
Point p2 = new Point(2, 3);
r = new Rect(p1, p2);
assertNotNull(r);
assertEquals(2, r.x);
assertEquals(3, r.y);
assertEquals(2, r.width);
assertEquals(1, r.height);
}
public void testRectPointSize() {
Point p1 = new Point(4, 4);
Size sz = new Size(3, 1);
r = new Rect(p1, sz);
assertEquals(4, r.x);
assertEquals(4, r.y);
assertEquals(3, r.width);
assertEquals(1, r.height);
}
public void testSet() {
double[] vals1 = {};
Rect r1 = new Rect(vals1);
assertEquals(0, r1.x);
assertEquals(0, r1.y);
assertEquals(0, r1.width);
assertEquals(0, r1.height);
double[] vals2 = { 2, 2, 10, 5 };
r = new Rect(vals2);
assertEquals(2, r.x);
assertEquals(2, r.y);
assertEquals(10, r.width);
assertEquals(5, r.height);
}
public void testSize() {
Size s1 = new Size(0, 0);
assertEquals(s1, r.size());
Size s2 = new Size(10, 10);
assertEquals(s2, rect.size());
}
public void testTl() {
Point p_tl = new Point();
p_tl = rect.tl();
Point truth = new Point(0, 0);
assertEquals(truth, p_tl);
}
public void testToString() {
String actual = rect.toString();
String expected = "{0, 0, 10x10}";
assertEquals(expected, actual);
}
}

View File

@@ -0,0 +1,191 @@
package org.opencv.test.core;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.RotatedRect;
import org.opencv.core.Size;
import org.opencv.test.OpenCVTestCase;
public class RotatedRectTest extends OpenCVTestCase {
private double angle;
private Point center;
private Size size;
@Override
protected void setUp() throws Exception {
super.setUp();
center = new Point(matSize / 2, matSize / 2);
size = new Size(matSize / 4, matSize / 2);
angle = 40;
}
public void testBoundingRect() {
size = new Size(matSize / 2, matSize / 2);
assertEquals(size.height, size.width);
double length = size.height;
angle = 45;
RotatedRect rr = new RotatedRect(center, size, angle);
Rect r = rr.boundingRect();
double halfDiagonal = length * Math.sqrt(2) / 2;
assertTrue((r.x == Math.floor(center.x - halfDiagonal)) && (r.y == Math.floor(center.y - halfDiagonal)));
assertTrue((r.br().x >= Math.ceil(center.x + halfDiagonal)) && (r.br().y >= Math.ceil(center.y + halfDiagonal)));
assertTrue((r.br().x - Math.ceil(center.x + halfDiagonal)) <= 1 && (r.br().y - Math.ceil(center.y + halfDiagonal)) <= 1);
}
public void testClone() {
RotatedRect rrect = new RotatedRect(center, size, angle);
RotatedRect clone = rrect.clone();
assertTrue(clone != null);
assertTrue(rrect.center.equals(clone.center));
assertTrue(rrect.size.equals(clone.size));
assertTrue(rrect.angle == clone.angle);
}
public void testEqualsObject() {
Point center2 = new Point(matSize / 3, matSize / 1.5);
Size size2 = new Size(matSize / 2, matSize / 4);
double angle2 = 0;
RotatedRect rrect1 = new RotatedRect(center, size, angle);
RotatedRect rrect2 = new RotatedRect(center2, size2, angle2);
RotatedRect rrect3 = rrect1;
RotatedRect clone1 = rrect1.clone();
RotatedRect clone2 = rrect2.clone();
assertTrue(rrect1.equals(rrect3));
assertTrue(!rrect1.equals(rrect2));
assertTrue(rrect2.equals(clone2));
clone2.angle = 10;
assertTrue(!rrect2.equals(clone2));
assertTrue(rrect1.equals(clone1));
clone1.center.x += 1;
assertTrue(!rrect1.equals(clone1));
clone1.center.x -= 1;
assertTrue(rrect1.equals(clone1));
clone1.size.width += 1;
assertTrue(!rrect1.equals(clone1));
assertTrue(!rrect1.equals(size));
}
public void testHashCode() {
RotatedRect rr = new RotatedRect(center, size, angle);
assertEquals(rr.hashCode(), rr.hashCode());
}
public void testPoints() {
RotatedRect rrect = new RotatedRect(center, size, angle);
Point p[] = new Point[4];
rrect.points(p);
boolean is_p0_irrational = (100 * p[0].x != (int) (100 * p[0].x)) && (100 * p[0].y != (int) (100 * p[0].y));
boolean is_p1_irrational = (100 * p[1].x != (int) (100 * p[1].x)) && (100 * p[1].y != (int) (100 * p[1].y));
boolean is_p2_irrational = (100 * p[2].x != (int) (100 * p[2].x)) && (100 * p[2].y != (int) (100 * p[2].y));
boolean is_p3_irrational = (100 * p[3].x != (int) (100 * p[3].x)) && (100 * p[3].y != (int) (100 * p[3].y));
assertTrue(is_p0_irrational && is_p1_irrational && is_p2_irrational && is_p3_irrational);
assertTrue("Symmetric points 0 and 2",
Math.abs((p[0].x + p[2].x) / 2 - center.x) + Math.abs((p[0].y + p[2].y) / 2 - center.y) < EPS);
assertTrue("Symmetric points 1 and 3",
Math.abs((p[1].x + p[3].x) / 2 - center.x) + Math.abs((p[1].y + p[3].y) / 2 - center.y) < EPS);
assertTrue("Orthogonal vectors 01 and 12",
Math.abs((p[1].x - p[0].x) * (p[2].x - p[1].x) +
(p[1].y - p[0].y) * (p[2].y - p[1].y)) < EPS);
assertTrue("Orthogonal vectors 12 and 23",
Math.abs((p[2].x - p[1].x) * (p[3].x - p[2].x) +
(p[2].y - p[1].y) * (p[3].y - p[2].y)) < EPS);
assertTrue("Orthogonal vectors 23 and 30",
Math.abs((p[3].x - p[2].x) * (p[0].x - p[3].x) +
(p[3].y - p[2].y) * (p[0].y - p[3].y)) < EPS);
assertTrue("Orthogonal vectors 30 and 01",
Math.abs((p[0].x - p[3].x) * (p[1].x - p[0].x) +
(p[0].y - p[3].y) * (p[1].y - p[0].y)) < EPS);
assertTrue("Length of the vector 01",
Math.abs((p[1].x - p[0].x) * (p[1].x - p[0].x) +
(p[1].y - p[0].y) * (p[1].y - p[0].y) - size.height * size.height) < EPS);
assertTrue("Length of the vector 21",
Math.abs((p[1].x - p[2].x) * (p[1].x - p[2].x) +
(p[1].y - p[2].y) * (p[1].y - p[2].y) - size.width * size.width) < EPS);
assertTrue("Angle of the vector 21 with the axes", Math.abs((p[2].x - p[1].x) / size.width - Math.cos(angle * Math.PI / 180)) < EPS);
}
public void testRotatedRect() {
RotatedRect rr = new RotatedRect();
assertTrue(rr != null);
assertTrue(rr.center != null);
assertTrue(rr.size != null);
assertTrue(rr.angle == 0.0);
}
public void testRotatedRectDoubleArray() {
double[] vals = { 1.5, 2.6, 3.7, 4.2, 5.1 };
RotatedRect rr = new RotatedRect(vals);
assertNotNull(rr);
assertEquals(1.5, rr.center.x);
assertEquals(2.6, rr.center.y);
assertEquals(3.7, rr.size.width);
assertEquals(4.2, rr.size.height);
assertEquals(5.1, rr.angle);
}
public void testRotatedRectPointSizeDouble() {
RotatedRect rr = new RotatedRect(center, size, 40);
assertTrue(rr != null);
assertTrue(rr.center != null);
assertTrue(rr.size != null);
assertTrue(rr.angle == 40.0);
}
public void testSet() {
double[] vals1 = {};
RotatedRect r1 = new RotatedRect(center, size, 40);
r1.set(vals1);
assertEquals(0., r1.angle);
assertPointEquals(new Point(0, 0), r1.center, EPS);
assertSizeEquals(new Size(0, 0), r1.size, EPS);
double[] vals2 = { 1, 2, 3, 4, 5 };
RotatedRect r2 = new RotatedRect(center, size, 40);
r2.set(vals2);
assertEquals(5., r2.angle);
assertPointEquals(new Point(1, 2), r2.center, EPS);
assertSizeEquals(new Size(3, 4), r2.size, EPS);
}
public void testToString() {
String actual = new RotatedRect(new Point(1, 2), new Size(10, 12), 4.5).toString();
String expected = "{ {1.0, 2.0} 10x12 * 4.5 }";
assertEquals(expected, actual);
}
}

View File

@@ -0,0 +1,110 @@
package org.opencv.test.core;
import org.opencv.core.Scalar;
import org.opencv.test.OpenCVTestCase;
public class ScalarTest extends OpenCVTestCase {
private Scalar dstScalar;
private Scalar s1;
private Scalar s2;
@Override
protected void setUp() throws Exception {
super.setUp();
s1 = new Scalar(1.0);
s2 = Scalar.all(1.0);
dstScalar = null;
}
public void testAll() {
dstScalar = Scalar.all(2.0);
Scalar truth = new Scalar(2.0, 2.0, 2.0, 2.0);
assertEquals(truth, dstScalar);
}
public void testClone() {
dstScalar = s2.clone();
assertEquals(s2, dstScalar);
}
public void testConj() {
dstScalar = s2.conj();
Scalar truth = new Scalar(1, -1, -1, -1);
assertEquals(truth, dstScalar);
}
public void testEqualsObject() {
dstScalar = s2.clone();
assertTrue(s2.equals(dstScalar));
assertFalse(s2.equals(s1));
}
public void testHashCode() {
assertEquals(s2.hashCode(), s2.hashCode());
}
public void testIsReal() {
assertTrue(s1.isReal());
assertFalse(s2.isReal());
}
public void testMulScalar() {
dstScalar = s2.mul(s1);
assertEquals(s1, dstScalar);
}
public void testMulScalarDouble() {
double multiplier = 2.0;
dstScalar = s2.mul(s1, multiplier);
Scalar truth = new Scalar(2);
assertEquals(truth, dstScalar);
}
public void testScalarDouble() {
Scalar truth = new Scalar(1);
assertEquals(truth, s1);
}
public void testScalarDoubleArray() {
double[] vals = { 2.0, 4.0, 5.0, 3.0 };
dstScalar = new Scalar(vals);
Scalar truth = new Scalar(2.0, 4.0, 5.0, 3.0);
assertEquals(truth, dstScalar);
}
public void testScalarDoubleDouble() {
dstScalar = new Scalar(2, 5);
Scalar truth = new Scalar(2.0, 5.0, 0.0, 0.0);
assertEquals(truth, dstScalar);
}
public void testScalarDoubleDoubleDouble() {
dstScalar = new Scalar(2.0, 5.0, 5.0);
Scalar truth = new Scalar(2.0, 5.0, 5.0, 0.0);
assertEquals(truth, dstScalar);
}
public void testScalarDoubleDoubleDoubleDouble() {
dstScalar = new Scalar(2.0, 5.0, 5.0, 9.0);
Scalar truth = new Scalar(2.0, 5.0, 5.0, 9.0);
assertEquals(truth, dstScalar);
}
public void testSet() {
double[] vals = { 1.0, 1.0, 1.0, 1.0 };
s1.set(vals);
assertEquals(s2, s1);
}
public void testToString() {
String actual = s2.toString();
String expected = "[1.0, 1.0, 1.0, 1.0]";
assertEquals(expected, actual);
}
}

View File

@@ -0,0 +1,93 @@
package org.opencv.test.core;
import org.opencv.core.Point;
import org.opencv.core.Size;
import org.opencv.test.OpenCVTestCase;
public class SizeTest extends OpenCVTestCase {
Size dstSize;
Size sz1;
Size sz2;
@Override
protected void setUp() throws Exception {
super.setUp();
sz1 = new Size(10.0, 10.0);
sz2 = new Size(-1, -1);
dstSize = null;
}
public void testArea() {
double area = sz1.area();
assertEquals(100.0, area);
}
public void testClone() {
dstSize = sz1.clone();
assertEquals(sz1, dstSize);
}
public void testEqualsObject() {
assertFalse(sz1.equals(sz2));
sz2 = sz1.clone();
assertTrue(sz1.equals(sz2));
}
public void testHashCode() {
assertEquals(sz1.hashCode(), sz1.hashCode());
}
public void testSet() {
double[] vals1 = {};
sz2.set(vals1);
assertEquals(0., sz2.width);
assertEquals(0., sz2.height);
double[] vals2 = { 9, 12 };
sz1.set(vals2);
assertEquals(9., sz1.width);
assertEquals(12., sz1.height);
}
public void testSize() {
dstSize = new Size();
assertNotNull(dstSize);
assertEquals(0., dstSize.width);
assertEquals(0., dstSize.height);
}
public void testSizeDoubleArray() {
double[] vals = { 10, 20 };
sz2 = new Size(vals);
assertEquals(10., sz2.width);
assertEquals(20., sz2.height);
}
public void testSizeDoubleDouble() {
assertNotNull(sz1);
assertEquals(10.0, sz1.width);
assertEquals(10.0, sz1.height);
}
public void testSizePoint() {
Point p = new Point(2, 4);
sz1 = new Size(p);
assertNotNull(sz1);
assertEquals(2.0, sz1.width);
assertEquals(4.0, sz1.height);
}
public void testToString() {
String actual = sz1.toString();
String expected = "10x10";
assertEquals(expected, actual);
}
}

View File

@@ -0,0 +1,86 @@
package org.opencv.test.core;
import org.opencv.core.TermCriteria;
import org.opencv.test.OpenCVTestCase;
public class TermCriteriaTest extends OpenCVTestCase {
private TermCriteria tc1;
private TermCriteria tc2;
@Override
protected void setUp() throws Exception {
super.setUp();
tc1 = new TermCriteria();
tc2 = new TermCriteria(2, 4, EPS);
}
public void testClone() {
tc1 = tc2.clone();
assertEquals(tc2, tc1);
}
public void testEqualsObject() {
assertFalse(tc2.equals(tc1));
tc1 = tc2.clone();
assertTrue(tc2.equals(tc1));
}
public void testHashCode() {
assertEquals(tc2.hashCode(), tc2.hashCode());
}
public void testSet() {
double[] vals1 = {};
tc1.set(vals1);
assertEquals(0, tc1.type);
assertEquals(0, tc1.maxCount);
assertEquals(0.0, tc1.epsilon);
double[] vals2 = { 9, 8, 0.002 };
tc2.set(vals2);
assertEquals(9, tc2.type);
assertEquals(8, tc2.maxCount);
assertEquals(0.002, tc2.epsilon);
}
public void testTermCriteria() {
tc1 = new TermCriteria();
assertNotNull(tc1);
assertEquals(0, tc1.type);
assertEquals(0, tc1.maxCount);
assertEquals(0.0, tc1.epsilon);
}
public void testTermCriteriaDoubleArray() {
double[] vals = { 3, 2, 0.007 };
tc1 = new TermCriteria(vals);
assertEquals(3, tc1.type);
assertEquals(2, tc1.maxCount);
assertEquals(0.007, tc1.epsilon);
}
public void testTermCriteriaIntIntDouble() {
tc1 = new TermCriteria(2, 4, EPS);
assertNotNull(tc2);
assertEquals(2, tc2.type);
assertEquals(4, tc2.maxCount);
assertEquals(EPS, tc2.epsilon);
}
public void testToString() {
String actual = tc2.toString();
double eps = EPS;
String expected = "{ type: 2, maxCount: 4, epsilon: " + eps + "}";
assertEquals(expected, actual);
}
}