小编tav*_*ndo的帖子

在不创建外部文本文件的情况下将终端输出捕获到 Pandas 数据帧中

我正在使用 ffmpeg 的 extract_mvs 文件来生成一些文本信息。我会在终端中使用这样的命令:

/extract_mvs input.mp4 > output.txt
Run Code Online (Sandbox Code Playgroud)

我想将此命令与Popenpython 中的或其他子进程一起使用,以便将数据直接传递到 Pandas 数据帧而不是实际生成文本文件,而不是 output.txt。

这个想法是多次自动化,所以,我试图避免生成许多 .txt 文件,从而避免open()一个一个地生成它们。

我想到了这样的事情:

import subprocess
cmd = ['./extract_mvs', 'input.mp4']
a = subprocess.Popen(cmd, stdout=subprocess.PIPE)
df = pd.read_csv(a.communicate()[0], sep=',')
Run Code Online (Sandbox Code Playgroud)

但后来我收到一个错误: OSError: Expected file path name or file-like object, got <class 'bytes'> type

它可以固定和扩展以便直接从子进程读取到熊猫吗?

python terminal ffmpeg popen pandas

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

ffmpeg 返回“frame_pts”作为无法识别的选项

今天早些时候,我发布了一个关于按编码顺序使用关键帧进行帧提取的问题(此处),我尝试运行答案之一中提供的命令,但 ffmpeg 返回:

Unrecognized option 'frame_pts'.
Run Code Online (Sandbox Code Playgroud)

分割参数列表时出错:未找到选项

有任何线索如何使 ffmpeg 识别“frame_pts”选项吗?我运行的完整命令是:

ffmpeg -i input.mp4 "select='eq(pict_type\,I)" -vsync 0 -frame_pts 1 thumbnails-%02d-I.png
Run Code Online (Sandbox Code Playgroud)

ffmpeg video-encoding keyframe video-compression

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

欧几里得距离的矢量化实现

我正在尝试计算欧几里得距离的矢量化实现(使用内积在 X 和 Y 中的每个元素之间)。数据如下:

X = np.random.uniform(low=0, high=1, size=(10000, 5))
Y = np.random.uniform(low=0, high=1, size=(10000, 5))
Run Code Online (Sandbox Code Playgroud)

我所做的是:

euclidean_distances_vectorized = np.array(np.sqrt(np.sum(X**2, axis=1) - 2 * np.dot(X, Y.T) + np.sum(Y**2, axis=1)))
Run Code Online (Sandbox Code Playgroud)

尽管这给出了“一些输出”,但答案是错误的,因为每行仍然包含 5 个元素。

有谁知道我做错了什么?

python numpy vectorization euclidean-distance

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

使用scikit-image将RGB图像转换为LAB

我正在尝试使用skimage将RGB图像转换为LAB颜色空间,但结果似乎只是噪音.使用opencv的相同操作似乎有效.

cat = io.imread('https://poopr.org/images/2017/08/22/91615172-find-a-lump-on-cats-skin-632x475.jpg')
cat_sk_image_lab = skimage.color.rgb2lab(cat)
plt.imshow(cat_sk_image_lab)
cat_cv_lab = cv2.cvtColor(cat, cv2.COLOR_BGR2LAB)
plt.imshow(cat_cv_lab)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

python scikit-image

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

Getting infinite loop when reading file from method

I am trying to refactor my code, and adding methods where possible. When I read a file from a method and return the result of the computation, the code goes into extreme memory consumption, infinite loop.

My modification looks like this:

import java.util.Scanner;

public class NumberOfLines {
    public static int compute () {
        // read this file
        String theFile = "numbers.txt";

        Scanner fileRead = null;

        if (NumberOfLines.class.getResourceAsStream(theFile) != null) {
            fileRead = new Scanner(NumberOfLines.class.getResourceAsStream(theFile));
        }           
        else {
            System.out.print("The file " …
Run Code Online (Sandbox Code Playgroud)

java methods file infinite-loop java.util.scanner

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

在Perl中动态存储变量

我试图在Perl中动态存储和打印变量,方法是要求用户输入要创建的变量数,然后要求每个创建的变量添加信息,然后输出每个变量中包含的文本长度.在我脑海里,我想出了这个:

use strict;
use warnings;

sub main {

    my %VarStore = ();

    print ("How many variables to create: ");
    chomp(my $varNum = <STDIN>);

    my $counter = 1
    while ($counter <= $varNum) {
        print "Enter text to variable $counter: \n";
        chomp(my $buffer = <STDIN>);
        $VarStore{'var'$counter} = $buffer;
        $counter ++;
    }

    while ($counter <= $varNum) {
        print "Variable $counter is length($VarStore{'var'$counter}) character  long \n";
        $counter ++;
    }


}
Run Code Online (Sandbox Code Playgroud)

我想要的是:

> How many variables to create: 3
> Enter text to variable 1: …
Run Code Online (Sandbox Code Playgroud)

perl

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

将字符串作为数组传递给子例程并返回特定字符的计数

我试图以正确的方式思考解决这个问题: - 我会将说明,n个元素数组作为参数传递给子程序.并且为每个元素匹配两个char类型ST并为每个元素打印,这些字母的计数.到目前为止,我做了这个,但我被锁定,并在我的代码中发现了一些无限循环.

用严格; 使用警告;

sub main {

my @array = @_;

while (@array) {
    my $s = ($_ = tr/S//);
    my $t = ($_ = tr/T//);
    print "ST are in total $s + $t\n";
    }
}

my @bunchOfdata = ("QQQRRRRSCCTTTS", "ZZZSTTKQSST", "ZBQLDKSSSS");
main(@bunchOfdata);
Run Code Online (Sandbox Code Playgroud)

我希望输出为:

Element 1 Counts of ST = 5
Element 2 Counts of ST = 6
Element 3 Counts of ST = 4
Run Code Online (Sandbox Code Playgroud)

任何线索如何解决这个问题?

perl

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

追加列表的累积列表 python

我正在尝试以如下方式扩展列表列表:

# Consider the following list of lists
l_Of_l = [ [1], [2], [3], [4], [5], [6], [7]]
Run Code Online (Sandbox Code Playgroud)

期望的结果是:

l_extended = [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6, 7]]
Run Code Online (Sandbox Code Playgroud)

所以基本上列表的大小在累积扩展后保持不变。

编辑:

这是我最初所做的:

l_Of_l = [ [1], [2], [3], [4], [5], [6], [7]]
lista = []
for i in l_Of_l:
    lista.extend(i)
    print(list([i for i in lista]))
Run Code Online (Sandbox Code Playgroud)

但后来的结果是:

[1]
[1, 2] …
Run Code Online (Sandbox Code Playgroud)

python list extend

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