mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 12:22:51 +08:00

Added CV_WRAP to Animation struct #26813 closes #26808 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
97 lines
3.0 KiB
Java
97 lines
3.0 KiB
Java
package org.opencv.test.imgcodecs;
|
|
|
|
import org.opencv.core.Mat;
|
|
import org.opencv.core.MatOfByte;
|
|
import org.opencv.core.MatOfInt;
|
|
import org.opencv.imgproc.Imgproc;
|
|
import org.opencv.imgcodecs.Imgcodecs;
|
|
import org.opencv.imgcodecs.Animation;
|
|
import org.opencv.test.OpenCVTestCase;
|
|
import org.opencv.test.OpenCVTestRunner;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class ImgcodecsTest extends OpenCVTestCase {
|
|
|
|
public void testAnimation() {
|
|
Mat src = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH, Imgcodecs.IMREAD_REDUCED_COLOR_4);
|
|
assertFalse(src.empty());
|
|
|
|
Mat rgb = new Mat();
|
|
Imgproc.cvtColor(src, rgb, Imgproc.COLOR_BGR2RGB);
|
|
|
|
Animation animation = new Animation();
|
|
List<Mat> frames = new ArrayList<>();
|
|
MatOfInt durations = new MatOfInt(100, 100);
|
|
|
|
frames.add(src);
|
|
frames.add(rgb);
|
|
|
|
animation.set_frames(frames);
|
|
animation.set_durations(durations);
|
|
|
|
String filename = OpenCVTestRunner.getTempFileName("png");
|
|
assertTrue(Imgcodecs.imwriteanimation(filename, animation));
|
|
|
|
Animation readAnimation = new Animation();
|
|
assertTrue(Imgcodecs.imreadanimation(filename, readAnimation));
|
|
|
|
List<Mat> readFrames = readAnimation.get_frames();
|
|
assertTrue(readFrames.size() == 2);
|
|
}
|
|
|
|
public void testImdecode() {
|
|
fail("Not yet implemented");
|
|
}
|
|
|
|
public void testImencodeStringMatListOfByte() {
|
|
MatOfByte buff = new MatOfByte();
|
|
assertEquals(0, buff.total());
|
|
assertTrue( Imgcodecs.imencode(".jpg", gray127, buff) );
|
|
assertFalse(0 == buff.total());
|
|
}
|
|
|
|
public void testImencodeStringMatListOfByteListOfInteger() {
|
|
MatOfInt params40 = new MatOfInt(Imgcodecs.IMWRITE_JPEG_QUALITY, 40);
|
|
MatOfInt params90 = new MatOfInt(Imgcodecs.IMWRITE_JPEG_QUALITY, 90);
|
|
/* or
|
|
MatOfInt params = new MatOfInt();
|
|
params.fromArray(Imgcodecs.IMWRITE_JPEG_QUALITY, 40);
|
|
*/
|
|
MatOfByte buff40 = new MatOfByte();
|
|
MatOfByte buff90 = new MatOfByte();
|
|
|
|
assertTrue( Imgcodecs.imencode(".jpg", rgbLena, buff40, params40) );
|
|
assertTrue( Imgcodecs.imencode(".jpg", rgbLena, buff90, params90) );
|
|
|
|
assertTrue(buff40.total() > 0);
|
|
assertTrue(buff40.total() < buff90.total());
|
|
}
|
|
|
|
public void testImreadString() {
|
|
dst = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH);
|
|
assertFalse(dst.empty());
|
|
assertEquals(3, dst.channels());
|
|
assertTrue(512 == dst.cols());
|
|
assertTrue(512 == dst.rows());
|
|
}
|
|
|
|
public void testImreadStringInt() {
|
|
dst = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH, Imgcodecs.IMREAD_GRAYSCALE);
|
|
assertFalse(dst.empty());
|
|
assertEquals(1, dst.channels());
|
|
assertTrue(512 == dst.cols());
|
|
assertTrue(512 == dst.rows());
|
|
}
|
|
|
|
public void testImwriteStringMat() {
|
|
fail("Not yet implemented");
|
|
}
|
|
|
|
public void testImwriteStringMatListOfInteger() {
|
|
fail("Not yet implemented");
|
|
}
|
|
|
|
}
|