feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake

1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试
2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程
3.重整权利声明文件,重整代码工程,确保最小化侵权风险

Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake
Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
wangzhengyang
2022-05-10 09:54:44 +08:00
parent ecdd171c6f
commit 718c41634f
10018 changed files with 3593797 additions and 186748 deletions

View File

@ -0,0 +1,104 @@
package org.opencv.test.objdetect;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import org.opencv.objdetect.CascadeClassifier;
import org.opencv.objdetect.Objdetect;
import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner;
public class CascadeClassifierTest extends OpenCVTestCase {
private CascadeClassifier cc;
@Override
protected void setUp() throws Exception {
super.setUp();
cc = null;
}
public void testCascadeClassifier() {
cc = new CascadeClassifier();
assertNotNull(cc);
}
public void testCascadeClassifierString() {
cc = new CascadeClassifier(OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH);
assertNotNull(cc);
}
public void testDetectMultiScaleMatListOfRect() {
CascadeClassifier cc = new CascadeClassifier(OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH);
MatOfRect faces = new MatOfRect();
Mat greyLena = new Mat();
Imgproc.cvtColor(rgbLena, greyLena, Imgproc.COLOR_RGB2GRAY);
Imgproc.equalizeHist(greyLena, greyLena);
cc.detectMultiScale(greyLena, faces, 1.1, 3, Objdetect.CASCADE_SCALE_IMAGE, new Size(30, 30), new Size());
assertEquals(1, faces.total());
}
public void testDetectMultiScaleMatListOfRectDouble() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectDoubleInt() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectDoubleIntInt() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectDoubleIntIntSize() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectDoubleIntIntSizeSize() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfIntegerListOfDouble() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfIntegerListOfDoubleDouble() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfIntegerListOfDoubleDoubleInt() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfIntegerListOfDoubleDoubleIntInt() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfIntegerListOfDoubleDoubleIntIntSize() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfIntegerListOfDoubleDoubleIntIntSizeSize() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfIntegerListOfDoubleDoubleIntIntSizeSizeBoolean() {
fail("Not yet implemented");
}
public void testEmpty() {
cc = new CascadeClassifier();
assertTrue(cc.empty());
}
public void testLoad() {
cc = new CascadeClassifier();
cc.load(OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH);
assertFalse(cc.empty());
}
}

View File

