java识别处理中的特定blob
我正在使用blobDetection library从高度图制作等高线图。我的最终目标是用激光切割这些斑点,制作某种建筑景观模型
目前,我可以获得轮廓,并将轮廓图导出为SVG,这很好,但我希望能够识别每个斑点(或轮廓,或环),然后能够分别操作每个轮廓。也就是说,我想在窗口上重新定位它们,这样它们就不会相互重叠。我还想为每个单独的斑点指定坐标,这样他们就可以很容易地知道激光切割后每个斑点的去向
以下是代码(来自作者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方法中填充这个数组。然而,我在获取存储在这个数组中的正确信息时遇到了很多困难
所以我的问题是:
- 如何识别复杂形状(如这些斑点)的x、y坐标
- 在阵列中存储Blob的信息后,如何重新定位Blob
任何建议,即使使用其他技术(即不处理),也将不胜感激
# 1 楼答案
要在3D中显示水滴,请在顶部添加高度_比例常数,并将drawContours函数修改为以下内容:
请记住,我没有运行这段代码,也没有使用您正在使用的框架,但是beginShape()、vertex()和endShape()函数应该允许您在边之间创建相同的线,并且我向顶点添加了一个z坐标,以便它们在高度上分开
我刚刚意识到你也可以这样做,因为直线(x1,y1,x2,y2)也可以取直线(x1,y1,z1,x2,y2,z2):