简体   繁体   English

C ++多线程数据管理

[英]C++ multi-threaded data management

I am looking for conceptual advice regarding managing a large quantity of data in a computer vision project of mine. 我正在寻找有关在我的计算机视觉项目中管理大量数据的概念性建议。 I am having trouble a) conceptualizing and b) implementing a concept of coordinating this large stream of data coming both as input to the program from the cameras and generated by the code. 我遇到麻烦a)概念化和b)实施一个概念,以协调来自摄像机的程序输入和代码生成的大量数据流。

So the data I have to get a handle on is separable into five separate 'streams' as I'll call them: 因此,我需要处理的数据可分为五个单独的“流”,我将它们称为:

Raw frames (direct input from camera) Target images (sub-frames, taken from the previous image stream) Timestamps (for the raw frames) Vehicle attitude data (GPS, body angles, etc. from a wireless serial port connection to the vehicle) Attitude data timestamps 原始帧(来自摄像机的直接输入)目标图像(子帧,取自前一个图像流)时间戳(用于原始帧)车辆姿态数据(从无线串行端口连接到车辆的GPS,车身角度等)姿态数据时间戳

The general flow, if we were to do this completely sequentially, would be: 如果我们要完全按顺序执行此操作,则一般流程为:

Frame = grabInputFrame();
TargetsVector = searchForTargets(Frame);
VehicleData = getDataFromVehicle();

for each Target in TargetVector (
    targetData = processData(Target, VehicleData);
    updateTargetLog(targetData);
}

So here's the deal: I'm trying to do this by means of threads, since the algorithms are very processor intensive and not sequentially related (I mean that I don't need the color data to get the GPS coords of the target). 所以这是要解决的问题:我正在尝试通过线程来执行此操作,因为算法占用大量处理器,并且不顺序相关(我的意思是我不需要颜色数据来获取目标的GPS坐标)。 BUT, I do need to coordinate images with targets and timestamps with those images, so I can use the right vehicle data for the right image, etc. 但是,我确实需要将具有目标的图像与带有这些图像的时间戳进行协调,因此我可以为正确的图像使用正确的车辆数据,等等。

A friend of mine suggested a relational DB approach, but I'm using C++. 我的一个朋友建议使用关系数据库方法,但是我正在使用C ++。 What I wonder is, is there a way to mimic relational DBs in C++ (having keys associate with data, like a timestamp or target ID associate to the data or target image)? 我想知道的是,是否有一种方法可以模仿C ++中的关系数据库(具有与数据相关联的键,例如与数据或目标图像相关联的时间戳或目标ID)? Would connecting to a SQL DB make this easier to manage? 连接到SQL DB会使它更易于管理吗? Is there a significant performance penalty associated with doing so? 这样做是否会严重影响性能? The most important point here is that whatever I do, I have to be able to lock the shared data so I can multi-thread it safely. 这里最重要的一点是,无论我做什么,我都必须能够锁定共享数据,以便可以安全地对其进行多线程处理。

I hope that someone with some experience in hierarchical data structures like this can shed some light on my situation. 我希望对这种分层数据结构有一定经验的人能对我的情况有所了解。 I thank you in advance for your ideas and criticisms. 我预先感谢您的想法和批评。

OpenMP may be helpful for such a problem, there are inbuilt functions provided for locks and atomic operations. OpenMP可能会对此类问题有所帮助,其中提供了用于锁定和原子操作的内置函数。 Since you have 5 parallel operations, you can create 5 threads and based on the threadId, perform different operations. 由于您有5个并行操作,因此可以创建5个线程,并基于threadId执行不同的操作。

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

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