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

本文共 2219 字,大约阅读时间需要 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目录下找到文件。

转载地址:http://poxql.baihongyu.com/

你可能感兴趣的文章
iOS9 App Thinning(应用瘦身)功能介绍
查看>>
LVS(DR) + Keepalive实现负载均衡
查看>>
JavaScript基础教程(一)
查看>>
关于容灾的那些事儿
查看>>
查询?还是计算?这不再是个问题!(二)
查看>>
SQL Server Alwayson读写分离配置
查看>>
【源资讯 第41期】前端项目一言不合就分叉;工程师一言不合就删库??
查看>>
date(时间),timedatectl(时区),cal(日历)的用法
查看>>
软件设计流程+***搭建
查看>>
Mycat实现MySQL的分库分表、读写分离、主从切换
查看>>
NTP服务器
查看>>
195. 安装solr服务器
查看>>
一个完整的 Web 请求到底发生了什么
查看>>
三星8.0系统设备最完美激活xposed框架的方法
查看>>
云计算的未来是自动化
查看>>
科略教育:三个层次说战略
查看>>
nginx 502错误
查看>>
VS2013环境下Boost库配置
查看>>
F5多出口配置
查看>>
Android Studio 第六十二期 - Android框架
查看>>