gpt4 book ai didi

java - 识别处理中的特定 Blob

转载 作者:太空宇宙 更新时间:2023-11-04 11:53:28 25 4
gpt4 key购买 nike

我正在处理使用blobDetection library从高度图制作等值线图。 。我的最终目标是激光切割 Blob 以制作某种建筑景观模型。

enter image description here

目前我可以获取轮廓并将轮廓图导出为 SVG,这很棒,但我希望能够识别每个 Blob (或轮廓或环),然后能够单独操作每个轮廓。也就是说,我想将它们重新定位在窗口上,以便它们不会彼此重叠并且不会重叠。我还想为每个单独的 Blob 分配坐标,这样他们就很容易知道每个 Blob 被激光切割后的去向。

以下是代码(来自作者 v3ga 提供的示例):

import processing.svg.*;
import blobDetection.*;
import peasy.*;
import processing.pdf.*;

PeasyCam cam;
PImage img;

float levels = 10;
float factor = 10;
float elevation = 125;

float colorStart = 0;
float colorRange = 160;

BlobDetection[] contours = new BlobDetection[int(levels)];

boolean recording = false;
void keyPressed(){
if (key == 'r' || key == 'R'){
recording = !recording;
}
}

void setup() {

size(1000,800,P3D);
surface.setResizable(true);

img = loadImage("map1.gif");
surface.setSize(img.width, img.height);

cam = new PeasyCam(this, img.width, img.height, 0, 500);
colorMode(HSB, 360, 100, 100);

for (int i=0; i<levels; i++){
contours[i] = new BlobDetection(img.width, img.height);
contours[i].setThreshold(i/levels);
contours[i].computeBlobs(img.pixels);
}

}

void draw(){

if (recording){
beginRecord(SVG, "frame_####.svg");
}

for (int i=0; i<levels; i++){
drawContours(i);
}

if (recording) {
endRecord();
recording = false;
}

}

void drawContours(int i) {
Blob b;
EdgeVertex eA,eB;
for (int n=0 ; n<contours[i].getBlobNb() ; n++) {
b=contours[i].getBlob(n);
if (b!=null) {
stroke(250,75,90);
for (int m=0;m<b.getEdgeNb();m++) {
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null)
line(
eA.x*img.width, eA.y*img.height,
eB.x*img.width, eB.y*img.height
);
}
}
}
}

经过一些测试后,我认为最好的方法是创建包含每个 blob 信息(x 和 y 坐标、级别)的对象数组,并在 drawContours 方法中填充该数组。但是,我在获取要存储在该数组中的正确信息时遇到了很多麻烦。

所以我的问题是:

  • 如何识别复杂形状(例如这些 Blob )的 x,y 坐标
  • 一旦我将 Blob 的信息存储在数组中,如何重新定位它们

任何建议,即使使用其他技术(即不处理),我们都将不胜感激。

最佳答案

要以 3D 形式显示 Blob ,请在顶部添加 height_scale 常量,并将 drawContours 函数修改为以下内容:

final int HEIGHT_SCALE = 10; // amount of z space between each blob

void drawContours(int i) {
Blob b;
EdgeVertex eA,eB;
for (int n=0 ; n<contours[i].getBlobNb() ; n++) {
b=contours[i].getBlob(n);
if (b!=null) {
stroke(250,75,90);
beginShape();
for (int m=0;m<b.getEdgeNb();m++) {
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null)
vertex(eA.x*img.width, eA.y*img.height, i*HEIGHT_SCALE);
vertex(eB.x*img.width, eB.y*img.height, i*HEIGHT_SCALE);
}
endShape(CLOSE);
}
}
}

请记住,我没有运行此代码,也没有使用您正在使用的框架,但是 beginShape()、vertex() 和 endShape() 函数应该允许您在边缘之间创建相同的线,并且我向顶点添加了 z 坐标,以便它们在高度上分开。

刚刚意识到您也可以使用以下内容,因为 line(x1,y1,x2,y2) 也可以采用 line(x1,y1,z1,x2,y2,z2):

final int HEIGHT_SCALE = 10; // amount of z space between each blob

void drawContours(int i) {
Blob b;
EdgeVertex eA,eB;
for (int n=0 ; n<contours[i].getBlobNb() ; n++) {
b=contours[i].getBlob(n);
if (b!=null) {
stroke(250,75,90);
for (int m=0;m<b.getEdgeNb();m++) {
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null)
line(eA.x*img.width, eA.y*img.height, i*HEIGHT_SCALE, eB.x*img.width, eB.y*img.height, i*HEIGHT_SCALE);
}
}
}
}

关于java - 识别处理中的特定 Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41579326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com