Python3 - 无法根据对象检测过程的输入正确启动输出设备

Python3 - Fail to actuate output device properly based on input from object detection process

首先,我在这个post的最后附上了我的项目的一些一般规格。

我项目的主要objective是通过摄像头视觉检测口罩的使用情况,然后相应地执行某些操作。例如,如果检测到有人没有戴口罩,蜂鸣器会开始持续嗡嗡作响,红色LED开始闪烁,闸机不会打开。

到目前为止,我设法实现了对象检测过程,它能够充分检测到面罩的使用。对象检测过程应该 运行 在无限循环中连续进行,没有任何延迟,并且会停止,直到我按下特定的键。

问题 是当我尝试在同一个循环中合并驱动过程的延迟时,例如闪烁的 LED。由于延迟,对象检测过程的视频流冻结。

因此,我尝试了一些方法来确保输出驱动过程不会中断对象检测过程,例如通过实现多处理以及 pickle 文件作为缓冲存储器存储对象检测产生的信息过程。但是,我还是没能解决这个问题。我对 writing/reading 同时来自两个不同进程的 pickle 文件有疑问。

流程要求如下。

Process 1 (Main Process)

  • In an infinite loop
  • No delays, speed of the iteration is limited by the hardware and the OS
  • Able to write output signal as soon as it detect the face mask

Process 2 (Secondary Process)

  • Start to run the program once received signal from the main process
  • Able to read output signal from the main process
  • Able to operate with delays without interrupting the main process
  • Able to delete/edit the output signal from the main process
  • Killed once the main process is terminated

因此,我想知道是否有任何 method/library/function 能够同时独立地 运行 两个具有不同时序的进程,并且能够 retrieve/transfer 这些进程中的信息。如果有必要分享我的代码,请告诉我。

谢谢。

我的项目的一般规格:

在阅读和搜索有关多处理的更多信息后,我设法找到了对我的项目有用的东西,它是“使用服务器进程共享数据”和“进程同步”的方法,有关此功能的更多详细信息,您可以参考下面的 YouTube 视频。强烈建议您观看完整的播放列表,以便您对多处理有更广泛的了解,从而简化您的工作。

Sharing data using server process https://youtu.be/v5u5zSYKhFs

Process synchronization https://youtu.be/-zJ1x2QHTKE

这两种方法都成功解决了我的问题,我认为我之前的问题是由于两个进程同时写入和读取 pickle 文件的问题引起的。