vendor: OpenCV 5.0.0 snapshot at 40738fb16ceddb5fb3fea747585f7ce6abb0605b
This commit is contained in:
@@ -0,0 +1 @@
|
||||
misc/java/src/cpp/objdetect_converters.hpp
|
||||
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"ManualFuncs" : {
|
||||
"QRCodeEncoder" : {
|
||||
"QRCodeEncoder" : {
|
||||
"j_code" : [
|
||||
"\n",
|
||||
"/** Generates QR code from input string.",
|
||||
"@param encoded_info Input bytes to encode.",
|
||||
"@param qrcode Generated QR code.",
|
||||
"*/",
|
||||
"public void encode(byte[] encoded_info, Mat qrcode) {",
|
||||
" encode_1(nativeObj, encoded_info, qrcode.nativeObj);",
|
||||
"}",
|
||||
"\n"
|
||||
],
|
||||
"jn_code": [
|
||||
"\n",
|
||||
"private static native void encode_1(long nativeObj, byte[] encoded_info, long qrcode_nativeObj);",
|
||||
"\n"
|
||||
],
|
||||
"cpp_code": [
|
||||
"//",
|
||||
"// void cv::QRCodeEncoder::encode(String encoded_info, Mat& qrcode)",
|
||||
"//",
|
||||
"\n",
|
||||
"JNIEXPORT void JNICALL Java_org_opencv_objdetect_QRCodeEncoder_encode_11 (JNIEnv*, jclass, jlong, jbyteArray, jlong);",
|
||||
"\n",
|
||||
"JNIEXPORT void JNICALL Java_org_opencv_objdetect_QRCodeEncoder_encode_11",
|
||||
"(JNIEnv* env, jclass , jlong self, jbyteArray encoded_info, jlong qrcode_nativeObj)",
|
||||
"{",
|
||||
"",
|
||||
" static const char method_name[] = \"objdetect::encode_11()\";",
|
||||
" try {",
|
||||
" LOGD(\"%s\", method_name);",
|
||||
" Ptr<cv::QRCodeEncoder>* me = (Ptr<cv::QRCodeEncoder>*) self; //TODO: check for NULL",
|
||||
" const char* n_encoded_info = reinterpret_cast<char*>(env->GetByteArrayElements(encoded_info, NULL));",
|
||||
" const jsize n_encoded_info_size = env->GetArrayLength(encoded_info);",
|
||||
" Mat& qrcode = *((Mat*)qrcode_nativeObj);",
|
||||
" (*me)->encode( std::string(n_encoded_info, n_encoded_info_size), qrcode );",
|
||||
" } catch(const std::exception &e) {",
|
||||
" throwJavaException(env, &e, method_name);",
|
||||
" } catch (...) {",
|
||||
" throwJavaException(env, 0, method_name);",
|
||||
" }",
|
||||
"}",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"type_dict": {
|
||||
"NativeByteArray": {
|
||||
"j_type" : "byte[]",
|
||||
"jn_type": "byte[]",
|
||||
"jni_type": "jbyteArray",
|
||||
"jni_name": "n_%(n)s",
|
||||
"jni_var": "jbyteArray n_%(n)s = env->NewByteArray(static_cast<jsize>(%(n)s.size())); env->SetByteArrayRegion(n_%(n)s, 0, static_cast<jsize>(%(n)s.size()), reinterpret_cast<const jbyte*>(%(n)s.c_str()));",
|
||||
"cast_from": "std::string"
|
||||
},
|
||||
"vector_NativeByteArray": {
|
||||
"j_type": "List<byte[]>",
|
||||
"jn_type": "List<byte[]>",
|
||||
"jni_type": "jobject",
|
||||
"jni_var": "std::vector< std::string > %(n)s",
|
||||
"suffix": "Ljava_util_List",
|
||||
"v_type": "vector_NativeByteArray"
|
||||
}
|
||||
},
|
||||
"func_arg_fix" : {
|
||||
"findChessboardCorners" : { "corners" : {"ctype" : "vector_Point2f"} },
|
||||
"drawChessboardCorners" : { "corners" : {"ctype" : "vector_Point2f"} }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "objdetect_converters.hpp"
|
||||
|
||||
#define LOG_TAG "org.opencv.objdetect"
|
||||
|
||||
void Copy_vector_NativeByteArray_to_List(JNIEnv* env, std::vector<std::string>& vs, jobject list)
|
||||
{
|
||||
static jclass juArrayList = ARRAYLIST(env);
|
||||
jmethodID m_clear = LIST_CLEAR(env, juArrayList);
|
||||
jmethodID m_add = LIST_ADD(env, juArrayList);
|
||||
|
||||
env->CallVoidMethod(list, m_clear);
|
||||
for (std::vector<std::string>::iterator it = vs.begin(); it != vs.end(); ++it)
|
||||
{
|
||||
jsize sz = static_cast<jsize>((*it).size());
|
||||
jbyteArray element = env->NewByteArray(sz);
|
||||
env->SetByteArrayRegion(element, 0, sz, reinterpret_cast<const jbyte*>((*it).c_str()));
|
||||
env->CallBooleanMethod(list, m_add, element);
|
||||
env->DeleteLocalRef(element);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html
|
||||
|
||||
#ifndef OBJDETECT_CONVERTERS_HPP
|
||||
#define OBJDETECT_CONVERTERS_HPP
|
||||
|
||||
#include <jni.h>
|
||||
#include "opencv_java.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
void Copy_vector_NativeByteArray_to_List(JNIEnv* env, std::vector<std::string>& vs, jobject list);
|
||||
|
||||
#endif /* OBJDETECT_CONVERTERS_HPP */
|
||||
@@ -0,0 +1,115 @@
|
||||
package org.opencv.test.aruco;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfInt;
|
||||
import org.opencv.core.Size;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.objdetect.*;
|
||||
|
||||
|
||||
public class ArucoTest extends OpenCVTestCase {
|
||||
|
||||
public void testGenerateBoards() {
|
||||
Dictionary dictionary = Objdetect.getPredefinedDictionary(Objdetect.DICT_4X4_50);
|
||||
|
||||
Mat point1 = new Mat(4, 3, CvType.CV_32FC1);
|
||||
int row = 0, col = 0;
|
||||
double squareLength = 40.;
|
||||
point1.put(row, col, 0, 0, 0,
|
||||
0, squareLength, 0,
|
||||
squareLength, squareLength, 0,
|
||||
0, squareLength, 0);
|
||||
List<Mat>objPoints = new ArrayList<Mat>();
|
||||
objPoints.add(point1);
|
||||
|
||||
Mat ids = new Mat(1, 1, CvType.CV_32SC1);
|
||||
ids.put(row, col, 0);
|
||||
|
||||
Board board = new Board(objPoints, dictionary, ids);
|
||||
|
||||
Mat image = new Mat();
|
||||
board.generateImage(new Size(80, 80), image, 2);
|
||||
|
||||
assertTrue(image.total() > 0);
|
||||
}
|
||||
|
||||
public void testArucoIssue3133() {
|
||||
byte[][] marker = {{0,1,1},{1,1,1},{0,1,1}};
|
||||
Dictionary dictionary = Objdetect.extendDictionary(1, 3);
|
||||
dictionary.set_maxCorrectionBits(0);
|
||||
Mat markerBits = new Mat(3, 3, CvType.CV_8UC1);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
markerBits.put(i, j, marker[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
Mat markerCompressed = Dictionary.getByteListFromBits(markerBits);
|
||||
assertMatNotEqual(markerCompressed, dictionary.get_bytesList());
|
||||
|
||||
dictionary.set_bytesList(markerCompressed);
|
||||
assertMatEqual(markerCompressed, dictionary.get_bytesList());
|
||||
}
|
||||
|
||||
public void testArucoDetector() {
|
||||
Dictionary dictionary = Objdetect.getPredefinedDictionary(0);
|
||||
DetectorParameters detectorParameters = new DetectorParameters();
|
||||
ArucoDetector detector = new ArucoDetector(dictionary, detectorParameters);
|
||||
|
||||
Mat markerImage = new Mat();
|
||||
int id = 1, offset = 5, size = 40;
|
||||
Objdetect.generateImageMarker(dictionary, id, size, markerImage, detectorParameters.get_markerBorderBits());
|
||||
|
||||
Mat image = new Mat(markerImage.rows() + 2*offset, markerImage.cols() + 2*offset,
|
||||
CvType.CV_8UC1, new Scalar(255));
|
||||
Mat m = image.submat(offset, size+offset, offset, size+offset);
|
||||
markerImage.copyTo(m);
|
||||
|
||||
List<Mat> corners = new ArrayList();
|
||||
Mat ids = new Mat();
|
||||
detector.detectMarkers(image, corners, ids);
|
||||
|
||||
assertEquals(1, corners.size());
|
||||
Mat res = corners.get(0);
|
||||
assertArrayEquals(new double[]{offset, offset}, res.get(0, 0), 0.0);
|
||||
assertArrayEquals(new double[]{size + offset - 1, offset}, res.get(0, 1), 0.0);
|
||||
assertArrayEquals(new double[]{size + offset - 1, size + offset - 1}, res.get(0, 2), 0.0);
|
||||
assertArrayEquals(new double[]{offset, size + offset - 1}, res.get(0, 3), 0.0);
|
||||
}
|
||||
|
||||
public void testCharucoDetector() {
|
||||
Dictionary dictionary = Objdetect.getPredefinedDictionary(0);
|
||||
int boardSizeX = 3, boardSizeY = 3;
|
||||
CharucoBoard board = new CharucoBoard(new Size(boardSizeX, boardSizeY), 1.f, 0.8f, dictionary);
|
||||
CharucoDetector charucoDetector = new CharucoDetector(board);
|
||||
|
||||
int cellSize = 80;
|
||||
Mat boardImage = new Mat();
|
||||
board.generateImage(new Size(cellSize*boardSizeX, cellSize*boardSizeY), boardImage);
|
||||
|
||||
assertTrue(boardImage.total() > 0);
|
||||
|
||||
Mat charucoCorners = new Mat();
|
||||
Mat charucoIds = new Mat();
|
||||
charucoDetector.detectBoard(boardImage, charucoCorners, charucoIds);
|
||||
|
||||
assertEquals(4, charucoIds.total());
|
||||
int[] intCharucoIds = (new MatOfInt(charucoIds)).toArray();
|
||||
Assert.assertArrayEquals(new int[]{0, 1, 2, 3}, intCharucoIds);
|
||||
|
||||
// Note: Expected values adjusted by -0.5px after fixing the systematic offset bug in charuco_detector.cpp
|
||||
// The fix removes the incorrect +0.5 offset that was added after cornerSubPix
|
||||
double eps = 0.2;
|
||||
assertArrayEquals(new double[]{cellSize - 0.5, cellSize - 0.5}, charucoCorners.get(0, 0), eps);
|
||||
assertArrayEquals(new double[]{2*cellSize - 0.5, cellSize - 0.5}, charucoCorners.get(0,1), eps);
|
||||
assertArrayEquals(new double[]{cellSize - 0.5, 2*cellSize - 0.5}, charucoCorners.get(0,2), eps);
|
||||
assertArrayEquals(new double[]{2*cellSize - 0.5, 2*cellSize - 0.5}, charucoCorners.get(0,3), eps);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.opencv.test.barcode;
|
||||
|
||||
import java.util.List;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.objdetect.BarcodeDetector;
|
||||
import org.opencv.imgcodecs.Imgcodecs;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BarcodeDetectorTest extends OpenCVTestCase {
|
||||
|
||||
private final static String ENV_OPENCV_TEST_DATA_PATH = "OPENCV_TEST_DATA_PATH";
|
||||
private String testDataPath;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
// relys on https://developer.android.com/reference/java/lang/System
|
||||
isTestCaseEnabled = System.getProperties().getProperty("java.vm.name") != "Dalvik";
|
||||
|
||||
if (isTestCaseEnabled) {
|
||||
testDataPath = System.getenv(ENV_OPENCV_TEST_DATA_PATH);
|
||||
if (testDataPath == null)
|
||||
throw new Exception(ENV_OPENCV_TEST_DATA_PATH + " has to be defined!");
|
||||
}
|
||||
}
|
||||
|
||||
public void testDetectAndDecode() {
|
||||
Mat img = Imgcodecs.imread(testDataPath + "/cv/barcode/multiple/4_barcodes.jpg");
|
||||
assertFalse(img.empty());
|
||||
BarcodeDetector detector = new BarcodeDetector();
|
||||
assertNotNull(detector);
|
||||
List < String > infos = new ArrayList< String >();
|
||||
List < String > types = new ArrayList< String >();
|
||||
|
||||
boolean result = detector.detectAndDecodeWithType(img, infos, types);
|
||||
assertTrue(result);
|
||||
assertEquals(infos.size(), 4);
|
||||
assertEquals(types.size(), 4);
|
||||
final String[] correctResults = {"9787122276124", "9787118081473", "9787564350840", "9783319200064"};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
assertEquals(types.get(i), "EAN_13");
|
||||
result = false;
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (correctResults[j].equals(infos.get(i))) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package org.opencv.test.objdetect;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfDouble;
|
||||
import org.opencv.core.MatOfPoint2f;
|
||||
import org.opencv.core.MatOfPoint3f;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.Size;
|
||||
import org.opencv.objdetect.Objdetect;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
public class ObjdetectTest extends OpenCVTestCase {
|
||||
|
||||
Size size;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
size = new Size(3, 3);
|
||||
}
|
||||
|
||||
public void testFindChessboardCornersMatSizeMat() {
|
||||
Size patternSize = new Size(9, 6);
|
||||
MatOfPoint2f corners = new MatOfPoint2f();
|
||||
Objdetect.findChessboardCorners(grayChess, patternSize, corners);
|
||||
assertFalse(corners.empty());
|
||||
}
|
||||
|
||||
public void testFindChessboardCornersMatSizeMatInt() {
|
||||
Size patternSize = new Size(9, 6);
|
||||
MatOfPoint2f corners = new MatOfPoint2f();
|
||||
Objdetect.findChessboardCorners(grayChess, patternSize, corners, Objdetect.CALIB_CB_ADAPTIVE_THRESH + Objdetect.CALIB_CB_NORMALIZE_IMAGE
|
||||
+ Objdetect.CALIB_CB_FAST_CHECK);
|
||||
assertFalse(corners.empty());
|
||||
}
|
||||
|
||||
public void testFind4QuadCornerSubpix() {
|
||||
Size patternSize = new Size(9, 6);
|
||||
MatOfPoint2f corners = new MatOfPoint2f();
|
||||
Size region_size = new Size(5, 5);
|
||||
Objdetect.findChessboardCorners(grayChess, patternSize, corners);
|
||||
Objdetect.find4QuadCornerSubpix(grayChess, corners, region_size);
|
||||
assertFalse(corners.empty());
|
||||
}
|
||||
|
||||
public void testFindCirclesGridMatSizeMat() {
|
||||
int size = 300;
|
||||
Mat img = new Mat(size, size, CvType.CV_8U);
|
||||
img.setTo(new Scalar(255));
|
||||
Mat centers = new Mat();
|
||||
|
||||
assertFalse(Objdetect.findCirclesGrid(img, new Size(5, 5), centers));
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
for (int j = 0; j < 5; j++) {
|
||||
Point pt = new Point(size * (2 * i + 1) / 10, size * (2 * j + 1) / 10);
|
||||
Imgproc.circle(img, pt, 10, new Scalar(0), -1);
|
||||
}
|
||||
|
||||
assertTrue(Objdetect.findCirclesGrid(img, new Size(5, 5), centers));
|
||||
|
||||
assertEquals(1, centers.rows());
|
||||
assertEquals(25, centers.cols());
|
||||
assertEquals(CvType.CV_32FC2, centers.type());
|
||||
}
|
||||
|
||||
public void testFindCirclesGridMatSizeMatInt() {
|
||||
int size = 300;
|
||||
Mat img = new Mat(size, size, CvType.CV_8U);
|
||||
img.setTo(new Scalar(255));
|
||||
Mat centers = new Mat();
|
||||
|
||||
assertFalse(Objdetect.findCirclesGrid(img, new Size(3, 5), centers, Objdetect.CALIB_CB_CLUSTERING
|
||||
| Objdetect.CALIB_CB_ASYMMETRIC_GRID));
|
||||
|
||||
int step = size * 2 / 15;
|
||||
int offsetx = size / 6;
|
||||
int offsety = (size - 4 * step) / 2;
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int j = 0; j < 5; j++) {
|
||||
Point pt = new Point(offsetx + (2 * i + j % 2) * step, offsety + step * j);
|
||||
Imgproc.circle(img, pt, 10, new Scalar(0), -1);
|
||||
}
|
||||
|
||||
assertTrue(Objdetect.findCirclesGrid(img, new Size(3, 5), centers, Objdetect.CALIB_CB_CLUSTERING
|
||||
| Objdetect.CALIB_CB_ASYMMETRIC_GRID));
|
||||
|
||||
assertEquals(1, centers.rows());
|
||||
assertEquals(15, centers.cols());
|
||||
assertEquals(CvType.CV_32FC2, centers.type());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package org.opencv.test.objdetect;
|
||||
|
||||
import java.util.List;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Size;
|
||||
import org.opencv.objdetect.QRCodeDetector;
|
||||
import org.opencv.objdetect.QRCodeEncoder;
|
||||
import org.opencv.objdetect.QRCodeEncoder_Params;
|
||||
import org.opencv.imgcodecs.Imgcodecs;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class QRCodeDetectorTest extends OpenCVTestCase {
|
||||
|
||||
private final static String ENV_OPENCV_TEST_DATA_PATH = "OPENCV_TEST_DATA_PATH";
|
||||
private String testDataPath;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
// relys on https://developer.android.com/reference/java/lang/System
|
||||
isTestCaseEnabled = System.getProperties().getProperty("java.vm.name") != "Dalvik";
|
||||
|
||||
if (isTestCaseEnabled) {
|
||||
testDataPath = System.getenv(ENV_OPENCV_TEST_DATA_PATH);
|
||||
if (testDataPath == null)
|
||||
throw new Exception(ENV_OPENCV_TEST_DATA_PATH + " has to be defined!");
|
||||
}
|
||||
}
|
||||
|
||||
public void testDetectAndDecode() {
|
||||
Mat img = Imgcodecs.imread(testDataPath + "/cv/qrcode/link_ocv.jpg");
|
||||
assertFalse(img.empty());
|
||||
QRCodeDetector detector = new QRCodeDetector();
|
||||
assertNotNull(detector);
|
||||
String output = detector.detectAndDecode(img);
|
||||
assertEquals(output, "https://opencv.org/");
|
||||
}
|
||||
|
||||
public void testDetectAndDecodeMulti() {
|
||||
Mat img = Imgcodecs.imread(testDataPath + "/cv/qrcode/multiple/6_qrcodes.png");
|
||||
assertFalse(img.empty());
|
||||
QRCodeDetector detector = new QRCodeDetector();
|
||||
assertNotNull(detector);
|
||||
List < String > output = new ArrayList< String >();
|
||||
boolean result = detector.detectAndDecodeMulti(img, output);
|
||||
assertTrue(result);
|
||||
assertEquals(output.size(), 6);
|
||||
List < String > expectedResults = Arrays.asList("SKIP", "EXTRA", "TWO STEPS FORWARD", "STEP BACK", "QUESTION", "STEP FORWARD");
|
||||
assertEquals(new HashSet<String>(output), new HashSet<String>(expectedResults));
|
||||
}
|
||||
|
||||
public void testKanji() {
|
||||
byte[] inp = new byte[]{(byte)0x82, (byte)0xb1, (byte)0x82, (byte)0xf1, (byte)0x82, (byte)0xc9, (byte)0x82,
|
||||
(byte)0xbf, (byte)0x82, (byte)0xcd, (byte)0x90, (byte)0xa2, (byte)0x8a, (byte)0x45};
|
||||
QRCodeEncoder_Params params = new QRCodeEncoder_Params();
|
||||
params.set_mode(QRCodeEncoder.MODE_KANJI);
|
||||
QRCodeEncoder encoder = QRCodeEncoder.create(params);
|
||||
|
||||
Mat qrcode = new Mat();
|
||||
encoder.encode(inp, qrcode);
|
||||
Imgproc.resize(qrcode, qrcode, new Size(0, 0), 2, 2, Imgproc.INTER_NEAREST);
|
||||
|
||||
QRCodeDetector detector = new QRCodeDetector();
|
||||
byte[] output = detector.detectAndDecodeBytes(qrcode);
|
||||
assertEquals(detector.getEncoding(), QRCodeEncoder.ECI_SHIFT_JIS);
|
||||
assertArrayEquals(inp, output);
|
||||
|
||||
List < byte[] > outputs = new ArrayList< byte[] >();
|
||||
assertTrue(detector.detectAndDecodeBytesMulti(qrcode, outputs));
|
||||
assertEquals(detector.getEncoding(0), QRCodeEncoder.ECI_SHIFT_JIS);
|
||||
assertArrayEquals(inp, outputs.get(0));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user