小编Tec*_*Sam的帖子

是否有零拷贝方法来查找任意数量的集合的交集?

这是一个简单的例子,展示了我正在尝试做的事情:

use std::collections::HashSet;

fn main() {
    let mut sets: Vec<HashSet<char>> = vec![];

    let mut set = HashSet::new();
    set.insert('a');
    set.insert('b');
    set.insert('c');
    set.insert('d');
    sets.push(set);

    let mut set = HashSet::new();
    set.insert('a');
    set.insert('b');
    set.insert('d');
    set.insert('e');
    sets.push(set);

    let mut set = HashSet::new();
    set.insert('a');
    set.insert('b');
    set.insert('f');
    set.insert('g');
    sets.push(set);

    // Simple intersection of two sets
    let simple_intersection = sets[0].intersection(&sets[1]);
    println!("Intersection of 0 and 1: {:?}", simple_intersection);

    let mut iter = sets.iter();
    let base = iter.next().unwrap().clone();
    let intersection = iter.fold(base, |acc, set| acc.intersection(set).map(|x| x.clone()).collect());
    println!("Intersection of all: {:?}", …
Run Code Online (Sandbox Code Playgroud)

set set-intersection rust

6
推荐指数
1
解决办法
4971
查看次数

基于边缘检测"剪切"图像

这是我原来的形象: 焊接螺母

我已要求用户裁剪它,将其转换为灰度并在其上运行以下代码:

edgeImg = edge(grayImg,'canny',0.23);
Run Code Online (Sandbox Code Playgroud)

这是结果:

边缘

我想基本上"切掉"中间圆和外边缘的所有东西.我很难搞清楚如何做到这一点,说实话,我很茫然.

我考虑过试图填写我想要保留在二进制图像中的区域,然后我可以将它用作图章,但我无法想出一种不填充中间圆圈的方法.

有任何想法吗?

谢谢.

编辑:这个白色区域是我想要保留的:

突出

matlab image-processing

5
推荐指数
1
解决办法
1774
查看次数

有什么方法可以将引用类型克隆到拥有的类型中吗?

我有一个方法,我想返回一个元素的拥有副本。如果需要的话,我可以证明为什么我想要这个。

这是一个最小的可重现示例:(游乐场

use std::collections::HashMap;

struct AsciiDisplayPixel {
    value: char,
    color: u32,
}

struct PieceToPixelMapper {
    map: HashMap<usize, AsciiDisplayPixel>,
}

impl PieceToPixelMapper {
    pub fn map(&self, index: usize) -> Option<AsciiDisplayPixel> {
        let pixel = self.map.get(&index);
        let pixel = match pixel {
            None => return None,
            Some(x) => x,
        };

        return Some(pixel.clone());
    }
}

fn main() {
    println!("Hello World");
}
Run Code Online (Sandbox Code Playgroud)

这无法编译

use std::collections::HashMap;

struct AsciiDisplayPixel {
    value: char,
    color: u32,
}

struct PieceToPixelMapper {
    map: HashMap<usize, AsciiDisplayPixel>,
}

impl PieceToPixelMapper …
Run Code Online (Sandbox Code Playgroud)

clone reference ownership rust

2
推荐指数
1
解决办法
1248
查看次数