chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#include "../perf_precomp.hpp"
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
#include "opencv2/ts/ocl_perf.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
using namespace perf;
|
||||
|
||||
typedef tuple<std::string, std::string, int> Cascade_Image_MinSize_t;
|
||||
typedef perf::TestBaseWithParam<Cascade_Image_MinSize_t> Cascade_Image_MinSize;
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
OCL_PERF_TEST_P(Cascade_Image_MinSize, CascadeClassifier,
|
||||
testing::Combine(
|
||||
testing::Values( string("cv/cascadeandhog/cascades/haarcascade_frontalface_alt.xml"),
|
||||
string("cv/cascadeandhog/cascades/haarcascade_frontalface_alt2.xml"),
|
||||
string("cv/cascadeandhog/cascades/lbpcascade_frontalface.xml") ),
|
||||
testing::Values( string("cv/shared/lena.png"),
|
||||
string("cv/cascadeandhog/images/bttf301.png"),
|
||||
string("cv/cascadeandhog/images/class57.png") ),
|
||||
testing::Values(30, 64, 90) ) )
|
||||
{
|
||||
const string cascadePath = get<0>(GetParam());
|
||||
const string imagePath = get<1>(GetParam());
|
||||
int min_size = get<2>(GetParam());
|
||||
Size minSize(min_size, min_size);
|
||||
|
||||
CascadeClassifier cc( getDataPath(cascadePath) );
|
||||
if (cc.empty())
|
||||
FAIL() << "Can't load cascade file: " << getDataPath(cascadePath);
|
||||
|
||||
Mat img = imread(getDataPath(imagePath), IMREAD_GRAYSCALE);
|
||||
if (img.empty())
|
||||
FAIL() << "Can't load source image: " << getDataPath(imagePath);
|
||||
|
||||
vector<Rect> faces;
|
||||
|
||||
equalizeHist(img, img);
|
||||
declare.in(img).time(60);
|
||||
|
||||
UMat uimg = img.getUMat(ACCESS_READ);
|
||||
|
||||
while(next())
|
||||
{
|
||||
faces.clear();
|
||||
cvtest::ocl::perf::safeFinish();
|
||||
|
||||
startTimer();
|
||||
cc.detectMultiScale(uimg, faces, 1.1, 3, 0, minSize);
|
||||
stopTimer();
|
||||
}
|
||||
|
||||
sort(faces.begin(), faces.end(), comparators::RectLess());
|
||||
SANITY_CHECK(faces, min_size/5);
|
||||
}
|
||||
|
||||
#endif //HAVE_OPENCL
|
||||
|
||||
} // namespace
|
||||
@@ -0,0 +1,93 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Fangfang Bai, fangfang@multicorewareinc.com
|
||||
// Jin Ma, jin@multicorewareinc.com
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors as is and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "../perf_precomp.hpp"
|
||||
#include "opencv2/ts/ocl_perf.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
///////////// HOG////////////////////////
|
||||
|
||||
struct RectLess
|
||||
{
|
||||
bool operator()(const cv::Rect& a,
|
||||
const cv::Rect& b) const
|
||||
{
|
||||
if (a.x != b.x)
|
||||
return a.x < b.x;
|
||||
else if (a.y != b.y)
|
||||
return a.y < b.y;
|
||||
else if (a.width != b.width)
|
||||
return a.width < b.width;
|
||||
else
|
||||
return a.height < b.height;
|
||||
}
|
||||
};
|
||||
|
||||
OCL_PERF_TEST(HOGFixture, HOG)
|
||||
{
|
||||
UMat src;
|
||||
imread(getDataPath("gpu/hog/road.png"), cv::IMREAD_GRAYSCALE).copyTo(src);
|
||||
ASSERT_FALSE(src.empty());
|
||||
|
||||
vector<cv::Rect> found_locations;
|
||||
declare.in(src);
|
||||
|
||||
HOGDescriptor hog;
|
||||
hog.setSVMDetector(hog.getDefaultPeopleDetector());
|
||||
|
||||
OCL_TEST_CYCLE() hog.detectMultiScale(src, found_locations);
|
||||
|
||||
std::sort(found_locations.begin(), found_locations.end(), RectLess());
|
||||
SANITY_CHECK(found_locations, 3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,285 @@
|
||||
// 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
|
||||
#include "perf_precomp.hpp"
|
||||
#include "opencv2/calib3d.hpp"
|
||||
|
||||
namespace opencv_test {
|
||||
using namespace perf;
|
||||
|
||||
typedef tuple<bool, int> UseArucoParams;
|
||||
typedef TestBaseWithParam<UseArucoParams> EstimateAruco;
|
||||
#define ESTIMATE_PARAMS Combine(Values(false, true), Values(-1))
|
||||
|
||||
static double deg2rad(double deg) { return deg * CV_PI / 180.; }
|
||||
|
||||
class MarkerPainter
|
||||
{
|
||||
private:
|
||||
int imgMarkerSize = 0;
|
||||
Mat cameraMatrix;
|
||||
public:
|
||||
MarkerPainter(const int size) {
|
||||
setImgMarkerSize(size);
|
||||
}
|
||||
|
||||
void setImgMarkerSize(const int size) {
|
||||
imgMarkerSize = size;
|
||||
cameraMatrix = Mat::eye(3, 3, CV_64FC1);
|
||||
cameraMatrix.at<double>(0, 0) = cameraMatrix.at<double>(1, 1) = imgMarkerSize;
|
||||
cameraMatrix.at<double>(0, 2) = imgMarkerSize / 2.0;
|
||||
cameraMatrix.at<double>(1, 2) = imgMarkerSize / 2.0;
|
||||
}
|
||||
|
||||
static std::pair<Mat, Mat> getSyntheticRT(double yaw, double pitch, double distance) {
|
||||
auto rvec_tvec = std::make_pair(Mat(3, 1, CV_64FC1), Mat(3, 1, CV_64FC1));
|
||||
Mat& rvec = rvec_tvec.first;
|
||||
Mat& tvec = rvec_tvec.second;
|
||||
|
||||
// Rvec
|
||||
// first put the Z axis aiming to -X (like the camera axis system)
|
||||
Mat rotZ(3, 1, CV_64FC1);
|
||||
rotZ.ptr<double>(0)[0] = 0;
|
||||
rotZ.ptr<double>(0)[1] = 0;
|
||||
rotZ.ptr<double>(0)[2] = -0.5 * CV_PI;
|
||||
|
||||
Mat rotX(3, 1, CV_64FC1);
|
||||
rotX.ptr<double>(0)[0] = 0.5 * CV_PI;
|
||||
rotX.ptr<double>(0)[1] = 0;
|
||||
rotX.ptr<double>(0)[2] = 0;
|
||||
|
||||
Mat camRvec, camTvec;
|
||||
composeRT(rotZ, Mat(3, 1, CV_64FC1, Scalar::all(0)), rotX, Mat(3, 1, CV_64FC1, Scalar::all(0)),
|
||||
camRvec, camTvec);
|
||||
|
||||
// now pitch and yaw angles
|
||||
Mat rotPitch(3, 1, CV_64FC1);
|
||||
rotPitch.ptr<double>(0)[0] = 0;
|
||||
rotPitch.ptr<double>(0)[1] = pitch;
|
||||
rotPitch.ptr<double>(0)[2] = 0;
|
||||
|
||||
Mat rotYaw(3, 1, CV_64FC1);
|
||||
rotYaw.ptr<double>(0)[0] = yaw;
|
||||
rotYaw.ptr<double>(0)[1] = 0;
|
||||
rotYaw.ptr<double>(0)[2] = 0;
|
||||
|
||||
composeRT(rotPitch, Mat(3, 1, CV_64FC1, Scalar::all(0)), rotYaw,
|
||||
Mat(3, 1, CV_64FC1, Scalar::all(0)), rvec, tvec);
|
||||
|
||||
// compose both rotations
|
||||
composeRT(camRvec, Mat(3, 1, CV_64FC1, Scalar::all(0)), rvec,
|
||||
Mat(3, 1, CV_64FC1, Scalar::all(0)), rvec, tvec);
|
||||
|
||||
// Tvec, just move in z (camera) direction the specific distance
|
||||
tvec.ptr<double>(0)[0] = 0.;
|
||||
tvec.ptr<double>(0)[1] = 0.;
|
||||
tvec.ptr<double>(0)[2] = distance;
|
||||
return rvec_tvec;
|
||||
}
|
||||
|
||||
std::pair<Mat, vector<Point2f> > getProjectMarker(int id, double yaw, double pitch,
|
||||
const aruco::DetectorParameters& parameters,
|
||||
const aruco::Dictionary& dictionary) {
|
||||
auto marker_corners = std::make_pair(Mat(imgMarkerSize, imgMarkerSize, CV_8UC1, Scalar::all(255)), vector<Point2f>());
|
||||
Mat& img = marker_corners.first;
|
||||
vector<Point2f>& corners = marker_corners.second;
|
||||
|
||||
// canonical image
|
||||
const int markerSizePixels = static_cast<int>(imgMarkerSize/sqrt(2.f));
|
||||
aruco::generateImageMarker(dictionary, id, markerSizePixels, img, parameters.markerBorderBits);
|
||||
|
||||
// get rvec and tvec for the perspective
|
||||
const double distance = 0.1;
|
||||
auto rvec_tvec = MarkerPainter::getSyntheticRT(yaw, pitch, distance);
|
||||
Mat& rvec = rvec_tvec.first;
|
||||
Mat& tvec = rvec_tvec.second;
|
||||
|
||||
const float markerLength = 0.05f;
|
||||
vector<Point3f> markerObjPoints;
|
||||
markerObjPoints.emplace_back(Point3f(-markerLength / 2.f, +markerLength / 2.f, 0));
|
||||
markerObjPoints.emplace_back(markerObjPoints[0] + Point3f(markerLength, 0, 0));
|
||||
markerObjPoints.emplace_back(markerObjPoints[0] + Point3f(markerLength, -markerLength, 0));
|
||||
markerObjPoints.emplace_back(markerObjPoints[0] + Point3f(0, -markerLength, 0));
|
||||
|
||||
// project markers and draw them
|
||||
Mat distCoeffs(5, 1, CV_64FC1, Scalar::all(0));
|
||||
projectPoints(markerObjPoints, rvec, tvec, cameraMatrix, distCoeffs, corners);
|
||||
|
||||
vector<Point2f> originalCorners;
|
||||
originalCorners.emplace_back(Point2f(0.f, 0.f));
|
||||
originalCorners.emplace_back(originalCorners[0]+Point2f((float)markerSizePixels, 0));
|
||||
originalCorners.emplace_back(originalCorners[0]+Point2f((float)markerSizePixels, (float)markerSizePixels));
|
||||
originalCorners.emplace_back(originalCorners[0]+Point2f(0, (float)markerSizePixels));
|
||||
|
||||
Mat transformation = getPerspectiveTransform(originalCorners, corners);
|
||||
|
||||
warpPerspective(img, img, transformation, Size(imgMarkerSize, imgMarkerSize), INTER_NEAREST, BORDER_CONSTANT,
|
||||
Scalar::all(255));
|
||||
return marker_corners;
|
||||
}
|
||||
|
||||
std::pair<Mat, map<int, vector<Point2f> > > getProjectMarkersTile(const int numMarkers,
|
||||
const aruco::DetectorParameters& params,
|
||||
const aruco::Dictionary& dictionary) {
|
||||
Mat tileImage(imgMarkerSize*numMarkers, imgMarkerSize*numMarkers, CV_8UC1, Scalar::all(255));
|
||||
map<int, vector<Point2f> > idCorners;
|
||||
|
||||
int iter = 0, pitch = 0, yaw = 0;
|
||||
for (int i = 0; i < numMarkers; i++) {
|
||||
for (int j = 0; j < numMarkers; j++) {
|
||||
int currentId = iter;
|
||||
auto marker_corners = getProjectMarker(currentId, deg2rad(70+yaw), deg2rad(pitch), params, dictionary);
|
||||
Point2i startPoint(j*imgMarkerSize, i*imgMarkerSize);
|
||||
Mat tmp_roi = tileImage(Rect(startPoint.x, startPoint.y, imgMarkerSize, imgMarkerSize));
|
||||
marker_corners.first.copyTo(tmp_roi);
|
||||
|
||||
for (Point2f& point: marker_corners.second)
|
||||
point += static_cast<Point2f>(startPoint);
|
||||
idCorners[currentId] = marker_corners.second;
|
||||
auto test = idCorners[currentId];
|
||||
yaw = (yaw + 10) % 51; // 70+yaw >= 70 && 70+yaw <= 120
|
||||
iter++;
|
||||
}
|
||||
pitch = (pitch + 60) % 360;
|
||||
}
|
||||
return std::make_pair(tileImage, idCorners);
|
||||
}
|
||||
};
|
||||
|
||||
static inline double getMaxDistance(map<int, vector<Point2f> > &golds, const vector<int>& ids,
|
||||
const vector<vector<Point2f> >& corners) {
|
||||
std::map<int, double> mapDist;
|
||||
for (const auto& el : golds)
|
||||
mapDist[el.first] = std::numeric_limits<double>::max();
|
||||
for (size_t i = 0; i < ids.size(); i++) {
|
||||
int id = ids[i];
|
||||
const auto gold_corners = golds.find(id);
|
||||
if (gold_corners != golds.end()) {
|
||||
double distance = 0.;
|
||||
for (int c = 0; c < 4; c++)
|
||||
distance = std::max(distance, cv::norm(gold_corners->second[c] - corners[i][c]));
|
||||
mapDist[id] = distance;
|
||||
}
|
||||
}
|
||||
return std::max_element(std::begin(mapDist), std::end(mapDist),
|
||||
[](const pair<int, double>& p1, const pair<int, double>& p2){return p1.second < p2.second;})->second;
|
||||
}
|
||||
|
||||
PERF_TEST_P(EstimateAruco, ArucoFirst, ESTIMATE_PARAMS) {
|
||||
UseArucoParams testParams = GetParam();
|
||||
aruco::Dictionary dictionary = aruco::getPredefinedDictionary(aruco::DICT_6X6_250);
|
||||
aruco::DetectorParameters detectorParams;
|
||||
detectorParams.minDistanceToBorder = 1;
|
||||
detectorParams.markerBorderBits = 1;
|
||||
detectorParams.cornerRefinementMethod = (int)cv::aruco::CORNER_REFINE_SUBPIX;
|
||||
|
||||
const int markerSize = 100;
|
||||
const int numMarkersInRow = 9;
|
||||
//USE_ARUCO3
|
||||
detectorParams.useAruco3Detection = get<0>(testParams);
|
||||
if (detectorParams.useAruco3Detection) {
|
||||
detectorParams.minSideLengthCanonicalImg = 32;
|
||||
detectorParams.minMarkerLengthRatioOriginalImg = 0.04f / numMarkersInRow;
|
||||
}
|
||||
aruco::ArucoDetector detector(dictionary, detectorParams);
|
||||
MarkerPainter painter(markerSize);
|
||||
auto image_map = painter.getProjectMarkersTile(numMarkersInRow, detectorParams, dictionary);
|
||||
|
||||
// detect markers
|
||||
vector<vector<Point2f> > corners;
|
||||
vector<int> ids;
|
||||
TEST_CYCLE() {
|
||||
detector.detectMarkers(image_map.first, corners, ids);
|
||||
}
|
||||
ASSERT_EQ(numMarkersInRow*numMarkersInRow, static_cast<int>(ids.size()));
|
||||
double maxDistance = getMaxDistance(image_map.second, ids, corners);
|
||||
ASSERT_LT(maxDistance, 3.);
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P(EstimateAruco, ArucoSecond, ESTIMATE_PARAMS) {
|
||||
UseArucoParams testParams = GetParam();
|
||||
aruco::Dictionary dictionary = aruco::getPredefinedDictionary(aruco::DICT_6X6_250);
|
||||
aruco::DetectorParameters detectorParams;
|
||||
detectorParams.minDistanceToBorder = 1;
|
||||
detectorParams.markerBorderBits = 1;
|
||||
detectorParams.cornerRefinementMethod = (int)cv::aruco::CORNER_REFINE_SUBPIX;
|
||||
|
||||
//USE_ARUCO3
|
||||
detectorParams.useAruco3Detection = get<0>(testParams);
|
||||
if (detectorParams.useAruco3Detection) {
|
||||
detectorParams.minSideLengthCanonicalImg = 64;
|
||||
detectorParams.minMarkerLengthRatioOriginalImg = 0.f;
|
||||
}
|
||||
aruco::ArucoDetector detector(dictionary, detectorParams);
|
||||
const int markerSize = 200;
|
||||
const int numMarkersInRow = 11;
|
||||
MarkerPainter painter(markerSize);
|
||||
auto image_map = painter.getProjectMarkersTile(numMarkersInRow, detectorParams, dictionary);
|
||||
|
||||
// detect markers
|
||||
vector<vector<Point2f> > corners;
|
||||
vector<int> ids;
|
||||
TEST_CYCLE() {
|
||||
detector.detectMarkers(image_map.first, corners, ids);
|
||||
}
|
||||
ASSERT_EQ(numMarkersInRow*numMarkersInRow, static_cast<int>(ids.size()));
|
||||
double maxDistance = getMaxDistance(image_map.second, ids, corners);
|
||||
ASSERT_LT(maxDistance, 3.);
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
struct Aruco3Params {
|
||||
bool useAruco3Detection = false;
|
||||
float minMarkerLengthRatioOriginalImg = 0.f;
|
||||
int minSideLengthCanonicalImg = 0;
|
||||
|
||||
Aruco3Params(bool useAruco3, float minMarkerLen, int minSideLen): useAruco3Detection(useAruco3),
|
||||
minMarkerLengthRatioOriginalImg(minMarkerLen),
|
||||
minSideLengthCanonicalImg(minSideLen) {}
|
||||
friend std::ostream& operator<<(std::ostream& os, const Aruco3Params& d) {
|
||||
os << d.useAruco3Detection << " " << d.minMarkerLengthRatioOriginalImg << " " << d.minSideLengthCanonicalImg;
|
||||
return os;
|
||||
}
|
||||
};
|
||||
typedef tuple<Aruco3Params, pair<int, int>> ArucoTestParams;
|
||||
|
||||
typedef TestBaseWithParam<ArucoTestParams> EstimateLargeAruco;
|
||||
#define ESTIMATE_FHD_PARAMS Combine(Values(Aruco3Params(false, 0.f, 0), Aruco3Params(true, 0.f, 32), \
|
||||
Aruco3Params(true, 0.015f, 32), Aruco3Params(true, 0.f, 16), Aruco3Params(true, 0.0069f, 16)), \
|
||||
Values(std::make_pair(1440, 1), std::make_pair(480, 3), std::make_pair(144, 10)))
|
||||
|
||||
PERF_TEST_P(EstimateLargeAruco, ArucoFHD, ESTIMATE_FHD_PARAMS) {
|
||||
ArucoTestParams testParams = GetParam();
|
||||
aruco::Dictionary dictionary = aruco::getPredefinedDictionary(aruco::DICT_6X6_250);
|
||||
aruco::DetectorParameters detectorParams;
|
||||
detectorParams.minDistanceToBorder = 1;
|
||||
detectorParams.markerBorderBits = 1;
|
||||
detectorParams.cornerRefinementMethod = (int)cv::aruco::CORNER_REFINE_SUBPIX;
|
||||
|
||||
//USE_ARUCO3
|
||||
detectorParams.useAruco3Detection = get<0>(testParams).useAruco3Detection;
|
||||
if (detectorParams.useAruco3Detection) {
|
||||
detectorParams.minSideLengthCanonicalImg = get<0>(testParams).minSideLengthCanonicalImg;
|
||||
detectorParams.minMarkerLengthRatioOriginalImg = get<0>(testParams).minMarkerLengthRatioOriginalImg;
|
||||
}
|
||||
aruco::ArucoDetector detector(dictionary, detectorParams);
|
||||
const int markerSize = get<1>(testParams).first; // 1440 or 480 or 144
|
||||
const int numMarkersInRow = get<1>(testParams).second; // 1 or 3 or 144
|
||||
MarkerPainter painter(markerSize); // num pixels is 1440x1440 as in FHD 1920x1080
|
||||
auto image_map = painter.getProjectMarkersTile(numMarkersInRow, detectorParams, dictionary);
|
||||
|
||||
// detect markers
|
||||
vector<vector<Point2f> > corners;
|
||||
vector<int> ids;
|
||||
TEST_CYCLE()
|
||||
{
|
||||
detector.detectMarkers(image_map.first, corners, ids);
|
||||
}
|
||||
ASSERT_EQ(numMarkersInRow*numMarkersInRow, static_cast<int>(ids.size()));
|
||||
double maxDistance = getMaxDistance(image_map.second, ids, corners);
|
||||
ASSERT_LT(maxDistance, 3.);
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
// 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.
|
||||
|
||||
#include "perf_precomp.hpp"
|
||||
#include "opencv2/objdetect/barcode.hpp"
|
||||
|
||||
namespace opencv_test{namespace{
|
||||
|
||||
typedef ::perf::TestBaseWithParam< tuple<string, cv::Size> > Perf_Barcode_multi;
|
||||
typedef ::perf::TestBaseWithParam< tuple<string, cv::Size> > Perf_Barcode_single;
|
||||
|
||||
PERF_TEST_P_(Perf_Barcode_multi, detect)
|
||||
{
|
||||
const string root = "cv/barcode/multiple/";
|
||||
const string name_current_image = get<0>(GetParam());
|
||||
const cv::Size sz = get<1>(GetParam());
|
||||
const string image_path = findDataFile(root + name_current_image);
|
||||
|
||||
Mat src = imread(image_path);
|
||||
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
||||
cv::resize(src, src, sz);
|
||||
|
||||
vector< Point > corners;
|
||||
auto bardet = barcode::BarcodeDetector();
|
||||
bool res = false;
|
||||
TEST_CYCLE()
|
||||
{
|
||||
res = bardet.detectMulti(src, corners);
|
||||
}
|
||||
SANITY_CHECK_NOTHING();
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(16ull, corners.size());
|
||||
}
|
||||
|
||||
PERF_TEST_P_(Perf_Barcode_multi, detect_decode)
|
||||
{
|
||||
const string root = "cv/barcode/multiple/";
|
||||
const string name_current_image = get<0>(GetParam());
|
||||
const cv::Size sz = get<1>(GetParam());
|
||||
const string image_path = findDataFile(root + name_current_image);
|
||||
|
||||
Mat src = imread(image_path);
|
||||
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
||||
cv::resize(src, src, sz);
|
||||
|
||||
vector<std::string> decoded_info;
|
||||
vector<std::string> decoded_type;
|
||||
vector< Point > corners;
|
||||
auto bardet = barcode::BarcodeDetector();
|
||||
bool res = false;
|
||||
TEST_CYCLE()
|
||||
{
|
||||
res = bardet.detectAndDecodeWithType(src, decoded_info, decoded_type, corners);
|
||||
}
|
||||
SANITY_CHECK_NOTHING();
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(16ull, corners.size());
|
||||
ASSERT_EQ(4ull, decoded_info.size());
|
||||
}
|
||||
|
||||
PERF_TEST_P_(Perf_Barcode_single, detect)
|
||||
{
|
||||
const string root = "cv/barcode/single/";
|
||||
const string name_current_image = get<0>(GetParam());
|
||||
const cv::Size sz = get<1>(GetParam());
|
||||
const string image_path = findDataFile(root + name_current_image);
|
||||
|
||||
Mat src = imread(image_path);
|
||||
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
||||
cv::resize(src, src, sz);
|
||||
|
||||
vector< Point > corners;
|
||||
auto bardet = barcode::BarcodeDetector();
|
||||
bool res = false;
|
||||
TEST_CYCLE()
|
||||
{
|
||||
res = bardet.detectMulti(src, corners);
|
||||
}
|
||||
SANITY_CHECK_NOTHING();
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(4ull, corners.size());
|
||||
}
|
||||
|
||||
PERF_TEST_P_(Perf_Barcode_single, detect_decode)
|
||||
{
|
||||
const string root = "cv/barcode/single/";
|
||||
const string name_current_image = get<0>(GetParam());
|
||||
const cv::Size sz = get<1>(GetParam());
|
||||
const string image_path = findDataFile(root + name_current_image);
|
||||
|
||||
Mat src = imread(image_path);
|
||||
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
||||
cv::resize(src, src, sz);
|
||||
|
||||
vector<std::string> decoded_info;
|
||||
vector<std::string> decoded_type;
|
||||
vector< Point > corners;
|
||||
auto bardet = barcode::BarcodeDetector();
|
||||
bool res = false;
|
||||
TEST_CYCLE()
|
||||
{
|
||||
res = bardet.detectAndDecodeWithType(src, decoded_info, decoded_type, corners);
|
||||
}
|
||||
SANITY_CHECK_NOTHING();
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(4ull, corners.size());
|
||||
ASSERT_EQ(1ull, decoded_info.size());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Barcode_multi,
|
||||
testing::Combine(
|
||||
testing::Values("4_barcodes.jpg"),
|
||||
testing::Values(cv::Size(2041, 2722), cv::Size(1361, 1815), cv::Size(680, 907))));
|
||||
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Barcode_single,
|
||||
testing::Combine(
|
||||
testing::Values("book.jpg", "bottle_1.jpg", "bottle_2.jpg"),
|
||||
testing::Values(cv::Size(480, 360), cv::Size(640, 480), cv::Size(800, 600))));
|
||||
|
||||
}} //namespace
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
#if defined(HAVE_HPX)
|
||||
#include <hpx/hpx_main.hpp>
|
||||
#endif
|
||||
|
||||
CV_PERF_TEST_MAIN(objdetect)
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef __OPENCV_PERF_PRECOMP_HPP__
|
||||
#define __OPENCV_PERF_PRECOMP_HPP__
|
||||
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/objdetect.hpp"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,202 @@
|
||||
// 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.
|
||||
|
||||
#include "perf_precomp.hpp"
|
||||
#include "../test/test_qr_utils.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
namespace
|
||||
{
|
||||
|
||||
typedef ::perf::TestBaseWithParam< std::string > Perf_Objdetect_QRCode;
|
||||
|
||||
PERF_TEST_P_(Perf_Objdetect_QRCode, detect)
|
||||
{
|
||||
const std::string name_current_image = GetParam();
|
||||
const std::string root = "cv/qrcode/";
|
||||
|
||||
std::string image_path = findDataFile(root + name_current_image);
|
||||
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
|
||||
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
||||
|
||||
std::vector< Point > corners;
|
||||
QRCodeDetector qrcode;
|
||||
TEST_CYCLE() ASSERT_TRUE(qrcode.detect(src, corners));
|
||||
const int pixels_error = 3;
|
||||
check_qr(root, name_current_image, "test_images", corners, {}, pixels_error);
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(Perf_Objdetect_QRCode, decode)
|
||||
{
|
||||
const std::string name_current_image = GetParam();
|
||||
const std::string root = "cv/qrcode/";
|
||||
|
||||
std::string image_path = findDataFile(root + name_current_image);
|
||||
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
|
||||
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
||||
|
||||
std::vector< Point > corners;
|
||||
std::string decoded_info;
|
||||
QRCodeDetector qrcode;
|
||||
ASSERT_TRUE(qrcode.detect(src, corners));
|
||||
TEST_CYCLE()
|
||||
{
|
||||
decoded_info = qrcode.decode(src, corners, straight_barcode);
|
||||
ASSERT_FALSE(decoded_info.empty());
|
||||
}
|
||||
const int pixels_error = 3;
|
||||
check_qr(root, name_current_image, "test_images", corners, {decoded_info}, pixels_error);
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
typedef ::perf::TestBaseWithParam<std::tuple<std::string, std::string>> Perf_Objdetect_QRCode_Multi;
|
||||
|
||||
static std::set<std::pair<std::string, std::string>> disabled_samples = {{"5_qrcodes.png", "aruco_based"}};
|
||||
|
||||
PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, detectMulti)
|
||||
{
|
||||
const std::string name_current_image = get<0>(GetParam());
|
||||
const std::string method = get<1>(GetParam());
|
||||
const std::string root = "cv/qrcode/multiple/";
|
||||
|
||||
std::string image_path = findDataFile(root + name_current_image);
|
||||
Mat src = imread(image_path);
|
||||
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
||||
std::vector<Point> corners;
|
||||
GraphicalCodeDetector qrcode = QRCodeDetector();
|
||||
if (method == "aruco_based") {
|
||||
qrcode = QRCodeDetectorAruco();
|
||||
}
|
||||
TEST_CYCLE() ASSERT_TRUE(qrcode.detectMulti(src, corners));
|
||||
const int pixels_error = 7;
|
||||
check_qr(root, name_current_image, "multiple_images", corners, {}, pixels_error, true);
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, decodeMulti)
|
||||
{
|
||||
const std::string name_current_image = get<0>(GetParam());
|
||||
std::string method = get<1>(GetParam());
|
||||
const std::string root = "cv/qrcode/multiple/";
|
||||
std::string image_path = findDataFile(root + name_current_image);
|
||||
Mat src = imread(image_path);
|
||||
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
||||
if (disabled_samples.find({name_current_image, method}) != disabled_samples.end()) {
|
||||
throw SkipTestException(name_current_image + " is disabled sample for method " + method);
|
||||
}
|
||||
GraphicalCodeDetector qrcode = QRCodeDetector();
|
||||
if (method == "aruco_based") {
|
||||
qrcode = QRCodeDetectorAruco();
|
||||
}
|
||||
std::vector<Point2f> corners;
|
||||
ASSERT_TRUE(qrcode.detectMulti(src, corners));
|
||||
std::vector<Mat> straight_barcode;
|
||||
std::vector< cv::String > decoded_info;
|
||||
TEST_CYCLE()
|
||||
{
|
||||
ASSERT_TRUE(qrcode.decodeMulti(src, corners, decoded_info, straight_barcode));
|
||||
}
|
||||
ASSERT_TRUE(decoded_info.size() > 0ull);
|
||||
for(size_t i = 0; i < decoded_info.size(); i++) {
|
||||
ASSERT_FALSE(decoded_info[i].empty());
|
||||
}
|
||||
ASSERT_EQ(decoded_info.size(), straight_barcode.size());
|
||||
vector<Point> corners_result(corners.size());
|
||||
for (size_t i = 0ull; i < corners_result.size(); i++) {
|
||||
corners_result[i] = corners[i];
|
||||
}
|
||||
|
||||
const int pixels_error = 7;
|
||||
check_qr(root, name_current_image, "multiple_images", corners_result, decoded_info, pixels_error, true);
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode,
|
||||
::testing::Values(
|
||||
"version_1_down.jpg", "version_1_left.jpg", "version_1_right.jpg", "version_1_up.jpg", "version_1_top.jpg",
|
||||
"version_5_down.jpg", "version_5_left.jpg",/*version_5_right.jpg*/ "version_5_up.jpg", "version_5_top.jpg",
|
||||
"russian.jpg", "kanji.jpg", "link_github_ocv.jpg", "link_ocv.jpg", "link_wiki_cv.jpg"
|
||||
)
|
||||
);
|
||||
// version_5_right.jpg DISABLED after tile fix, PR #22025
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode_Multi,
|
||||
testing::Combine(testing::Values("2_qrcodes.png", "3_close_qrcodes.png", "3_qrcodes.png", "4_qrcodes.png",
|
||||
"5_qrcodes.png", "6_qrcodes.png", "7_qrcodes.png", "8_close_qrcodes.png"),
|
||||
testing::Values("contours_based", "aruco_based")));
|
||||
|
||||
|
||||
typedef ::perf::TestBaseWithParam< tuple< std::string, Size > > Perf_Objdetect_Not_QRCode;
|
||||
|
||||
PERF_TEST_P_(Perf_Objdetect_Not_QRCode, detect)
|
||||
{
|
||||
std::vector<Point> corners;
|
||||
std::string type_gen = get<0>(GetParam());
|
||||
Size resolution = get<1>(GetParam());
|
||||
Mat not_qr_code(resolution, CV_8UC1, Scalar(0));
|
||||
if (type_gen == "random")
|
||||
{
|
||||
RNG rng;
|
||||
rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
|
||||
}
|
||||
if (type_gen == "chessboard")
|
||||
{
|
||||
uint8_t next_pixel = 0;
|
||||
for (int r = 0; r < not_qr_code.rows * not_qr_code.cols; r++)
|
||||
{
|
||||
int i = r / not_qr_code.cols;
|
||||
int j = r % not_qr_code.cols;
|
||||
not_qr_code.ptr<uchar>(i)[j] = next_pixel;
|
||||
next_pixel = 255 - next_pixel;
|
||||
}
|
||||
}
|
||||
|
||||
QRCodeDetector qrcode;
|
||||
TEST_CYCLE() ASSERT_FALSE(qrcode.detect(not_qr_code, corners));
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(Perf_Objdetect_Not_QRCode, decode)
|
||||
{
|
||||
Mat straight_barcode;
|
||||
std::vector< Point > corners;
|
||||
corners.push_back(Point( 0, 0)); corners.push_back(Point( 0, 5));
|
||||
corners.push_back(Point(10, 0)); corners.push_back(Point(15, 15));
|
||||
|
||||
std::string type_gen = get<0>(GetParam());
|
||||
Size resolution = get<1>(GetParam());
|
||||
Mat not_qr_code(resolution, CV_8UC1, Scalar(0));
|
||||
if (type_gen == "random")
|
||||
{
|
||||
RNG rng;
|
||||
rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
|
||||
}
|
||||
if (type_gen == "chessboard")
|
||||
{
|
||||
uint8_t next_pixel = 0;
|
||||
for (int r = 0; r < not_qr_code.rows * not_qr_code.cols; r++)
|
||||
{
|
||||
int i = r / not_qr_code.cols;
|
||||
int j = r % not_qr_code.cols;
|
||||
not_qr_code.ptr<uchar>(i)[j] = next_pixel;
|
||||
next_pixel = 255 - next_pixel;
|
||||
}
|
||||
}
|
||||
|
||||
QRCodeDetector qrcode;
|
||||
TEST_CYCLE() ASSERT_TRUE(qrcode.decode(not_qr_code, corners, straight_barcode).empty());
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_Not_QRCode,
|
||||
::testing::Combine(
|
||||
::testing::Values("zero", "random", "chessboard"),
|
||||
::testing::Values(Size(640, 480), Size(1280, 720),
|
||||
Size(1920, 1080), Size(3840, 2160))
|
||||
));
|
||||
|
||||
}
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user