- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我实现了一个对图像进行计算的类。一次对给定图像的一个子集(比如 1000 张中的 100 张)进行处理,每张图像需要不同次数的迭代才能完成。处理使用 GPU,因此不可能一次使用所有图像。图像处理完成后,将删除该图像并添加另一个图像。所以我使用了三个不同的 vector image_outcome
, image_index
, image_operation
保存有关图像的信息:
image_outcome
是 std::vector<float>
它的每个元素都是一个值,用作决定图像何时完成的标准。image_index
是 std::vector<int>
保存原始数据集中图像的索引。image_operation
是 std::vector<MyEnumValue>
包含用于更新 image_outcome
的操作.属于 enum
类型及其值是许多可能的操作之一。还有两个功能,一个是删除完成的图像,一个是添加与删除的图像一样多的图像(如果输入中还有足够的图像)。
remove_images()
函数获取所有三个矩阵和图像矩阵,并使用 std::vector.erase()
删除元素.add_images()
再次采用三个矩阵,图像矩阵将新图像和相关信息添加到 vector 中。因为我使用的是 erase()
在具有相同索引(以及类似的添加方式)的每个 vector 上,我正在考虑:
struct
具有三个 vector (嵌套结构)。class
这是使用三个 vector (嵌套类)实现的。代码的高级示例可以在下面找到:
class ComputationClass {
public:
// the constructor initializes the member variables
ComputationClass();
void computation_algorithm(std::vector<cv::Mat> images);
private:
// member variables which define the algorithms parameters
// add_images() and remove_images() functions take more than these
// arguments, but I only show the relevant here
add_images(std::vector<float>&, std::vector<int>&, std::vector<MyEnumValue>&);
remove_images(std::vector<float>&, std::vector<int>&, std::vector<MyEnumValue>&);
};
void ComputationClass::computation_algorithm(std::vector<cv::Mat> images) {
std::vector<float> image_output;
std::vector<int> image_index;
std::vector<MyEnumValue> image_operation;
add_images(image_output, image_index, image_operation);
while (there_are_still_images_to_process) {
// make computations by updating the image_output vector
// check which images finished computing
remove_images(image_output, image_index, image_operation);
add_images(image_output, image_index, image_operation);
}
}
最佳答案
我认为,与具有 3 个 vector 的结构相比,用户定义对象的单个 vector 会更好。
std::vector<MyImage> images;
class MyImage {
Image OImage; // the actual image
float fOutcome;
int dIndex;
MyEnumValue eOperation;
bool getIsDone() {
return fOutcome > 0; // random condition
}
}
你可以添加到 vector 或从 vector 中删除一个条件
if( (*it).getIsDone() ) {
VMyVector.erase( it );
}
在我看来,保持 3 个并行的 vector 很容易出错并且很难修改。
关于c++ - 首选哪种数据结构而不是操纵多个 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39079122/
有谁知道如何使 DIV 的行为方式使其始终尝试占用其最大空间(无论内容如何)? 例如,如果我有一个 max-height 的 DIV的 600px和一个 min-height的 200px ,我怎样才
考虑两个表表A和表B 表A |id|driver_id|vehicle_id|is_allowed|license_number|driver_name| 表B |id|driver_id|vehic
对于 ASP.NET 应用程序,自定义脏话删除器/替换器的最佳实践实现方法是什么? 如果这是一个数据表解决方案,是否有免费的资源来获取数据? (类似于找到可以导入到系统中进行拼写检查的公共(publi
有很多 jquery 工具提示插件。 我应该使用哪一个?为什么? 最佳答案 我们使用过qTip在我们的一个项目中,因为它符合我们的所有要求,开发和维护良好,附带优秀的文档和已经很漂亮的模板,并且还为我
我在Internet上四处张望,找不到相关信息。我的程序需要向PowerShell配置文件中编写一些PowerShell代码。如果没有配置文件,我的程序将创建一个。问题是应使用哪种编码来创建Power
在 D、int、uint 中使用 foreach 时,循环索引的首选类型是什么?或者只是通过省略类型自动实现? 最佳答案 一般来说,索引应该是size_t。与长度相同。如果您尝试使用 int 或 ui
这个问题在这里已经有了答案: Repeat each row of data.frame the number of times specified in a column (9 个回答) 2年前关闭
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我有一个看起来像这样的字符串: "Element 1 | Element 2| Element 3: element 4" 我想对冒号后面的源字符串部分进行子串(到源字符串的末尾),但如果没有冒号,那
我接受任何解释语言 Perl、Python、Bash 等。但我更喜欢 Perl,因为它是我想要学习的。我有一个时间戳列表,例如: 17:31:16 17:31:16 17:31:18 17:31:29
我想在后台运行程序。首选 C#我想把图标放在托盘里。在指定的时间同步文件夹(我知道如何同步文件夹)。如何在后台运行它并开始同步(例如凌晨 2 点)? 最佳答案 您需要考虑使用 windows sche
我有一个 onChange 事件处理程序,它的结构如下: (e) => (value => this.setState(prevState => ({ form: {
我想在windows 7中捕获删除操作。如果用户从计算机上删除了文件,我需要在文件被删除时存储一条记录,以及删除了哪个文件。 一般文件操作,不针对特定文件夹或软件。所以假设用户从 d:\testFol
是否有任何库或开源函数可以近似通过以不规则间隔获取的一些值来描述的线下的面积? 首选 Action Script,但 Java 也可以正常工作。 最佳答案 您可以使用as3mathlib数学图书馆。这
对于我的网络应用程序,我希望提供给用户的图像具有响应性。此外,我还想在图像标签中指定 width 和 height 属性,这样在移动连接速度较慢的情况下,就不会出现浏览器重排。 是否可以通过使用纯 H
在展示公司 Logo 时,我今天看到了一些新东西。 他们在 h1 标签上设置了高度和宽度以及 overflow:hidden 并在 h1 标签内的 a 标签上设置了负边距以防止文本显示。 代码是这样的
我使用 Lucene 库开发了一个索引和搜索应用程序。但是这个库在我的上下文中在自定义排名方面有一些限制,除了它的性能之外,我需要可扩展性和访问各种词频等。是否有任何强大的开源全文库可用? 最佳答案
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 8 年前。 Improve
这是一个关于当我需要在列表中查找对象实例时如何实现 equals 方法的问题,该实例的值是我在其成员中拥有的实例之一。 我有一个实现了 equals 的对象: class User { pri
我是一名优秀的程序员,十分优秀!