在图像上检测人脸的不同技术,从使用具有 Haar 特征的级联分类器的更经典算法到采用深度学习的新技术;使用 OpenCV.js 为 Web 开发计算机视觉算法的新方法,OpenCV.js 是用于 JavaScript 的 OpenCV 的编译版本;
使用 OpenCV 的 ArUco 模块、Android 的 Camera2 API 和 JMonkeyEngine 3D 游戏引擎在 Android 生态系统中实现增强现实 (AR) 应用程序;使用 OpenCV 的 iOS 预编译库在 iPhone 上构建全景图像拼接应用程序。
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#define CERES_FOUND true
#include <opencv2/core/utils/filesystem.hpp>
#include <opencv2/core/utils/logger.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/sfm.hpp>
#include <opencv2/viz.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <boost/filesystem.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/graphviz.hpp>
#define _USE_OPENCV true
#include <libs/MVS/Interface.h>
using namespace cv;
using namespace std;
namespace fs = boost::filesystem;
class StructureFromMotion {
public:
StructureFromMotion(const string& dir, const float matchSurvivalRate = 0.5f,
const bool viz = false, const string mvs = "", const string cloud = "",
const bool saveDebug = false)
: PAIR_MATCH_SURVIVAL_RATE(matchSurvivalRate)
, visualize(viz)
, saveMVS(mvs)
, saveCloud(cloud)
, saveDebugVisualizations(saveDebug)
{
findImagesInDiretcory(dir);
}
void runSfM()
{
extractFeatures();
matchFeatures();
buildTracks();
reconstructFromTracks();
if (visualize) {
visualize3D();
}
if (saveMVS != "") {
saveToMVSFile();
}
if (saveCloud != "") {
CV_LOG_INFO(TAG, "Save point cloud to: " + saveCloud);
viz::writeCloud(saveCloud, pointCloud, pointCloudColor);
}
}
void extractFeatures()
{
CV_LOG_INFO(TAG, "Extract Features");
auto detector = AKAZE::create();
auto extractor = AKAZE::create();
for (const auto& i : imagesFilenames) {
Mat grayscale;
cvtColor(images[i], grayscale, COLOR_BGR2GRAY);
detector->detect(grayscale, keypoints[i]);
extractor->compute(grayscale, keypoints[i], descriptors[i]);
CV_LOG_INFO(TAG, "Found " + to_string(keypoints[i].size()) + " keypoints in " + i);
if (saveDebugVisualizations) {
Mat out;
drawKeypoints(images[i], keypoints[i], out, Scalar(0, 0, 255));
imwrite(fs::basename(fs::path(i)) + "_features.jpg", out);
}
}
}
vector<DMatch> matchWithRatioTest(
const DescriptorMatcher& matcher, const Mat& desc1, const Mat& desc2)
{
// Raw match
vector<vector<DMatch>> nnMatch;
matcher.knnMatch(desc1, desc2, nnMatch, 2);
// Ratio test filter
vector<DMatch> ratioMatched;
for (size_t i = 0; i < nnMatch.size(); i++) {
DMatch first = nnMatch[i][0];
float dist1 = nnMatch[i][0].distance;
float dist2 = nnMatch[i][1].distance;
if (dist1 < MATCH_RATIO_THRESHOLD * dist2) {
ratioMatched.push_back(first);
}
}
return ratioMatched;
}
使用 OpenCV 的 ArUco 模块、Android 的 Camera2 API 和 JMonkeyEngine 3D 游戏引擎在 Android 生态系统中实现增强现实 (AR) 应用程序