我有一个紧凑的循环,我得到一个相机图像,不失真,并根据一些变换(例如透视变换)转换它.我已经想出cv::remap(...)
用于每个操作,这已经比使用普通矩阵操作更有效.
根据我的理解,应该可以将查找映射组合成一个,并在每次循环迭代中只调用一次重映射.有没有规范的方法来做到这一点?我宁愿不自己实现所有插值的东西.
注意:该过程应适用于不同大小的地图.在我的特定情况下,不失真保留图像尺寸,而另一个转换将图像缩放到不同的尺寸.
插图代码:
// input arguments
const cv::Mat_<math::flt> intrinsic = getIntrinsic();
const cv::Mat_<math::flt> distortion = getDistortion();
const cv::Mat mNewCameraMatrix = cv::getOptimalNewCameraMatrix(intrinsic, distortion, myImageSize, 0);
// output arguments
cv::Mat undistortMapX;
cv::Mat undistortMapY;
// computes undistortion maps
cv::initUndistortRectifyMap(intrinsic, distortion, cv::Mat(),
newCameraMatrix, myImageSize, CV_16SC2,
undistortMapX, undistortMapY);
// computes undistortion maps
// ...computation of mapX and mapY omitted
cv::convertMaps(mapX, mapY, skewMapX, skewMapY, CV_16SC2);
for(;;) {
cv::Mat originalImage = getNewImage();
cv::Mat undistortedImage;
cv::remap(originalImage, undistortedImage, undistortMapX, undistortMapY, cv::INTER_LINEAR);
cv::Mat skewedImage;
cv::remap(undistortedImage, skewedImage, skewMapX, …
Run Code Online (Sandbox Code Playgroud) 我有以下MWE:
#include <iostream>
#include <memory>
class A {
public:
int n = 42;
typedef std::shared_ptr<A> Ptr;
};
template<typename T>
void foo(typename T::Ptr arg) {
std::cout << arg->n << std::endl;
}
template<typename T>
void bar(T arg) {
std::cout << arg.n << std::endl;
}
int main() {
A::Ptr a = A::Ptr(new A());
foo<A>(a); // Can I avoid giving <A> here explicitly.
// foo(a); // does not compile
bar(*a); // after all this does work
return 0;
}
Run Code Online (Sandbox Code Playgroud)
对我来说,看起来也应该可以打电话foo(a)
而不是foo<A>(a)
.为什么这是不可能的,我可以以某种方式改变定义, …
假设一个模板类,我们在编译时断言整数模板参数必须大于零:
template<int N>
class A
{
public:
A() {
static_assert(N > 0, "N needs to be greater 0.");
}
};
Run Code Online (Sandbox Code Playgroud)
是否可以创建一个可编译但在运行时报告错误的 googletest 单元测试?例如:
TEST(TestA, ConstructionNotAllowedWithZero)
{
ASSERT_DOES_NOT_COMPILE(
{
A< 0 > a;
}
);
}
Run Code Online (Sandbox Code Playgroud) 我有以下数据:
df <- data.frame(A = c(1,2,3,4,5,6), B=c("P","P","P","Q","Q","Q"), C=c("a","b","c","d","e","f"))
df
## A B C
## 1 1 P a
## 2 2 P b
## 3 3 P c
## 4 4 Q d
## 5 5 Q e
## 6 6 Q f
Run Code Online (Sandbox Code Playgroud)
我想以某种方式为每个不同的B获取A中具有最小值的行,但是也使用C中的对应值
## A B C
## 1 1 P a
## 4 4 Q d
Run Code Online (Sandbox Code Playgroud)
我试过以下,但我想要的也没有:
> aggregate(df[c('A')], by=df[c('B')], FUN=min)
B A
1 P 1
2 Q 4
> aggregate(df[c('A')], by=df[c('B','C')], FUN=min)
B C A
1 P …
Run Code Online (Sandbox Code Playgroud)