@ -0,0 +1,259 @@
package org.opencv.test.objdetect;
import org.opencv.objdetect.HOGDescriptor;
import org.opencv.test.OpenCVTestCase;
public class HOGDescriptorTest extends OpenCVTestCase {
public void testCheckDetectorSize() {
fail("Not yet implemented");
}
public void testComputeGradientMatMatMat() {
fail("Not yet implemented");
}
public void testComputeGradientMatMatMatSize() {
fail("Not yet implemented");
}
public void testComputeGradientMatMatMatSizeSize() {
fail("Not yet implemented");
}
public void testComputeMatListOfFloat() {
fail("Not yet implemented");
}
public void testComputeMatListOfFloatSize() {
fail("Not yet implemented");
}
public void testComputeMatListOfFloatSizeSize() {
fail("Not yet implemented");
}
public void testComputeMatListOfFloatSizeSizeListOfPoint() {
fail("Not yet implemented");
}
public void testDetectMatListOfPoint() {
fail("Not yet implemented");
}
public void testDetectMatListOfPointDouble() {
fail("Not yet implemented");
}
public void testDetectMatListOfPointDoubleSize() {
fail("Not yet implemented");
}
public void testDetectMatListOfPointDoubleSizeSize() {
fail("Not yet implemented");
}
public void testDetectMatListOfPointDoubleSizeSizeListOfPoint() {
fail("Not yet implemented");
}
public void testDetectMatListOfPointListOfDouble() {
fail("Not yet implemented");
}
public void testDetectMatListOfPointListOfDoubleDouble() {
fail("Not yet implemented");
}
public void testDetectMatListOfPointListOfDoubleDoubleSize() {
fail("Not yet implemented");
}
public void testDetectMatListOfPointListOfDoubleDoubleSizeSize() {
fail("Not yet implemented");
}
public void testDetectMatListOfPointListOfDoubleDoubleSizeSizeListOfPoint() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRect() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectDouble() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectDoubleSize() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectDoubleSizeSize() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectDoubleSizeSizeDouble() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectDoubleSizeSizeDoubleDouble() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectDoubleSizeSizeDoubleDoubleBoolean() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfDouble() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfDoubleDouble() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSize() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSizeSize() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSizeSizeDouble() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSizeSizeDoubleDouble() {
fail("Not yet implemented");
}
public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSizeSizeDoubleDoubleBoolean() {
fail("Not yet implemented");
}
public void testGet_blockSize() {
fail("Not yet implemented");
}
public void testGet_blockStride() {
fail("Not yet implemented");
}
public void testGet_cellSize() {
fail("Not yet implemented");
}
public void testGet_derivAperture() {
fail("Not yet implemented");
}
public void testGet_gammaCorrection() {
fail("Not yet implemented");
}
public void testGet_histogramNormType() {
fail("Not yet implemented");
}
public void testGet_L2HysThreshold() {
fail("Not yet implemented");
}
public void testGet_nbins() {
fail("Not yet implemented");
}
public void testGet_nlevels() {
fail("Not yet implemented");
}
public void testGet_svmDetector() {
fail("Not yet implemented");
}
public void testGet_winSigma() {
fail("Not yet implemented");
}
public void testGet_winSize() {
fail("Not yet implemented");
}
public void testGetDaimlerPeopleDetector() {
fail("Not yet implemented");
}
public void testGetDefaultPeopleDetector() {
fail("Not yet implemented");
}
public void testGetDescriptorSize() {
fail("Not yet implemented");
}
public void testGetWinSigma() {
fail("Not yet implemented");
}
public void testHOGDescriptor() {
HOGDescriptor hog = new HOGDescriptor();
assertNotNull(hog);
assertEquals(HOGDescriptor.DEFAULT_NLEVELS, hog.get_nlevels());
}
public void testHOGDescriptorSizeSizeSizeSizeInt() {
fail("Not yet implemented");
}
public void testHOGDescriptorSizeSizeSizeSizeIntInt() {
fail("Not yet implemented");
}
public void testHOGDescriptorSizeSizeSizeSizeIntIntDouble() {
fail("Not yet implemented");
}
public void testHOGDescriptorSizeSizeSizeSizeIntIntDoubleInt() {
fail("Not yet implemented");
}
public void testHOGDescriptorSizeSizeSizeSizeIntIntDoubleIntDouble() {
fail("Not yet implemented");
}
public void testHOGDescriptorSizeSizeSizeSizeIntIntDoubleIntDoubleBoolean() {
fail("Not yet implemented");
}
public void testHOGDescriptorSizeSizeSizeSizeIntIntDoubleIntDoubleBooleanInt() {
fail("Not yet implemented");
}
public void testHOGDescriptorString() {
fail("Not yet implemented");
}
public void testLoadString() {
fail("Not yet implemented");
}
public void testLoadStringString() {
fail("Not yet implemented");
}
public void testSaveString() {
fail("Not yet implemented");
}
public void testSaveStringString() {
fail("Not yet implemented");
}
public void testSetSVMDetector() {
fail("Not yet implemented");
}
}

View File

