博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
selective search生成.mat文件
阅读量:5232 次
发布时间:2019-06-14

本文共 2270 字,大约阅读时间需要 7 分钟。

https://github.com/sergeyk/selective_search_ijcv_with_python 里的selective_search.py是python接口

import tempfileimport subprocessimport shleximport osimport numpy as npimport scipy.ioscript_dirname = os.path.abspath(os.path.dirname(__file__))def get_windows(image_fnames, cmd='selective_search'):    """    Run MATLAB Selective Search code on the given image filenames to    generate window proposals.    Parameters    ----------    image_filenames: strings        Paths to images to run on.    cmd: string        selective search function to call:            - 'selective_search' for a few quick proposals            - 'selective_seach_rcnn' for R-CNN configuration for more coverage.    """    # Form the MATLAB script command that processes images and write to    # temporary results file.    f, output_filename = tempfile.mkstemp(suffix='.mat')    os.close(f)    fnames_cell = '{
' + ','.join("'{}'".format(x) for x in image_fnames) + '}' command = "{}({}, '{}')".format(cmd, fnames_cell, output_filename) print(command) # Execute command in MATLAB. mc = "matlab -nojvm -r \"try; {}; catch; exit; end; exit\"".format(command) pid = subprocess.Popen( shlex.split(mc), stdout=open('/dev/null', 'w'), cwd=script_dirname) retcode = pid.wait() if retcode != 0: raise Exception("Matlab script did not exit successfully!") # Read the results and undo Matlab's 1-based indexing. all_boxes = list(scipy.io.loadmat(output_filename)['all_boxes'][0]) subtractor = np.array((1, 1, 0, 0))[np.newaxis, :] all_boxes = [boxes - subtractor for boxes in all_boxes] # Remove temporary file, and return. os.remove(output_filename) if len(all_boxes) != len(image_fnames): raise Exception("Something went wrong computing the windows!") return all_boxesif __name__ == '__main__': """ Run a demo. """ import time image_filenames = [ script_dirname + '/000015.jpg', script_dirname + '/cat.jpg' ]*4 t = time.time() boxes = get_windows(image_filenames) print(boxes[:2]) print("Processed {} images in {:.3f} s".format( len(image_filenames), time.time() - t))

直接运行不会产生.mat文件,而是如图:

os.remove(output_filename)这句注释掉就可以在/tmp目录下找到文件。

转载于:https://www.cnblogs.com/ymjyqsx/p/6959328.html

你可能感兴趣的文章
【Java】数组转List常见方式的对比
查看>>
格式化函数的用法
查看>>
k8s之yaml文件书写格式
查看>>
Individual Reading Assignment
查看>>
[Swift]LeetCode780. 到达终点 | Reaching Points
查看>>
poj3085
查看>>
Java学习不走弯路教程(13 HTTP服务器)
查看>>
[LeetCode] 733. Flood Fill_Easy tag: BFS
查看>>
uptime命令_打印系统总共运行了多长时间和系统的平均负载
查看>>
自定义alert弹框,title不显示域名
查看>>
Linux sed 命令字符串替换使用方法详解
查看>>
Nested Loops join时显示no join predicate原因分析以及解决办法
查看>>
Mybatis遇到的坑
查看>>
loj题目总览
查看>>
mutillidae之Insert型注入
查看>>
python基础:面向对象
查看>>
编译安装 LLVM
查看>>
2019-06-07 学习日记 day28 THML
查看>>
Books
查看>>
C 语言代码规范
查看>>