Bundler分析1

1.分析Runbundler.sh文件

这是个shell脚本,集合了一些命令一起执行

#!/bin/bash
#告诉系统其后路径所指定的程序即是解释此脚本文件的 Shell 程序
# RunBundler.sh
#   copyright 2008 Noah Snavely
#
# A script for preparing a set of image for use with the Bundler 
# structure-from-motion system.
#
# Usage: RunBundler.sh [image_dir]
#
# The image_dir argument is the directory containing the input images.
# If image_dir is omitted, the current directory is used.
#

# Set this variable to your base install path (e.g., /home/foo/bundler)
# BASE_PATH="TODO"

#$0当前Shell程序的文件名
#dirname $0,获取当前Shell程序的路径
#cd `dirname $0`,进入当前Shell程序的目录
# $0 为执行的文件名:./test.sh



BASE_PATH=$(dirname $(which $0));

if [ $BASE_PATH == "TODO" ]
then
    echo "Please modify this script (RunBundler.sh) with the base path of your bundler installation.";
    exit;
fi
#定义变量EXTRACT_FOCAL,存放extract_focal.pl的路径
EXTRACT_FOCAL=$BASE_PATH/bin/extract_focal.pl

OS=`uname -o`

if [ $OS == "Cygwin" ]
then
    MATCHKEYS=$BASE_PATH/bin/KeyMatchFull.exe
    BUNDLER=$BASE_PATH/bin/Bundler.exe
else
    MATCHKEYS=$BASE_PATH/bin/KeyMatchFull
    BUNDLER=$BASE_PATH/bin/bundler
fi
#存放ToSift.sh路径
TO_SIFT=$BASE_PATH/bin/ToSift.sh
#图片路径默认当前目录
IMAGE_DIR="."
#如果通过参数形式给出了图片路径,那就用图片的路径
if [ $# -eq 1 ]
then
    echo "Using directory '$1'"
    IMAGE_DIR=$1
fi

# Rename ".JPG" to ".jpg"
for d in `ls -1 $IMAGE_DIR | egrep ".JPG$"`
do 
    mv $IMAGE_DIR/$d $IMAGE_DIR/`echo $d | sed 's/\.JPG/\.jpg/'`
done

# Create the list of images
find $IMAGE_DIR -maxdepth 1 | egrep ".jpg$" | sort > list_tmp.txt

#提取照片焦距信息
$EXTRACT_FOCAL list_tmp.txt
#复制prepare下的list.txt到当前目录(图片目录)
cp prepare/list.txt .
#提取sift特征点
# Run the ToSift script to generate a list of SIFT commands
echo "[- Extracting keypoints -]"
rm -f sift.txt
$TO_SIFT $IMAGE_DIR > sift.txt 

# Execute the SIFT commands
sh sift.txt
#匹配特征点
# Match images (can take a while)
echo "[- Matching keypoints (this can take a while) -]"
sed 's/\.jpg$/\.key/' list_tmp.txt > list_keys.txt
sleep 1
echo $MATCHKEYS list_keys.txt matches.init.txt
$MATCHKEYS list_keys.txt matches.init.txt
#生成options文件执行bundler
# Generate the options file for running bundler 
mkdir bundle
rm -f options.txt

echo "--match_table matches.init.txt" >> options.txt
echo "--output bundle.out" >> options.txt
echo "--output_all bundle_" >> options.txt
echo "--output_dir bundle" >> options.txt
echo "--variable_focal_length" >> options.txt
echo "--use_focal_estimate" >> options.txt
echo "--constrain_focal" >> options.txt
echo "--constrain_focal_weight 0.0001" >> options.txt
echo "--estimate_distortion" >> options.txt
echo "--run_bundle" >> options.txt

# Run Bundler!
echo "[- Running Bundler -]"
rm -f constraints.txt
rm -f pairwise_scores.txt
$BUNDLER list.txt --options_file options.txt > bundle/out

echo "[- Done -]"

总结四步:提取照片焦距 、提取sift特征点、匹配 、运行bundler

find $IMAGE_DIR -maxdepth 1 | egrep ".jpg$" | sort > list_tmp.txt会将图片路径名称保存在list_tmp.txt中

2.计算照片焦距信息(也就是执行sh中的$EXTRACT_FOCAL list_tmp.txt)

这一步会 通过jhead二进制文件分析照片,从中提取相机制造商和相机型号信息,如果有ccd width就提取,没有就从perl文件中的hash数组中找,提取mm为单位的焦距,提取分辨率,计算像素单位的焦距(保证宽大于长,宽为res_x)

$focal_pixels = $res_x * ($focal_mm / $ccd_width_mm);

将照片及焦距信息以下方式保存在prepare文件夹下的list.txt中:

$line = sprintf("%s.jpg 0 %0.5f", $basename, $SCALE * $focal_pixels);

即:./et000.jpg 0 660.80306

并将list.txt复制到照片路径下

3.提取sift特征点

$TO_SIFT $IMAGE_DIR > sift.txt 

ToSift.sh文件:生成SIFT命令,写入sift.txt 命令形式:mogrify -format pgm $IMAGE_DIR/$d; $SIFT < $pgm_file > $key_file; rm $pgm_file; gzip -f $key_file 将每张图片变为  图片名称.pgm  格式,并创建    图片名称.key 调用sift二进制文件(额外添加的): 图片名称.pgm 作为输入,结果写入 图片名称.key,打包 图片名称.key文件

注意:sift提取手机照片的特征点时,照片过大可能会出现错误,应在提取特征点之前对照片进行缩放处理

修改ToShift.sh文件

在之前

for d in `ls -1 $IMAGE_DIR | egrep "jpg$"`
do 
    
    pgm_file=$IMAGE_DIR/`echo $d | sed 's/jpg$/pgm/'`
    key_file=$IMAGE_DIR/`echo $d | sed 's/jpg$/key/'`

    echo "mogrify -format pgm $IMAGE_DIR/$d; $SIFT < $pgm_file > $key_file; rm $pgm_file; gzip -f $key_file"
done

添加(这样不会丢失照片exif信息,用美图秀秀会丢失exif)

for d in `ls -1 $IMAGE_DIR | egrep "jpg$"`
do 
    jpg_file=$IMAGE_DIR/$d   

    #当照片宽度大于两千时进行缩放,设置宽为2000,保持宽高比

    echo "convert -resize '2000x>' $jpg_file $jpg_file"
done


 

执行前:

sh sift.txt执行sift,提取特征点

执行后:

多了key文件

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值