@ -0,0 +1,42 @@
package org.opencv.test.objdetect;
import org.opencv.test.OpenCVTestCase;
public class ObjdetectTest extends OpenCVTestCase {
public void testGroupRectanglesListOfRectListOfIntegerInt() {
fail("Not yet implemented");
/*
final int NUM = 10;
MatOfRect rects = new MatOfRect();
rects.alloc(NUM);
for (int i = 0; i < NUM; i++)
rects.put(i, 0, 10, 10, 20, 20);
int groupThreshold = 1;
Objdetect.groupRectangles(rects, null, groupThreshold);//TODO: second parameter should not be null
assertEquals(1, rects.total());
*/
}
public void testGroupRectanglesListOfRectListOfIntegerIntDouble() {
fail("Not yet implemented");
/*
final int NUM = 10;
MatOfRect rects = new MatOfRect();
rects.alloc(NUM);
for (int i = 0; i < NUM; i++)
rects.put(i, 0, 10, 10, 20, 20);
for (int i = 0; i < NUM; i++)
rects.put(i, 0, 10, 10, 25, 25);
int groupThreshold = 1;
double eps = 0.2;
Objdetect.groupRectangles(rects, null, groupThreshold, eps);//TODO: second parameter should not be null
assertEquals(2, rects.size());
*/
}
}

View File

@ -0,0 +1,48 @@
package org.opencv.test.objdetect;
import java.util.List;
import org.opencv.core.Mat;
import org.opencv.objdetect.QRCodeDetector;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.test.OpenCVTestCase;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
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();
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));
}
}

View File

@ -0,0 +1,8 @@
#ifdef HAVE_OPENCV_OBJDETECT
#include "opencv2/objdetect.hpp"
typedef HOGDescriptor::HistogramNormType HOGDescriptor_HistogramNormType;
typedef HOGDescriptor::DescriptorStorageFormat HOGDescriptor_DescriptorStorageFormat;
#endif

View File

@ -0,0 +1,92 @@
#!/usr/bin/env python
'''
face detection using haar cascades
'''
# Python 2/3 compatibility
from __future__ import print_function
import numpy as np
import cv2 as cv
def detect(img, cascade):
rects = cascade.detectMultiScale(img, scaleFactor=1.275, minNeighbors=4, minSize=(30, 30),
flags=cv.CASCADE_SCALE_IMAGE)
if len(rects) == 0:
return []
rects[:,2:] += rects[:,:2]
return rects
from tests_common import NewOpenCVTests, intersectionRate
class facedetect_test(NewOpenCVTests):
def test_facedetect(self):
cascade_fn = self.repoPath + '/data/haarcascades/haarcascade_frontalface_alt.xml'
nested_fn = self.repoPath + '/data/haarcascades/haarcascade_eye.xml'
cascade = cv.CascadeClassifier(cascade_fn)
nested = cv.CascadeClassifier(nested_fn)
samples = ['samples/data/lena.jpg', 'cv/cascadeandhog/images/mona-lisa.png']
faces = []
eyes = []
testFaces = [
#lena
[[218, 200, 389, 371],
[ 244, 240, 294, 290],
[ 309, 246, 352, 289]],
#lisa
[[167, 119, 307, 259],
[188, 153, 229, 194],
[236, 153, 277, 194]]
]
for sample in samples:
img = self.get_sample( sample)
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
gray = cv.GaussianBlur(gray, (5, 5), 0)
rects = detect(gray, cascade)
faces.append(rects)
if not nested.empty():
for x1, y1, x2, y2 in rects:
roi = gray[y1:y2, x1:x2]
subrects = detect(roi.copy(), nested)
for rect in subrects:
rect[0] += x1
rect[2] += x1
rect[1] += y1
rect[3] += y1
eyes.append(subrects)
faces_matches = 0
eyes_matches = 0
eps = 0.8
for i in range(len(faces)):
for j in range(len(testFaces)):
if intersectionRate(faces[i][0], testFaces[j][0]) > eps:
faces_matches += 1
#check eyes
if len(eyes[i]) == 2:
if intersectionRate(eyes[i][0], testFaces[j][1]) > eps and intersectionRate(eyes[i][1] , testFaces[j][2]) > eps:
eyes_matches += 1
elif intersectionRate(eyes[i][1], testFaces[j][1]) > eps and intersectionRate(eyes[i][0], testFaces[j][2]) > eps:
eyes_matches += 1
self.assertEqual(faces_matches, 2)
self.assertEqual(eyes_matches, 2)
if __name__ == '__main__':
NewOpenCVTests.bootstrap()

View File

