- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在寻找用于运动计时的线扫描相机的替代品,或者更确切地说,用于需要确定位置的部分。我发现普通工业相机可以轻松达到每秒 1000 帧以上的商用相机解决方案的速度。就我的需要而言,通常计时的准确性并不重要,重要的是运动员的相对位置。为此,我想我可以使用最便宜的 Basler、IDS 或任何其他区域扫描工业相机之一。当然,有些线扫描相机的速度远不止几千 fps(或 hz),但也有可能以不到 500 欧元的价格获得能够达到所需的 1000-3000fps 速度的面扫描相机。
我的 chalice 当然是 FinishLynx(或任何其他线扫描系统)的近实时图像合成功能,基本上是这一部分:https://youtu.be/7CWZvFcwSEk?t=23s
我考虑替代方案的整个过程是:
- Use Basler Pylon Viewer (or other software) to record 2px wide images at the camera’s fastest read speed. For the camera I am currently using it means it has to be turned on it’s side and the height needs to be reduced, since it is the only way it will read 1920x2px frames @ >250fps
- Make a program or batch script that then stitches these 1920x2px frames together to, for example one second of recording 1000*1920x2px frames, meaning a resulting image with a resolution of 1920x2000px (Horizontal x Vertical).
- Finally using the same program or another way, just rotate the image so it reflects how the camera is positioned, thus achieving an image with a resolution of 2000x1920px (again Horizontal x Vertical)
- Open the image in an analyzing program (currently ImageJ) to quickly analyze results
我不是程序员,但这是我能够使用批处理脚本组合在一起的,当然是在 stackoverflow 的帮助下。
- Currently recording a whole 10 seconds for example to disk as a raw/mjpeg(avi/mkv) stream can be done in real time.
- Recording individual frames as TIFF or BMP, or using FFMPEG to save them as PNG or JPG takes ~20-60 seconds The appending and rotation then takes a further ~45-60 seconds This all needs to be achieved in less than 60 seconds for 10 seconds of footage(1000-3000fps @ 10s = 10000-30000 frames) , thus why I need something faster.
我能够弄清楚如何使用 ImageMagick 非常高效:
magick convert -limit file 16384 -limit memory 8GiB -interlace Plane -quality 85 -append +rotate 270 “%folder%\Basler*.Tiff” “%out%”
#%out% has a .jpg -filename that is dynamically made from folder name and number of frames.
此命令有效并在 i5-2520m 上让我在大约 30 秒内编码了 10000 帧(虽然大多数处理似乎只使用一个线程,因为它以 25% 的 cpu 使用率工作)。这是生成的图像:https://i.imgur.com/OD4RqL7.jpg (19686x1928px)
然而,由于使用 Basler 的 Pylon Viewer 记录到 TIFF 帧所花的时间比记录 MJPEG 视频流要长得多,所以我想使用 MJPEG (avi/mkv) 文件作为附加源。我注意到 FFMPEG 有“image2pipe”-command,它应该能够直接将图像提供给 ImageMagick。虽然我无法让这个工作:
$ ffmpeg.exe -threads 4 -y -i "Basler acA1920-155uc (21644989)_20180930_043754312.avi" -f image2pipe - | convert - -interlace Plane -quality 85 -append +rotate 270 "%out%" >> log.txt
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: –enable-gpl –enable-version3 –enable-sdl2 –enable-bzlib –enable-fontconfig –enable-gnutls –enable-iconv –enable-libass –enable-libbluray –enable-libfreetype –enable-libmp3lame –enable-libopenjpeg –enable-libopus –enable-libshine –enable-libsnappy –enable-libsoxr –enable-libtheora –enable-libtwolame –enable-libvpx –enable-libwavpack –enable-libwebp –enable-libx264 –enable-libx265 –enable-libxml2 –enable-libzimg –enable-lzma –enable-zlib –enable-gmp –enable-libvidstab –enable-libvorbis –enable-cuda –enable-cuvid –enable-d3d11va –enable-nvenc –enable-dxva2 –enable-avisynth –enable-libmfx
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Invalid Parameter - -interlace
[mjpeg @ 000000000046b0a0] EOI missing, emulating
Input #0, avi, from 'Basler acA1920-155uc (21644989)_20180930_043754312.avi’:
Duration: 00:00:50.02, start: 0.000000, bitrate: 1356 kb/s
Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj422p(pc, bt470bg/unknown/unknown), 1920x2, 1318 kb/s, 200 fps, 200 tbr, 200 tbn, 200 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> mjpeg (native))
Press [q] to stop, [?] for help
Output #0, image2pipe, to ‘pipe:’:
Metadata:
encoder : Lavf57.83.100
Stream #0:0: Video: mjpeg, yuvj422p(pc), 1920x2, q=2-31, 200 kb/s, 200 fps, 200 tbn, 200 tbc
Metadata:
encoder : Lavc57.107.100 mjpeg
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
av_interleaved_write_frame(): Invalid argument
Error writing trailer of pipe:: Invalid argument
frame= 1 fps=0.0 q=1.6 Lsize= 0kB time=00:00:00.01 bitrate= 358.4kbits/s speed=0.625x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
Conversion failed!
如果我的高度再高一点,我就不会再收到“[mjpeg @ 000000000046b0a0] EOI 丢失,正在模拟”错误。然而,整个事情只适用于 <2px 高/宽镜头。
编辑:哦,是的,我也可以使用 ffmpeg -i file.mpg -r 1/1 $filename%03d.bmp
或 ffmpeg -i file.mpg $filename%03d .bmp
从 MJPEG/RAW 流中提取所有帧。但是,这是我不想采取的额外步骤。 (仅仅删除一个30000 jpgs的文件夹就需要2分钟......)
有人能想到管道方法的工作解决方案或完全不同的替代方法来处理这个问题吗?
最佳答案
我又做了一次尝试,看看我是否可以通过几种不同的方式来加快我的另一个答案——因此得到了一个不同的答案。我使用了我在另一个答案中生成的相同合成视频片段进行测试。
我没有将 2x1920 扫描线传递到 ImageMagick 以将其附加在一起并写入为 JPEG,而是执行了以下操作:
在 C++ 程序中预先创建了完整的输出帧,然后在每次迭代中循环读取 2x1920 扫描线并将其填充到输出帧中的正确位置,并且
读取整个序列后,使用 turbo-jpeg 将其压缩为 JPEG 并将其写入磁盘。
因此,不再需要 ImageMagick。整个程序现在运行大约 1.3 秒,而不是通过 ImageMagick 的 10.3 秒。
代码如下:
////////////////////////////////////////////////////////////////////////////////
// stitch.cpp
// Mark Setchell
//
// Read 2x1920 RGB frames from `ffmpeg` and stitch into 20000x1920 RGB image.
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <unistd.h>
#include <turbojpeg.h>
using namespace std;
int main()
{
int frames = 10000;
int height = 1920;
int width = frames *2;
// Buffer in which to assemble complete output image (RGB), e.g. 20000x1920
unsigned char *img = new unsigned char [width*height*3];
// Buffer for one scanline image 1920x2 (RGB)
unsigned char *scanline = new unsigned char[2*height*3];
// Output column
int ocol=0;
// Read frames from `ffmpeg` fed into us like this:
// ffmpeg -threads 4 -y -i video.mov -frames 10000 -vf "transpose=1" -f image2pipe -vcodec rawvideo -pix_fmt rgb24 - | ./stitch
for(int f=0;f<10000;f++){
// Read one scanline from stdin, i.e. 2x1920 RGB image...
ssize_t bytesread = read(STDIN_FILENO, scanline, 2*height*3);
// ... and place into finished frame
// ip is pointer to input image
unsigned char *ip = scanline;
for(int row=0;row<height;row++){
unsigned char *op = &(img[(row*width*3)+3*ocol]);
// Copy 2 RGB pixels from scanline to output image
*op++ = *ip++; // red
*op++ = *ip++; // green
*op++ = *ip++; // blue
*op++ = *ip++; // red
*op++ = *ip++; // green
*op++ = *ip++; // blue
}
ocol += 2;
}
// Now encode to JPEG with turbo-jpeg
const int JPEG_QUALITY = 75;
long unsigned int jpegSize = 0;
unsigned char* compressedImage = NULL;
tjhandle _jpegCompressor = tjInitCompress();
// Compress in memory
tjCompress2(_jpegCompressor, img, width, 0, height, TJPF_RGB,
&compressedImage, &jpegSize, TJSAMP_444, JPEG_QUALITY,
TJFLAG_FASTDCT);
// Clean up
tjDestroy(_jpegCompressor);
// And write to disk
ofstream f("result.jpg", ios::out | ios::binary);
f.write (reinterpret_cast<char*>(compressedImage), jpegSize);
}
注意事项:
注意 1: 为了预先分配输出图像,程序需要提前知道有多少帧到来——我没有参数化它,我只是硬编码了 10,000 但它应该很容易改变。
确定视频序列中帧数的一种方法是:
ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 video.mov
注意 2:请注意,我使用几个开关编译代码以提高性能:
g++-8 -O3 -march=native stitch.cpp -o stitch
注意 3:如果您在 Windows 上运行,您可能需要在执行以下操作之前以二进制模式重新打开 stdin
:
read(STDIN_FILENO...)
注意 4: 如果您不想使用 turbo-jpeg,您可以在主循环结束后删除所有内容,并简单地发送一个 NetPBM。 PPM
图像通过管道传输到 ImageMagick 并让它执行 JPEG 写入。这看起来非常粗略:
writeToStdout("P6 20000 1920 255\n");
writeToStdout(img, width*height*3);
然后你会运行:
ffmpeg ... | ./stitch | magick ppm:- result.jpg
关于ffmpeg - 使用 ImageMagick 高效拼接线扫描图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52580770/
.splice() 方法的基本问题,以及如何最好地从数组中删除元素。 我想使用 .splice() 从数组中删除一个项目,但是当我这样做时,我希望返回原始数组 减去 删除的元素。 .splice()
我正在过滤同位素库。单击按钮会添加到称为过滤器的数组中。这是正常工作的,但是当用户单击事件按钮时,我希望从数组中删除过滤的类别。由于某种原因,事实并非如此。 这是特定的代码: if($(this).h
几个月前,我将一个 Subversion 存储库转换为 Mercurial,结果在我的修订历史中留下了两个毫无意义的空白。我试图弄清楚我是否可以拼接间隙,但我一直无法让工具精确地完成我想要的。 在项目
我制作简单的射击游戏,但有一个问题(有时): GIF Game problem 3颗子弹被移除(但只有一颗子弹相撞)。子弹和敌人(蓝色方 block )位于一个数组中(var objects = []
假设我们在 JavaScript 中有两个数组,[3,4,7] 和 [5,6]。 在不排序或使用 .apply 的情况下,将 [5,6] 插入索引 2 处的 [3,4,7] 的最佳方式是什么实现结果数
我试图在从数组中删除项目时添加纸质警报对话框,但我似乎无法理解这是如何工作的。 我现在可以使用以下功能,无需对话框: _delete(e) { var index = this.t
我正在尝试使用 splice() 从 jQuery 对象中删除元素. 但是,最终发生的情况是所有其他项目都被删除。我假设这是由于使用 splice 重新索引造成的。 我要淡入每个 所以我需要从顶部开始
这是我尝试从数组中动态删除一个值的尝试 $('.btn-remove').click(function() { var players = ["compare","13076","13075"
我正在考虑在 Visual Studio 2008 上使用 OpenCV 2.3.1 实时拼接来自 2 个或更多(目前可能是 3 或 4 个)摄像头的图像。 但是,我很好奇它是如何完成的。 最近研究了
我在将两个数组拼接在一起时遇到问题。假设我有两个数组: a = array([1,2,3]) b = array([4,5,6]) 当我执行 vstack((a,b)) 时,我得到了 [[1,2,3]
我拼接 css 文件以提高性能。 现在我想包含一个 minify 函数,如下所示。我该如何合并它? function minify( $css ) { $css = preg_replace(
我有两个 matlab 向量。第一个有 N 个元素,另一个有 k*N。我知道 k 是什么,我想拼接列表,使第一个向量中的每个元素出现在下一个向量中相应的 k 元素之前。例如: k = 3 x = [1
我有以下上下文: https://jsfiddle.net/eqntaqbt/2/ obj.forEach(function(user, index){ var userName = user
假设你有一个像这样的数组: var arr= [{id:121, v:'a'}, {id:232, 'b'}]; 你需要找到 id: 232 并删除它,所以你可以这样做: for (var i = a
似乎是通过 建立报价语法非常低效。例如创建一个整数列表 let q1 = List.foldBack (fun n acc -> ) [1..100000] Real: 00:00:05.714,
我正在为一家希望为其用户创建服务的公司开发应用程序。该公司目前提供时长约为 1.5 小时的视频,他们想要集成的服务是让用户能够“录制”这个较大视频的剪辑,以创建本质上的精彩片段。此服务的最终结果将是
splice 当 OFFSET 在数组中但 LENGTH 的末尾超过数组末尾时,是否可以? 最佳答案 易于尝试。 $ perl -wE' my @a = "a".."e"; my @b =
以前从未使用过 Tkinter,我不太确定如何使用它或它是如何工作的。 Windows IDLE Shell。 import time from tkinter import * input("Pre
这里是 Javascript 新手 -- 我有以下数组: var group = ({ one: value1, two: value2, three:
我的屏幕上打印了以下行: Would you like to pay €xx to POS_ID Latte X 1....€2.50-Salad X 1....€4.00-Wrap X 1..
我是一名优秀的程序员,十分优秀!