我必须检查点之间的几个距离与距离阈值.我能做的是取我的门槛的平方,并将其与平方标准进行比较(a-b),在哪里a以及b我正在检查的点.
我知道cv::norm函数,但我想知道是否存在不计算平方根的版本(因此更快)或者我是否应该手动实现它.
我正在尝试应用X宏概念,以便有可能将所有struct成员初始化为自定义默认(无效)值.我写下面的代码:
#define LIST_OF_STRUCT_MEMBERS_foo \
X(a) \
X(b) \
X(c)
#define X(name) int name;
struct foo {
LIST_OF_STRUCT_MEMBERS_foo
};
#undef X
#define X(name) -1,
static inline void foo_invalidate(struct foo* in) {
*in = (struct foo){
LIST_OF_STRUCT_MEMBERS_foo
};
}
#undef X
#define X(name) -1,
#define foo_DEFAULT_VALUE { LIST_OF_STRUCT_MEMBERS_foo }
#undef X
static struct foo test = foo_DEFAULT_VALUE;
Run Code Online (Sandbox Code Playgroud)
但是,当我运行预处理器时,定义foo_DEFAULT_VALUE无法替换X(name)调用-1,
预处理器输出:
struct foo {
int a; int b; int c;
};
static inline void foo_invalidate(struct foo* in) …Run Code Online (Sandbox Code Playgroud) 我们目前正在尝试升级我们程序使用的ffmpeg版本.跳跃很大,因为到目前为止我们使用的是ffmpeg 0.8,最新版本是1.2.
在这些测试中我使用的是(让我说)惊人的包,我觉得在这里.
首先,我尝试下载并构建ffmpeg 1.2,当然我收到了很多警告和错误,关于函数和变量已弃用或不再存在.
为了平滑过渡,我尝试针对ffmpeg 1.0进行构建,ffmpeg 1.0是最接近0.8的最高版本.我得到了一个警告和错误列表,我在下面列出.
我的问题如下:在新版本中转换旧的ffmpeg范例/函数调用是否存在帮助这些转换的指南?既然我们正在谈论很多我没写过的代码,并且我不想逐行分析,那么如果能够对旧函数调用进行一对一的转换,我会非常高兴.新函数调用,变量相同.
这是警告和错误的列表(我已清理它,因此每个错误/警告只有一个条目)
warning: 'AVStream* av_new_stream(AVFormatContext*, int)' is deprecated (declared at /ffmpeg/include/libavformat/avformat.h:1646) [-Wdeprecated-declarations]
warning: 'int avcodec_open(AVCodecContext*, AVCodec*)' is deprecated (declared at /ffmpeg/include/libavcodec/avcodec.h:3569) [-Wdeprecated-declarations]
error: 'avcodec_init' was not declared in this scope
warning: 'int avcodec_encode_video(AVCodecContext*, uint8_t*, int, const AVFrame*)' is deprecated (declared at /ffmpeg/include/libavcodec/avcodec.h:4272) [-Wdeprecated-declarations]
warning: 'AVCodecContext* avcodec_alloc_context()' is deprecated (declared at /ffmpeg/include/libavcodec/avcodec.h:3423) [-Wdeprecated-declarations]
warning: 'int avcodec_decode_audio3(AVCodecContext*, int16_t*, int*, AVPacket*)' is deprecated (declared at /ffmpeg/include/libavcodec/avcodec.h:3852) [-Wdeprecated-declarations]
warning: 'void av_close_input_file(AVFormatContext*)' is …Run Code Online (Sandbox Code Playgroud) 鉴于这个起点:
double y = readDoubleValue();
Run Code Online (Sandbox Code Playgroud)
C++之间是否有任何显着差异:
int x = y;
Run Code Online (Sandbox Code Playgroud)
和
int x = trunc(y);
Run Code Online (Sandbox Code Playgroud)
我应该选择哪一个?如果其他人(包括我未来的自己):)读取我的代码,它看起来我用第二个更明确的事实,我确切知道我在做什么,但它需要一个库包含.
参考: C++中是否有trunc函数?
我想了解以下代码是否正确,或者不是:
#include <deque>
template<class T>
struct Node {
std::deque<Node<T> > branches;
T data;
Node(const T& _data) : data(_data) {
}
};
void dummy() {
Node<float> test(5.0f);
}
Run Code Online (Sandbox Code Playgroud)
此代码使用多个工具链编译而不会产生错误(请参阅此处).问题是,现在我得到一个实例化错误(可能与我使用llvm libc ++,不确定版本的事实有关).
<...>llvm-libc++/include/deque:912:55: error: invalid application of 'sizeof' to incomplete type 'std::__1::__deque_base<Node<float>, std::__ 1::allocator<Node<float> > >::value_type {aka Node<float>}'
static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16;
Run Code Online (Sandbox Code Playgroud)
如果这段代码是正确的,我不想调查bug的起源(编译器或std库实现)或有一个解决方法:再次,我主要想了解上面的代码是否正式正确.
我从来没有把过多考虑到静态库和动态库之间的大小差异,直到今天我下载了升压的预建库.我发现boost的静态库远远大于动态库.
例如,调试多线程boost wave静态库97.7 mb的大小,而相同的库,但动态,只是1.4 mb大小(包括导入库和DLL)!这是一个巨大的差异.这是为什么?
第二个问题,如果我静态链接,比方说,wave图书馆.这是否意味着我的可执行文件的大小会超过97.7 mb?
boost dynamic-linking static-libraries static-linking dynamic-library
所以我把我的手机超频到了1.664ghz,我知道有些应用可以测试你的手机的CPU性能和修饰器,但我想自己做一些.真正让CPU工作的最佳方法是什么?我只是想做一个for循环做一百万次迭代做一些耗时的数学......但这不起作用,因为我的手机在几毫秒内做到了我认为......我尝试了数万亿次迭代......应用程序冻结,但我的任务管理器甚至没有显示应用程序使用的CPU.通常压力测试应用程序显示为红色并说cpu:85%ram:10mb ...那么我怎样才能真正让我的处理器认真思考?
灵感来自于此.
假设我们有一个非空的std::vector<T> v;
是否有任何区别
for (int i = v.size() - 1; i >= 0; i--) {
///Stuff.
}
Run Code Online (Sandbox Code Playgroud)
和:
for (int i = v.size(); i--; ) {
///Stuff.
}
Run Code Online (Sandbox Code Playgroud)
?
我的意思是,出于可读性考虑,我不会这样做,但是谁知道生活中有用的东西......
(这里只是一个测试,看它们是等价的)
编辑:要点是i向后访问向量的索引(在索引优于迭代器的情况下)
我正在看这个有趣的主题:https: //stackoverflow.com/a/16596463/2436175
我的具体情况涉及使用来自opencv的cv :: Point_和cv :: Rect_的std容器声明模板化函数.我想反对模板:
我最后得到了以下声明:
template <typename T, template <typename, typename> class Container_t>
void CreateRects(const Container_t<cv::Point_<T>,std::allocator<cv::Point_<T> > >& points,
const T value,
Container_t<cv::Rect_<T>,std::allocator<cv::Rect_<T> > >& rects) {
}
Run Code Online (Sandbox Code Playgroud)
用这个编译很好:
void dummy() {
const std::vector<cv::Point_<double> > points;
std::vector<cv::Rect_<double> > rects;
CreateRects(points,5.0,rects);
}
Run Code Online (Sandbox Code Playgroud)
(我也看到我也可以使用,例如,CreateRects<double>(points,5,rects))
我想知道是否存在任何方式使我的声明更紧凑,例如,无需指定默认分配器的2倍.
我在将cmake PROJECT_VERSION_MAJOR变量导出到config.h文件时遇到问题.在我的主要内容CMakeLists.txt我通过调用project()主CMakeLists.txt文件根据cmake文档设置此变量:
cmake_minimum_required(VERSION 3.2.2)
cmake_policy(SET CMP0048 NEW)
set(PROJECT "SampleName")
project(${PROJECT}
VERSION "0.0.0")
configure_file(${CMAKE_SOURCE_DIR}/cmake/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
Run Code Online (Sandbox Code Playgroud)
通过configure_file()invokation我试图将一些cmake变量导出config.h到头文件.请看看我的config.h.cmake.file:
#ifndef CONFIG_H
#define CONFIG_H
#cmakedefine PROJECT "@PROJECT@"
#cmakedefine PROJECT_VERSION "@PROJECT_VERSION@"
#cmakedefine PROJECT_VERSION_MAJOR "@PROJECT_VERSION_MAJOR@"
#cmakedefine PROJECT_VERSION_MINOR "@PROJECT_VERSION_MINOR@"
#cmakedefine PROJECT_VERSION_PATCH "@PROJECT_VERSION_PATCH@"
#endif
Run Code Online (Sandbox Code Playgroud)
cmake ..在我的构建目录中运行命令后config.h创建,但它看起来像这样:
#ifndef CONFIG_H
#define CONFIG_H
#define PROJECT "SampleName"
#define PROJECT_VERSION "0.0.0"
/* #undef PROJECT_VERSION_MAJOR */
/* #undef PROJECT_VERSION_MINOR */
/* #undef PROJECT_VERSION_PATCH */
#endif
Run Code Online (Sandbox Code Playgroud)
我想这个行为的原因是在cmake文档中关于该configure_file() …