@ -0,0 +1,65 @@
#!/usr/bin/env python
'''
example to detect upright people in images using HOG features
'''
# Python 2/3 compatibility
from __future__ import print_function
import numpy as np
import cv2 as cv
def inside(r, q):
rx, ry, rw, rh = r
qx, qy, qw, qh = q
return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh
from tests_common import NewOpenCVTests, intersectionRate
class peopledetect_test(NewOpenCVTests):
def test_peopledetect(self):
hog = cv.HOGDescriptor()
hog.setSVMDetector( cv.HOGDescriptor_getDefaultPeopleDetector() )
dirPath = 'samples/data/'
samples = ['basketball1.png', 'basketball2.png']
testPeople = [
[[23, 76, 164, 477], [440, 22, 637, 478]],
[[23, 76, 164, 477], [440, 22, 637, 478]]
]
eps = 0.5
for sample in samples:
img = self.get_sample(dirPath + sample, 0)
found, _w = hog.detectMultiScale(img, winStride=(8,8), padding=(32,32), scale=1.05)
found_filtered = []
for ri, r in enumerate(found):
for qi, q in enumerate(found):
if ri != qi and inside(r, q):
break
else:
found_filtered.append(r)
matches = 0
for i in range(len(found_filtered)):
for j in range(len(testPeople)):
found_rect = (found_filtered[i][0], found_filtered[i][1],
found_filtered[i][0] + found_filtered[i][2],
found_filtered[i][1] + found_filtered[i][3])
if intersectionRate(found_rect, testPeople[j][0]) > eps or intersectionRate(found_rect, testPeople[j][1]) > eps:
matches += 1
self.assertGreater(matches, 0)
if __name__ == '__main__':
NewOpenCVTests.bootstrap()

View File

@ -0,0 +1,52 @@
#!/usr/bin/env python
'''
===============================================================================
QR code detect and decode pipeline.
===============================================================================
'''
import os
import numpy as np
import cv2 as cv
from tests_common import NewOpenCVTests
class qrcode_detector_test(NewOpenCVTests):
def test_detect(self):
img = cv.imread(os.path.join(self.extraTestDataPath, 'cv/qrcode/link_ocv.jpg'))
self.assertFalse(img is None)
detector = cv.QRCodeDetector()
retval, points = detector.detect(img)
self.assertTrue(retval)
self.assertEqual(points.shape, (1, 4, 2))
def test_detect_and_decode(self):
img = cv.imread(os.path.join(self.extraTestDataPath, 'cv/qrcode/link_ocv.jpg'))
self.assertFalse(img is None)
detector = cv.QRCodeDetector()
retval, points, straight_qrcode = detector.detectAndDecode(img)
self.assertEqual(retval, "https://opencv.org/")
self.assertEqual(points.shape, (1, 4, 2))
def test_detect_multi(self):
img = cv.imread(os.path.join(self.extraTestDataPath, 'cv/qrcode/multiple/6_qrcodes.png'))
self.assertFalse(img is None)
detector = cv.QRCodeDetector()
retval, points = detector.detectMulti(img)
self.assertTrue(retval)
self.assertEqual(points.shape, (6, 4, 2))
def test_detect_and_decode_multi(self):
img = cv.imread(os.path.join(self.extraTestDataPath, 'cv/qrcode/multiple/6_qrcodes.png'))
self.assertFalse(img is None)
detector = cv.QRCodeDetector()
retval, decoded_data, points, straight_qrcode = detector.detectAndDecodeMulti(img)
self.assertTrue(retval)
self.assertEqual(len(decoded_data), 6)
self.assertEqual(decoded_data[0], "TWO STEPS FORWARD")
self.assertEqual(decoded_data[1], "EXTRA")
self.assertEqual(decoded_data[2], "SKIP")
self.assertEqual(decoded_data[3], "STEP FORWARD")
self.assertEqual(decoded_data[4], "STEP BACK")
self.assertEqual(decoded_data[5], "QUESTION")
self.assertEqual(points.shape, (6, 4, 2))