使用opencv:开源工具CropImage -- 截取图片并更新Annotation坐标

CropImage Introduction

★ Download code

sudo apt-get install git
git clone https://github.com/galian123/CropImage

★ Configure Environment

  • Install opencv:
sudo apt-get install libopencv-dev

You can also refer to https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html .

  • Install cmake, boost, gflags:
sudo apt-get install cmake libboost-all-dev libgflags-dev

★ Compile

Current directory is CropImage.

cd build
cmake ..
make
make install

The executable file CropImage will be generated in ./build directory.
make install will put CropImage into your ~/bin. You can add ~/bin to your $PATH in ~/.bashrc, like this: PATH=~/bin:$PATH. Then run source ~/.bashrc.

★ Usage of CropImage

Current directory is CropImage.
Use CropImage -helpshort to get more help information.

./CropImage -helpshort
cropImage: crop images and save resize_width * resize_height area which contains labels.
It may split one image into several images with name suffix like 'xxx_1.png', 'xxx_2.png', etc.
Please use 'CropImage -helpshort' to get only help message for CropImage. 
Usage:
    CropImage -imgdir <image_folder> -labeldir <label_folder>
    CropImage -imgdir <image_folder> 
If '-labeldir' is not set, then use 'imgdir' as 'labeldir'.
Default image output folder is './output_image_<time>'. Default label output folder is './output_label_<time>'

  Flags from /home/galian/test/opencv/cropImage/cropImage.cpp:
    -imgdir (Set the input directory contains images.) type: string default: ""
    -labeldir (Set the input directory contains label files. If not set, use
      'imgdir' instead.) type: string default: ""
    -out_imgdir (Set the output directory which saves converted images.)
      type: string default: "./output_image"
    -out_labeldir (Set the output directory which saves converted label files.)
      type: string default: "./output_label"
    -resize_height (Height images are resized to) type: int32 default: 300
    -resize_width (Width images are resized to) type: int32 default: 300
    -verbose (show more logs) type: bool default: false

★ Example

Current directory is CropImage.

./CropImage -imgdir ../test_image/

★ Output

Croped images will be saved to output_image_<time> folder, like this output_image_300_300_2017-12-20_23-10-04.

Annotation files (label files) are saved into output_label_<time> folder, like this output_label_300_300_2017-12-20_23-10-04.

Warning information will be saved into result_warning_<time>.txt, like this result_warning_2017-12-20_23-10-04.txt.

You can use LabelImg to verify the result.

Original image file with annotations:
orig.png

After image is cropped, it is divided into two parts.
crop1.png

crop2.png

★ Notes

♦ box boundary exceed resize_width * resize_height

If the annotation box boundary exceed resize_width * resize_height (eg. 300 * 300), then warning info will be write to screen and log file.

print on screen: this annotation box boundary exceed 300 * 300

print to log file ./result_warning_<time>.txt

This annotation box boundary exceed 300 * 300, when processing ../test_image/99.jpg, labelfile: ../test_image/99.xml
(xmin: 470, xmax: 694, ymin: 88, ymax: 673, width: 225, height: 586)

♦ Now <path> and <filename> in annotation file are NOT changed after image is cropped.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值