7#include <opencv2/imgproc/types_c.h>
9#include <opencv2/videoio/videoio_c.h>
11#define CVVISUAL_DEBUGMODE
21template<
class T> std::string toString(
const T& p_arg)
34main(
int argc,
char** argv)
40 "{ help h usage ? | | show this message }"
41 "{ width W | 0| camera resolution width. leave at 0 to use defaults }"
42 "{ height H | 0| camera resolution height. leave at 0 to use defaults }";
45 if (parser.has(
"help")) {
46 parser.printMessage();
49 int res_w = parser.get<
int>(
"width");
50 int res_h = parser.get<
int>(
"height");
54 if (!capture.isOpened()) {
55 std::cout <<
"Could not open VideoCapture" << std::endl;
59 if (res_w>0 && res_h>0) {
60 printf(
"Setting resolution to %dx%d\n", res_w, res_h);
61 capture.set(CV_CAP_PROP_FRAME_WIDTH, res_w);
62 capture.set(CV_CAP_PROP_FRAME_HEIGHT, res_h);
67 std::vector<cv::KeyPoint> prevKeypoints;
70 int maxFeatureCount = 500;
71 Ptr<ORB> detector = ORB::create(maxFeatureCount);
75 for (
int imgId = 0; imgId < 10; imgId++) {
79 printf(
"%d: image captured\n", imgId);
81 std::string imgIdString{
"imgRead"};
82 imgIdString += toString(imgId);
91 std::vector<cv::KeyPoint> keypoints;
93 detector->detectAndCompute(imgGray,
cv::noArray(), keypoints, descriptors);
94 printf(
"%d: detected %zd keypoints\n", imgId, keypoints.size());
97 if (!prevImgGray.
empty()) {
98 std::vector<cv::DMatch> matches;
99 matcher.match(prevDescriptors, descriptors, matches);
100 printf(
"%d: all matches size=%zd\n", imgId, matches.size());
101 std::string allMatchIdString{
"all matches "};
102 allMatchIdString += toString(imgId-1) +
"<->" + toString(imgId);
106 double bestRatio = 0.8;
107 std::sort(matches.begin(), matches.end());
108 matches.resize(
int(bestRatio * matches.size()));
109 printf(
"%d: best matches size=%zd\n", imgId, matches.size());
110 std::string bestMatchIdString{
"best " + toString(bestRatio) +
" matches "};
111 bestMatchIdString += toString(imgId-1) +
"<->" + toString(imgId);
115 prevImgGray = imgGray;
116 prevKeypoints = keypoints;
117 prevDescriptors = descriptors;
暴力描述符匹配器。
定义 features2d.hpp:1247
如果数组没有元素,则返回 true。
int64_t int64
cv::getTickFrequency
double getTickFrequency()
用于指定图像或矩形大小的模板类。
Definition types.hpp:335
用于从视频文件、图像序列或摄像头捕获视频的类。
Definition videoio.hpp:772
@ NORM_HAMMING
定义 base.hpp:199
std::shared_ptr< _Tp > Ptr
Definition cvstd_wrapper.hpp:23
InputOutputArray noArray()
template<typename
_Tp , int m, int n>
void finalShow()
最后一次将控制权传递给调试窗口。
定义 final_show.hpp:23
static void debugDMatch(cv::InputArray img1, std::vector< cv::KeyPoint > keypoints1, cv::InputArray img2, std::vector< cv::KeyPoint > keypoints2, std::vector< cv::DMatch > matches, const impl::CallMetaData &data, const char *description=nullptr, const char *view=nullptr, bool useTrainDescriptor=true)
将已填充的DMatch <dmatch> 添加到调试GUI。
定义 dmatch.hpp:49
static void showImage(cv::InputArray img, impl::CallMetaData metaData=impl::CallMetaData(), const char *description=nullptr, const char *view=nullptr)
将单个图像添加到调试GUI(类似于imshow <>)。
定义 show_image.hpp:38
static void debugFilter(cv::InputArray original, cv::InputArray result, impl::CallMetaData metaData=impl::CallMetaData(), const char *description=nullptr, const char *view=nullptr)
使用调试框架比较两张图像(其中第二张图像应为...的结果)
定义 filter.hpp:36
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0, AlgorithmHint hint=cv::ALGO_HINT_DEFAULT)
将图像从一个颜色空间转换为另一个颜色空间。
int main(int argc, char *argv[])
定义 highgui_qt.cpp:3
cmake_minimum_required(VERSION 2.8)
project(cvvisual_test)
SET(CMAKE_PREFIX_PATH ~/software/opencv/install)
SET(CMAKE_CXX_COMPILER "g++-4.8")
SET(CMAKE_CXX_FLAGS "-std=c++11 -O2 -pthread -Wall -Werror")
# (un)set: cmake -DCVV_DEBUG_MODE=OFF ..
OPTION(CVV_DEBUG_MODE "cvvisual-debug-mode" ON)
if(CVV_DEBUG_MODE MATCHES ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCVVISUAL_DEBUGMODE")
endif()
FIND_PACKAGE(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(cvvt main.cpp)
target_link_libraries(cvvt
opencv_core opencv_videoio opencv_imgproc opencv_features2d
opencv_cvv
)