简体   繁体   English

多线程:如何在wxthread中使GUI线程无图像显示和工作线程处理图像同步

[英]Multithreading: how to make GUI thread for showing image non-blocking and worker thread for processing image synchronization in wxthread

I am getting started with the wxThread. 我开始使用wxThread。

I have shown the video in the GUI thread with wxWidgets. 我已经使用wxWidgets在GUI线程中显示了视频。 And now I want to handle each frame with opencv like drawing one circle in each frame. 现在我想用opencv处理每一帧,就像在每一帧中画一个圆一样。 At the beginning, I have done the processing in the GUI thread. 开始时,我已经在GUI线程中完成了处理。 But when I run the program, I find that the image in the GUI isnot shown continuously and some image doesnot include the circle. 但是,当我运行该程序时,发现GUI中的图像没有连续显示,并且某些图像不包含圆圈。

I have realized that image processing part is not put into the GUI thread. 我已经意识到图像处理部分没有放入GUI线程中。 I should creat a new thread to complete the image processing part. 我应该创建一个新线程来完成图像处理部分。

But I don't know how to how to make GUI thread and worker thread synchronization, it means that it can make the GUI thread non-blocking and the worker thread process the frame with opencv. 但是我不知道如何使GUI线程和工作线程同步,这意味着它可以使GUI线程无阻塞,并且工作线程使用opencv处理帧。 Although I konw the wxthread tutorial, I couldnot deal with the problem about how to share the data between the two wxThread. 尽管我了解wxthread教程,但是我无法处理有关如何在两个wxThread之间共享数据的问题。

Could anyone have some ideas about it or some reference? 有人能对此有一些想法或参考吗? Thx. 谢谢。

There is a pretty extensive section on thread synchronization in the wx-wiki https://wiki.wxwidgets.org/Inter-Thread_and_Inter-Process_communication 在wx-wiki https://wiki.wxwidgets.org/Inter-Thread_and_Inter-Process_communication中有关于线程同步的相当广泛的部分

For background-tasks I like to use the "post event to main thread" approach This might also work for you. 对于后台任务,我喜欢使用“将事件发布到主线程”方法,这也可能对您有用。 - Send an event whenever your work-thread is done with the processing of a single image and display the image in the event-handler method -只要您的工作线程完成了单个图像的处理,就发送一个事件,并在事件处理程序方法中显示该图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM