我在link here运行稀疏光流演示,我只是想在视频中所有帧之间跟踪的单个点之间划一条线。
在for循环中,
int LastX = 0;
int LastY = 0;
int px, py;
else if( !points[0].empty() )
{
vector<uchar> status;
vector<float> err;
if(prevGray.empty())
gray.copyTo(prevGray);
calcOpticalFlowPyrLK(prevGray, gray, points[0], points[1], status, err, winSize,
3, termcrit, 0, 0.001);
size_t i, k;
for( i = k = 0; i < points[1].size(); i++ )
{
if( addRemovePt )
{
if( norm(point - points[1][i]) <= 5 )
{
addRemovePt = false;
continue;
}
}
if( !status[i] )
continue;
points[1][k++] = points[1][i];
px = points[1][i].x;
py = points [1][i].y;
if (LastX > 0)
{
line(image, Point(px, py), Point(LastX, LastY), Scalar(255, 0, 0), 5);
}
LastX = px;
LastY = py;
circle( image, points[1][i], 3, Scalar(0,255,0), -1, 8);
}
points[1].resize(k);
}
但是,该行仅出现在当前帧中,并且该行的位置不会保存在先前帧中。有人可以告诉我我做错了吗?
答案 0 :(得分:0)
尝试使用 JavaSparkContext context = ......;
//Retrieve list of files from master file
List<String> files = context.textFile("/somepath/catmydata.csv")
.flatMap(row->Arrays.asList(row.split(",")).iterator()).collect();
//Iterate through each file and save it as object file
Map<String,JavaRDD<Cat>> adoptedCatsMap =new HashMap<String,JavaRDD<Cat>>();
for (String file:files) {
// Extract file path and attach to convert
String output=String.format("/convertedcatdata/%s",file.substring(file.indexOf('/'),file.length()))
JavaRDD<Cat> adoptedCatsRdd = context.textFile(file).map(s->new Cat(s));
adoptedCatsMap.put(output,adoptedCatsRdd);
//This will write number of files based on rdd partitions,
// if you want only one file in a directory then save it
// to temporary directory then use copyMerge to create one file using Hadoop fs FileUtil
// https://hadoop.apache.org/docs/r2.7.1/api/org/apache/hadoop/fs/FileUtil.html
//Save to physical location if required.
adoptedCatsRdd.saveAsObjectFile(output);
}
存储从第一帧到最后一帧的匹配点对。
流点的匹配过程与汽车追踪类似。
你可以参考这个Counting cars by Dan Mašek。