对于多线程视频教练程序来说,这是否是一个体面的结构? [英] Is this a decent structure for a multithreaded videocoacher program?

查看:83
本文介绍了对于多线程视频教练程序来说,这是否是一个体面的结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我目前正在从事一个视频教练程序的项目,该程序用于记录和重播视频,以及显示延迟的实时视频,并通过颜色跟踪放置.

Hi I’m currently working on a project for a videocoacher program for recording and replaying video, as well as showing delayed real-time video, and tracking placement via color.

该软件在linux上,在4核odroid上运行,最初,我开始使它成为多线程的,并且每个新类都实现了线程.这些线程中的每一个都照顾自己的gui元素.

The software is running on linux , on a 4 core odroid, and initially I started to make it multi threaded with threads implemented as a part of each new class. Each of these threads taking care of their own gui elements.

我后来发现我需要在main/gui线程中显示所有gui元素/视频.之前我使用过opencv和boost.但是似乎使用Qt可能是一个更好的主意,因为某些代码已经依赖于QT库.我目前是编程的新手,对opencv,qt或线程不太熟悉.

I’ve later found out that I need to show all gui elements/video in the main/gui thread. Earlier I’ve used opencv and boost. But it seems like using the Qt might be a better idea since some of the code already depends on the QT library. I am currently a novice at programming, and not very familiar with either opencv, qt, or threading.

我的问题是: 作为程序的结构,这相对来说是合理的吗?还是我现在打算如何做固有的错误?

My question is: Is this relatively sound as a structure for the program, or is there something inherently wrong with how I am planning to do it now?

主/GUI线程

  • 将显示所有视觉和视频内容
  • 将为 ButtonControl 对象
  • 启动线程
  • will show all visual & video content
  • will start a thread for ButtonControl object

ButtonControl

  • 将处理所有按钮输入,控制程序中发生的事情
  • 根据所按下的按钮将开始和结束线程 像:
  • StoreToFile 对象(开始将视频存储到文件,同时发送 视频流到 GUI线程,以实时显示其存储的内容
  • ReadFromFile 对象(读取当前存储的文件并发送数据 在 GUI线程
  • 中显示它
  • DelayedVideoStream 对象(将视频存储到缓冲区,并显示一个 持续延迟查看过去5秒内发生的事情)
  • ColorTracking 对象(跟踪图像中颜色位置的位置 )
  • will handle all button input, controlling what happens in the program
  • depending on what buttons are pressed will start and end threads like:
  • StoreToFile object ( starts storing video to a file, while sending a video stream to GUI thread to show what it is storing in real-time)
  • ReadFromFile object ( reads the file currently stored and sends data to display it in GUI thread
  • DelayedVideoStream object (stores video to buffer, and shows a continuous delayed view of what happened 5seconds in the past)
  • ColorTracking object (tracks where a color placement is in the image )

致以诚挚的问候,谢谢您抽出宝贵的时间来研究我的问题.

Kind regards, and thank you for taking the time to look at my question.

TLDR-是一种将线程实现为类并将图像数据发送回gui/主线程的一种结构,该方法可以完成多线程程序?

推荐答案

在性能方面,最好的方法是根本不直接处理线程,而是使用QtConcurrent::run.绘制QImages是安全的,只需通过信号将其传递给GUI对象即可显示.我写了一个完整的示例来演示这种方法.由于相关的代码相邻,因此它导致了一些非常简洁和易于理解的代码.

Performance-wise, the best approach is not to deal with threads directly at all, but use QtConcurrent::run. It is safe to paint QImages that are simply passed via signals to a GUI object to display. I wrote a complete example demonstrating that approach. It leads to some very concise and easy-to-understand code thanks to related code being adjacent.

如果您确实想使用显式线程,则不从QThread派生,而是将各种辅助对象简单地移动到它们的线程中,并使它们通过信号和插槽进行通信将更加容易.对于该方法,我也有完整的示例.

If you do want to use explicit threads, it will be much easier not to derive from QThread, but to simply move various worker objects into their threads, and have them communicate via signals and slots. I have a complete example for that approach as well.

这篇关于对于多线程视频教练程序来说,这是否是一个体面的结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