Skip to content

Commit

Permalink
* Upgrade dependencies for OpenCV 4.0.0-rc
Browse files Browse the repository at this point in the history
  • Loading branch information
saudet committed Nov 15, 2018
1 parent 2448229 commit 88e6df6
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 138 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -2,7 +2,7 @@
* Add support for multiple inputs to `FFmpegFrameFilter` ([issue #955](https://github.com/bytedeco/javacv/issues/955))
* Fix fps in output of `FFmpegFrameRecorder` by setting deprecated `AVStream.codec.time_base` ([issue #1069](https://github.com/bytedeco/javacv/issues/1069))
* Fix memory leak in `FFmpegFrameRecorder` on `writePacket()` ([issue #1068](https://github.com/bytedeco/javacv/issues/1068))
* Upgrade dependencies for FFmpeg 4.0.3 and Tesseract 4.0.0
* Upgrade dependencies for OpenCV 4.0.0-rc, FFmpeg 4.1, and Tesseract 4.0.0

### October 15, 2018 version 1.4.3
* Add `imageScalingFlags` property to `FrameGrabber` and `FrameRecorder`, with `SWS_BILINEAR` as default for FFmpeg ([issue #845](https://github.com/bytedeco/javacv/issues/845))
Expand Down
4 changes: 2 additions & 2 deletions platform/pom.xml
Expand Up @@ -28,12 +28,12 @@
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>opencv-platform</artifactId>
<version>3.4.3-${javacpp.version}</version>
<version>4.0.0-rc-${javacpp.version}</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>ffmpeg-platform</artifactId>
<version>4.0.3-${javacpp.version}</version>
<version>4.1-${javacpp.version}</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -74,12 +74,12 @@
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>opencv</artifactId>
<version>3.4.3-${javacpp.version}</version>
<version>4.0.0-rc-${javacpp.version}</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>ffmpeg</artifactId>
<version>4.0.3-${javacpp.version}</version>
<version>4.1-${javacpp.version}</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
Expand Down
3 changes: 1 addition & 2 deletions samples/Demo.java
Expand Up @@ -113,8 +113,7 @@ public static void main(String[] args) throws Exception {
// Let's try to detect some faces! but we need a grayscale image...
cvtColor(grabbedImage, grayImage, CV_BGR2GRAY);
RectVector faces = new RectVector();
classifier.detectMultiScale(grayImage, faces,
1.1, 3, CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH, null, null);
classifier.detectMultiScale(grayImage, faces);
long total = faces.size();
for (long i = 0; i < total; i++) {
Rect r = faces.get(i);
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/bytedeco/javacv/CameraDevice.java
Expand Up @@ -45,7 +45,7 @@ public CameraDevice(String name, String filename) throws Exception {
settings.setImageWidth(imageWidth);
settings.setImageHeight(imageHeight);
}
public CameraDevice(String name, CvFileStorage fs) throws Exception {
public CameraDevice(String name, FileStorage fs) throws Exception {
super(name, fs);
settings.setImageWidth(imageWidth);
settings.setImageHeight(imageHeight);
Expand Down Expand Up @@ -514,21 +514,21 @@ public FrameGrabber createFrameGrabber() throws FrameGrabber.Exception {
}

public static CameraDevice[] read(String filename) throws Exception {
CvFileStorage fs = CvFileStorage.open(filename, null, CV_STORAGE_READ);
FileStorage fs = new FileStorage(filename, FileStorage.READ);
CameraDevice[] devices = read(fs);
fs.release();
return devices;
}
public static CameraDevice[] read(CvFileStorage fs) throws Exception {
CvFileNode node = cvGetFileNodeByName(fs, null, "Cameras");
CvSeq seq = node.data_seq();
int count = seq.total();
public static CameraDevice[] read(FileStorage fs) throws Exception {
FileNode node = fs.get("Cameras");
FileNodeIterator seq = node.begin();
int count = (int)seq.remaining();

CameraDevice[] devices = new CameraDevice[count];
for (int i = 0; i < count; i++) {
Pointer p = cvGetSeqElem(seq, i);
if (p == null) continue;
String name = cvReadString(new CvFileNode(p), (String)null);
for (int i = 0; i < count; i++, seq.increment()) {
FileNode n = seq.access();
if (n.empty()) continue;
String name = n.asBytePointer().getString();
devices[i] = new CameraDevice(name, fs);
}
return devices;
Expand Down
72 changes: 57 additions & 15 deletions src/main/java/org/bytedeco/javacv/GeometricCalibrator.java
Expand Up @@ -209,6 +209,38 @@ public int getImageCount() {
return allObjectMarkers.size();
}

private Point3fVectorVector getObjectPoints(CvMat points, CvMat counts) {
FloatBuffer pointsBuf = points.getFloatBuffer();
IntBuffer countsBuf = counts.getIntBuffer();
int n = counts.length();
Point3fVectorVector vectors = new Point3fVectorVector(n);
for (int i = 0; i < n; i++) {
int m = countsBuf.get();
Point3fVector vector = new Point3fVector(m);
for (int j = 0; j < m; j++) {
vector.put(j, new Point3f(pointsBuf.get(), pointsBuf.get(), pointsBuf.get()));
}
vectors.put(i, vector);
}
return vectors;
}

private Point2fVectorVector getImagePoints(CvMat points, CvMat counts) {
FloatBuffer pointsBuf = points.getFloatBuffer();
IntBuffer countsBuf = counts.getIntBuffer();
int n = counts.length();
Point2fVectorVector vectors = new Point2fVectorVector(n);
for (int i = 0; i < n; i++) {
int m = countsBuf.get();
Point2fVector vector = new Point2fVector(m);
for (int j = 0; j < m; j++) {
vector.put(j, new Point2f(pointsBuf.get(), pointsBuf.get()));
}
vectors.put(i, vector);
}
return vectors;
}

private CvMat[] getPoints(boolean useCenters) {
// fill up pointCounts, objectPoints and imagePoints, with data from
// srcMarkers and dstMarkers
Expand Down Expand Up @@ -294,8 +326,8 @@ public static double[] computeReprojectionError(CvMat object_points,
cvGetRows(rot_vects, rot_vect, i, i+1, 1);
cvGetRows(trans_vects, trans_vect, i, i+1, 1);

cvProjectPoints2(object_points_i, rot_vect, trans_vect,
camera_matrix, dist_coeffs, image_points2_i);
projectPoints(cvarrToMat(object_points_i), cvarrToMat(rot_vect), cvarrToMat(trans_vect),
cvarrToMat(camera_matrix), cvarrToMat(dist_coeffs), cvarrToMat(image_points2_i));
err = cvNorm(image_points_i, image_points2_i);
err *= err;
if (per_view_errors != null)
Expand Down Expand Up @@ -347,11 +379,21 @@ public double[] calibrate(boolean useCenters) {
cvGetCols(d.extrParams, transVects, 3, 6);

CvMat[] points = getPoints(useCenters);
cvCalibrateCamera2(points[0], points[1], points[2],
cvSize(d.imageWidth, d.imageHeight),
d.cameraMatrix, d.distortionCoeffs,
rotVects, transVects, dsettings.flags,
cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 30, JavaCV.DBL_EPSILON));
MatVector rvecs = new MatVector();
MatVector tvecs = new MatVector();
Mat distortionCoeffs = new Mat();
calibrateCamera(getObjectPoints(points[0], points[2]), getImagePoints(points[1], points[2]),
new Size(d.imageWidth, d.imageHeight),
cvarrToMat(d.cameraMatrix), distortionCoeffs,
rvecs, tvecs, dsettings.flags,
new TermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 30, JavaCV.DBL_EPSILON));
int n = (int)rvecs.size();
CvMat row = new CvMat();
for (int i = 0; i < n; i++) {
cvTranspose(cvMat(rvecs.get(i)), cvGetRow(rotVects, row, i));
cvTranspose(cvMat(tvecs.get(i)), cvGetRow(transVects, row, i));
}
d.distortionCoeffs = cvMat(distortionCoeffs).clone();

if (cvCheckArr(d.cameraMatrix, CV_CHECK_QUIET, 0, 0) != 0 &&
cvCheckArr(d.distortionCoeffs, CV_CHECK_QUIET, 0, 0) != 0 &&
Expand Down Expand Up @@ -383,12 +425,12 @@ public static double[] computeStereoError(CvMat imagePoints1, CvMat imagePoints2
CvMat L1 = CvMat.create(1, N, CV_32F, 3);
CvMat L2 = CvMat.create(1, N, CV_32F, 3);
//Always work in undistorted space
cvUndistortPoints(imagePoints1, imagePoints1, M1, D1, null, M1);
cvUndistortPoints(imagePoints2, imagePoints2, M2, D2, null, M2);
undistortPoints(cvarrToMat(imagePoints1), cvarrToMat(imagePoints1), cvarrToMat(M1), cvarrToMat(D1), null, cvarrToMat(M1));
undistortPoints(cvarrToMat(imagePoints2), cvarrToMat(imagePoints2), cvarrToMat(M2), cvarrToMat(D2), null, cvarrToMat(M2));
//imagePoints1.put(d1.undistort(imagePoints1.get()));
//imagePoints2.put(d2.undistort(imagePoints2.get()));
cvComputeCorrespondEpilines(imagePoints1, 1, F, L1);
cvComputeCorrespondEpilines(imagePoints2, 2, F, L2);
computeCorrespondEpilines(cvarrToMat(imagePoints1), 1, cvarrToMat(F), cvarrToMat(L1));
computeCorrespondEpilines(cvarrToMat(imagePoints2), 2, cvarrToMat(F), cvarrToMat(L2));
double avgErr = 0, maxErr = 0;
CvMat p1 = imagePoints1, p2 = imagePoints2;
for(int i = 0; i < N; i++ ) {
Expand Down Expand Up @@ -488,10 +530,10 @@ public double[] calibrateStereo(boolean useCenters, GeometricCalibrator peer) {
dp.E = CvMat.create(3, 3);
dp.F = CvMat.create(3, 3);

cvStereoCalibrate(objectPointsMat, imagePoints1Mat, imagePoints2Mat, pointCountsMat,
d.cameraMatrix, d.distortionCoeffs, dp.cameraMatrix, dp.distortionCoeffs,
cvSize(d.imageWidth, d.imageHeight), dp.R, dp.T, dp.E, dp.F, dpsettings.flags,
cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,100,1e-6));
stereoCalibrate(getObjectPoints(objectPointsMat, pointCountsMat), getImagePoints(imagePoints1Mat, pointCountsMat), getImagePoints(imagePoints2Mat, pointCountsMat),
cvarrToMat(d.cameraMatrix), cvarrToMat(d.distortionCoeffs), cvarrToMat(dp.cameraMatrix), cvarrToMat(dp.distortionCoeffs),
new Size(d.imageWidth, d.imageHeight), cvarrToMat(dp.R), cvarrToMat(dp.T), cvarrToMat(dp.E), cvarrToMat(dp.F), dpsettings.flags,
new TermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,100,1e-6));

// compute and return epipolar error...
d.avgEpipolarErr = 0.0;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/bytedeco/javacv/IPCameraFrameGrabber.java
Expand Up @@ -68,7 +68,7 @@ public static void tryLoad() throws Exception {
private final int readTimeout;
private DataInputStream input;
private byte[] pixelBuffer = new byte[1024];
private IplImage decoded = null;
private Mat decoded = null;

/**
* @param url The URL to create the camera connection with.
Expand Down Expand Up @@ -160,9 +160,9 @@ public void trigger() throws Exception {
public Frame grab() throws Exception {
try {
final byte[] b = readImage();
final CvMat mat = cvMat(1, b.length, CV_8UC1, new BytePointer(b));
final Mat mat = new Mat(1, b.length, CV_8UC1, new BytePointer(b));
releaseDecoded();
return converter.convert(decoded = cvDecodeImage(mat));
return converter.convert(decoded = imdecode(mat, IMREAD_COLOR));
} catch (IOException e) {
throw new Exception(e.getMessage(), e);
}
Expand All @@ -180,7 +180,7 @@ public BufferedImage grabBufferedImage() throws IOException {
*/
private void releaseDecoded() {
if (decoded != null) {
cvReleaseImage(decoded);
decoded.release();
decoded = null;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/bytedeco/javacv/JavaCvErrorCallback.java
Expand Up @@ -38,6 +38,8 @@
*/
public class JavaCvErrorCallback extends CvErrorCallback {

static JavaCvErrorCallback instance;

public JavaCvErrorCallback() {
this(false);
}
Expand All @@ -48,6 +50,7 @@ public JavaCvErrorCallback(boolean showDialog, Component parent) {
this(showDialog, parent, 0);
}
public JavaCvErrorCallback(boolean showDialog, Component parent, int rc) {
instance = this;
this.parent = parent;
this.showDialog = showDialog;
this.rc = rc;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/bytedeco/javacv/MarkedPlane.java
Expand Up @@ -200,7 +200,7 @@ public double getTotalWarp(Marker[] imagedMarkers, CvMat totalWarp, boolean useC
if (numPoints == 4) {
JavaCV.getPerspectiveTransform(srcPts.get(), dstPts.get(), totalWarp);
} else {
cvFindHomography(srcPts, dstPts, totalWarp);
cvCopy(cvMat(findHomography(cvarrToMat(srcPts), cvarrToMat(dstPts))), totalWarp);
}

// compute transformed source<->dest RMSE
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/bytedeco/javacv/ProCamTransformer.java
Expand Up @@ -473,7 +473,7 @@ private double[] setSubspaceInternal(double ... p) {
}
double[] dst = new double[8+3];
t.put(p[0], p[1], p[2]);
cvRodrigues2(t, R, null);
Rodrigues(cvarrToMat(t), cvarrToMat(R), null);
t.put(p[3], p[4], p[5]);

// compute new H
Expand Down Expand Up @@ -514,7 +514,7 @@ private double[] getSubspaceInternal() {
cvMatMul(surfaceTransformer.getInvK2(), H, H);

JavaCV.HtoRt(H, R, t);
cvRodrigues2(R, n, null);
Rodrigues(cvarrToMat(R), cvarrToMat(n), null);
double[] p = { n.get(0), n.get(1), n.get(2),
t.get(0), t.get(1), t.get(2) };
return p;
Expand Down

0 comments on commit 88e6df6

Please sign in to comment.