我正在尝试一个看似非常简单的任务:使用bash搜索文件中的字符串,如果它们存在,则将它们输出到另一个文件.它可能是时差,但这应该工作:
#!/bin/bash
cnty=CNTRY
for line in $(cat wheatvrice.csv); do
if [[ $line = *$cnty* ]]
then
echo $line >> wr_imp.csv
fi
done
Run Code Online (Sandbox Code Playgroud)
我也尝试了这个完整性:
#!/bin/bash
cnty=CNTRY
for line in $(cat wheatvrice.csv); do
case $line in
*"$cnty"*) echo $line >> wr_imp.csv;;
*) echo "no";;
esac
done
Run Code Online (Sandbox Code Playgroud)
两者都输出所有内容,无论该行是否包含CNTRY,我都是从看似可靠的来源复制/粘贴的,所以显然有一些关于bash-ness的简单方法,我很遗憾?
有谁碰巧知道为什么OpenCV 2 DescriptorMatcher::radiusMatch()并knnMatch()采取vector<vector<DMatch>>& matches?我有点困惑为什么它不仅仅是一个矢量,因为它只是场景中与训练图像相对应的单个点阵,对吧?
我有这样的事情:
void getMatchingPoints(
const vector<vector<cv::DMatch> >& matches,
const vector<cv::KeyPoint>& keyPtsTemplates,
const vector<cv::KeyPoint>& keyPtsScene,
vector<Vec2f>& ptsTemplate,
vector<Vec2f>& ptsScene
)
{
ptsTemplate.clear();
ptsScene.clear();
for (size_t k = 0; k < matches.size(); k++)
{
for (size_t i = 0; i < matches[k].size(); i++)
{
const cv::DMatch& match = matches[k][i];
ptsScene.push_back(fromOcv(keyPtsScene[match.queryIdx].pt));
ptsTemplate.push_back(fromOcv(keyPtsTemplates[match.trainIdx].pt));
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我对如何实际映射大约有点困惑.一旦我将它们全部放入,对象的位置ptsScene.当我绘制它们时,这些点似乎散落在我身上,所以我想我错过了嵌套向量所代表的含义.
我正在将samples/c/motempl.c更新为OCV 2.3,我对cv :: updateMotionHistory()方法感到有些困惑.我按照motempl.c中的内容创建了历史记录:
history = cv::Mat::zeros(640, 480, CV_32FC1);
Run Code Online (Sandbox Code Playgroud)
然后,我这样调用updateMotionHistory():
cv::Mat diff = cv::Mat::zeros(640, 480, CV_8U);
if(prevFrame.size().width != 0) {
cv::absdiff(currentFrame, prevFrame, diff);
} else {
return;
}
cv::updateMotionHistory( diff, history, getElapsedSeconds(), MHI_DURATION);
Run Code Online (Sandbox Code Playgroud)
似乎没问题,但它总是抛出以下内容:
OpenCV Error: Sizes of input arguments do not match () in cvUpdateMotionHistory
Run Code Online (Sandbox Code Playgroud)
两个矩阵都是相同的大小,640,480,但只是为了好玩,我尝试将历史记录更改为CV_8U,这让我:
OpenCV Error: Unsupported format or combination of formats () in cvUpdateMotionHistory
Run Code Online (Sandbox Code Playgroud)
在样本之后,有这样的:
mhi = cvCreateImage( size, IPL_DEPTH_32F, 1 );
Run Code Online (Sandbox Code Playgroud)
我明白为什么历史需要是一个浮点图像,我只是不确定如何用矩阵而不是IplImage实例来调用这个方法.谢谢!
这是我的问题:我有一个.h文件中定义的虚方法,我想在一个继承自基类的类中调用它.遗憾的是,派生类中的方法不会被调用.有没有更好的方法来实现我正在尝试做的事情?
#ifndef ofxBASE_SND_OBJ
#define ofxBASE_SND_OBJ
#include "ofConstants.h"
class ofxBaseSndObj {
public:
virtual string getType(){}
string key;
};
#endif
Run Code Online (Sandbox Code Playgroud)
这是我的口碑课
#ifndef OFXSO_BUZZ
#define OFXSO_BUZZ
#include "ofxBaseSndObj.h"
class ofxSOBuzz : public ofxBaseSndObj
{
public:
string getType();
};
#endif
Run Code Online (Sandbox Code Playgroud)
ofxSOBuzz.cpp
string ofxSOBuzz::getType()
{
string s = string("ofxSOBuzz");
printf(" ********* returning string type %s", s.c_str()); // doesn't get called!
return s;
}
Run Code Online (Sandbox Code Playgroud)
然后在另一个类中我尝试这样称呼它:
string ofxSndObj::createFilter(ofxBaseSndObj obj)
{
string str = obj.getType();
if(str.compare("ofxSOBuzz") == 0)
{
printf(" all is well ");
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的方法中,我需要能够传递所有扩展ofxBaseSndObj对象的多种对象之一.任何建议或指示将不胜感激.谢谢!