RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

问题[очередь]

Martin Hope
goshanoob
Asked: 2022-08-16 11:42:13 +0000 UTC

在处理期间更改队列长度

  • 0

我有一个图像显示队列。我从队列中取出一张图像,显示它,等待两秒钟,然后拍摄下一张。但是,队列充满了来自外部的事件,因此可以在处理其他项目时将项目添加到其中。在我的代码中,调用 ShowImage() 方法会创建一个并行循环,因此图像不会延迟。我怎么解决这个问题?

// Метод вызывается по событию.
private void AddImageToSchedule(int imgNumber)
 {
     switch (imgNumber)
     {
     case 1:
         _schedule.Enqueue(_images[ImagesNames.FirstBlood]);
         break;

     case 2:
         _schedule.Enqueue(_images[ImagesNames.DoubleKill]);
         break;

     case 3:
         _schedule.Enqueue(_images[ImagesNames.TripleKill]);
         break;

     case 4:
         _schedule.Enqueue(_images[ImagesNames.UltraKill]);
         break;

     case 5:
         _schedule.Enqueue(_images[ImagesNames.Riot]);
         break;
 }
 
 ShowImage();
}

private async void ShowImage()
{
 while (_schedule.Count != 0)
 {
     var img = _schedule.Dequeue();
     _ui.ShowImage(img);
     await Task.Delay(SHOW_TIME);
 }
}
c# очередь
  • 1 个回答
  • 22 Views
Martin Hope
Gawain
Asked: 2022-07-22 17:08:39 +0000 UTC

线程与队列一起工作不正确

  • 1

我正在尝试在单独的线程中从相机录制视频而不加载主进程。为此,我实现了 Recorder 类,但它并不总是有效。有时视频坏了,有时程序只是“起床”。我认为错误在连接中的某个地方,但我不能完全理解

# recorder.py

import queue
import threading
from typing import Tuple

import cv2


class Recorder(threading.Thread):
    def __init__(self, output_path: str,
                 fourcc: str = 'mp4v',
                 fps: float = 30,
                 resolution: Tuple[int, int] = (1920, 1080),
                 record_in_background: bool = True):
        super(Recorder, self).__init__(daemon=record_in_background)

        self.resolution = resolution

        self.writer = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*fourcc),
                                      fps, self.resolution)

        self.frames_queue = queue.Queue()

        self.recording = False

    def __del__(self):
        self.frames_queue.join()

        self.writer.release()

    def write(self, frame):
        self.frames_queue.put(frame)

    def start(self):
        super().start()
        return self

    def run(self):
        self.recording = True
        while self.recording or not self.frames_queue.empty():
            frame = self.frames_queue.get()

            resized_frame = cv2.resize(frame, self.resolution)

            self.writer.write(resized_frame)

            self.frames_queue.task_done()

    def stop(self):
        self.recording = False

        self.join()



# main.py

import cv2

import recoder

cam = cv2.VideoCapture(0)
r = recoder.Recorder("123.mp4", resolution=(640, 480))
r.start()

while True:
    ret, frame = cam.read()

    if not ret:
        break

    r.write(frame)

    cv2.imshow("frame", frame)
    cv2.waitKey(1)

    if cv2.waitKey(25) == ord('q'):
        break

cv2.destroyAllWindows()
cam.release()
r.stop()

python очередь
  • 1 个回答
  • 31 Views
Martin Hope
asianirish
Asked: 2020-06-17 22:04:49 +0000 UTC

基于 Seq(Data.Sequence) 的队列模式匹配

  • -1

创建基于以下的队列类型Seq:

import Data.Sequence

type Queue v = Seq v

现在我想编写一个返回队列第一个元素(“头”)的函数。从我阅读和谷歌搜索的所有内容看来,应该是这样的:

qhead :: Queue v -> v
qhead Empty = error "empty sequence"
qhead (x :<| xs) = x

赛皮特:

不在范围内:数据构造函数 ':<|'

好的,我是这样做的:

qhead' :: ViewL v -> v
qhead' EmptyL = error "empty sequence"
qhead' (x :< xs) = x

qhead :: Queue v -> v
qhead q = qhead' $ viewl q

但也许可以做一些更笨拙的事情?直接用typeQueue来比较,不介意一些笨蛋ViewL吗?还是这么犹太?

完整代码:

import Data.Sequence

type Queue v = Seq v

qhead' :: ViewL v -> v
qhead' EmptyL = error "empty sequence"
qhead' (x :< xs) = x

qhead :: Queue v -> v
qhead q = qhead' $ viewl q

{-
*R.QTree> qhead $ fromList [12,13,14,15]
12
-}
очередь
  • 1 个回答
  • 10 Views
Martin Hope
asianirish
Asked: 2020-06-14 20:41:19 +0000 UTC

Haskell 中的快速 FIFO 实现?

  • 1

标准列表 ( [a]) 允许您在列表末尾快速插入并从列表末尾快速删除。

假设我们可以push为它创建一个“类似列表”的类型和一个函数,以保持“快速”添加的第一个元素可用,以便我们可以有效地循环从最旧到最新的队列:

data Queue a = Empty | Element a (Queue a)

push :: a -> Queue a -> Queue a
push a Empty             = Element a Empty
push a (Value b pointer) = Element b (push a pointer)

但是有一个明显的缺点——添加一个新元素时,它会递归地“深入”到队列中,即随着队列的增长,新添加的速度会越来越慢。

本质上,这是一个问题——如何在 Haskell 中实现一个容器FIFO,以便您可以快速添加一个新元素并快速从中读取,从旧元素开始?

очередь
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5