小编Sim*_*her的帖子

使用大型管道更快地渲染mayavi场景

mayavi.mlab用来显示从图像中提取的3D数据.数据如下:

  1. 3D摄像机参数为摄像机中心周围的3线条x, y, x,通常用于约20台摄像机mlab.plot3d().
  2. 3D空间中的彩色点用于关于4000点的使用mlab.points3d().

对于(1)我有一个功能来分别为每个摄像机绘制每条线.如果我是正确的,所有这些行都被添加到当前场景的mayavi管道中.在mlab.show()场景需要大约10秒钟来渲染所有这些线条.

对于(2)我找不到一种方法来一次绘制所有点,每个点都有不同的颜色,所以此刻我会迭代mlab.points3d(x,y,z, color = color).我有更新的等待这个例程完成,因为它需要很长时间.如果我用相同的颜色一次绘制所有点,则需要大约2秒钟.

我已经尝试使用fig.scene.disable_render = True并重置fig.scene.disable_render = False之前启动我的脚本,然后显示场景mlab.show().

如何在合理的等待时间内使用mayavi显示我的数据?

python mayavi

6
推荐指数
1
解决办法
1200
查看次数

使用 boost 将 C *FILE 转换为 C++ iostream

我对 C++ 相当陌生,想要将 *FILE(例如由 popen() 返回)转换为 iostream,以便与 getline 等函数一起使用。我找到了以下代码http://fw-geekycoder.blogspot。 co.za/2011/06/how-to-convert-c-file-to-c-iostream.html,以及来自很多地方的类似代码,但编译器抱怨boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_sink> bis(fd);boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_sink> bis(fd);

\n\n
#include <iostream>\n#include <cstdio>\n#include <unistd.h>\n#include <boost/iostreams/device/file_descriptor.hpp>\n#include <boost/iostreams/stream.hpp>\n\nvoid write() {\n    FILE* fp = fopen("whatever.txt", "w");\n    if (fp == NULL) {\n        perror("fopen error");\n    }\n    int fd = fileno(fp);\n    boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_sink> bis(fd);\n    std::ostream os(&bis);\n    os << "Hello World!" << std::endl;\n\n    fclose(fp);\n}\n\nvoid read() {\n    FILE* fp = fopen("whatever.txt", "r");\n    if (fp == NULL) {\n        perror("fopen error");\n    }\n    int fd = fileno(fp);\n    boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_source> bis(fd);\n    std::istream is(&bis);\n    while (is) {\n …
Run Code Online (Sandbox Code Playgroud)

c++ boost iostream boost-iostreams

4
推荐指数
1
解决办法
1911
查看次数

管道到 FFMPEG 与 Python 子进程冻结

通过以下代码,我可以使用 Python、Numpy 和 FFMPEG 二进制文件将视频帧通过管道传输到 FFMPEG:

from __future__ import print_function
import subprocess
import numpy as np
import sys

npshape = [480, 480]
cmd_out = ['ffmpeg',
           '-y', # (optional) overwrite output file if it exists
           '-f', 'rawvideo',
           '-vcodec','rawvideo',
           '-s', '%dx%d'%(npshape[1], npshape[0]), # size of one frame
           '-pix_fmt', 'rgb24',
           '-r', '24', # frames per second
           '-i', '-', # The input comes from a pipe
           '-an', # Tells FFMPEG not to expect any audio
           '-vcodec', 'mpeg4',
           'output.mp4']

fout = subprocess.Popen(cmd_out, stdin=subprocess.PIPE, stderr=subprocess.PIPE).stdin

for …
Run Code Online (Sandbox Code Playgroud)

python subprocess ffmpeg

4
推荐指数
1
解决办法
3055
查看次数

读取 iostream 直到找到字符串分隔符

我目前有一个从流中读取的函数,直到找到预定义的流停止器。我目前可以启动并运行它的唯一方法是使用 std::getline 并让一个字符后跟一个换行符(在我的情况下char(3))作为我的流停止器。

std::string readuntil(std::istream& in) {
    std::string text;
    std::getline(in, text, char(3));
    return text;
}
Run Code Online (Sandbox Code Playgroud)

有什么方法可以实现相同的但使用更大的字符串作为我的流停止器?我不介意它后面必须跟一个换行符,但我希望我的分隔符是某个大小的随机字符串,这样它在流中的变化发生的概率非常低。

知道如何实现这一目标吗?

c++

3
推荐指数
1
解决办法
1854
查看次数

如何在mayavi中绘制彩色图像(imshow)

是否可以使用mayavi绘制带有3个颜色通道的图像?根据mayavi的文档,mayavi.mlab.imshow只能处理形状(nxm)的图像.

python image mayavi

2
推荐指数
1
解决办法
1988
查看次数

Python"with"语句堆积

我倾向于经常使用Python"with"语句.在我将一些文件符号链接或复制到目录后,主要用于清理目录,因为即使python脚本崩溃,任务仍然会执行.以下是我的函数的示例,可以与"with"语句一起使用.

@contextmanager
def use_symlink(orig, dest):
    os.symlink(orig, dest)
    try: 
        yield
    finally:
        os.unlink(link)
Run Code Online (Sandbox Code Playgroud)

我使用这些语句的方式很快就会堆积起来.

#Off to an adventure
with use_symlink(a, b):
    with use_symlink(c, b):
        with use_symlink(d, b):
            with working_dir(dir1):
                #do something
            with working_dir(dir2):
                #do something that creates file dir2_file1, dir2_file2
                with use_symlink(dir2_file1, b):
                   with use_symlink(dir2_file2, b):
                       with working_dir(b):
                           #Do the last thing
#Home safely
Run Code Online (Sandbox Code Playgroud)

是否有更好的方法来执行上述操作与强大的"with"语句相同的简易性和安全性?

python with-statement contextmanager

1
推荐指数
1
解决办法
244
查看次数