Image processing 使用处理进行三维图像映射
事实上,我试过运行球形POV。对于运行POV,每个图像应转换为每次旋转中使用的线数,我尝试使用处理软件通过其库将2d图像转换为3d图像,但当在球形POV上插入这些像素数据时,图像确实无法识别,任何关于如何在球面上映射2d图像的线索,Processing editor附带了一些示例,其中一个示例将纹理图像映射到球体。它将球体拆分为三角形,然后使用Image processing 使用处理进行三维图像映射,image-processing,arduino,processing,pixel,led,Image Processing,Arduino,Processing,Pixel,Led,事实上,我试过运行球形POV。对于运行POV,每个图像应转换为每次旋转中使用的线数,我尝试使用处理软件通过其库将2d图像转换为3d图像,但当在球形POV上插入这些像素数据时,图像确实无法识别,任何关于如何在球面上映射2d图像的线索,Processing editor附带了一些示例,其中一个示例将纹理图像映射到球体。它将球体拆分为三角形,然后使用texture()和vertex()函数绘制带纹理的球体 您可以通过转到File>Examples>Topics>Textures>TextureSphe
texture()
和vertex()
函数绘制带纹理的球体
您可以通过转到File>Examples>Topics>Textures>TextureSphere
,从处理编辑器获取代码,但代码如下:
/**
* Texture Sphere
* by Gillian Ramsay
*
* Rewritten by Gillian Ramsay to better display the poles.
* Previous version by Mike 'Flux' Chang (and cleaned up by Aaron Koblin).
* Original based on code by Toxi.
*
* A 3D textured sphere with simple rotation control.
*/
int ptsW, ptsH;
PImage img;
int numPointsW;
int numPointsH_2pi;
int numPointsH;
float[] coorX;
float[] coorY;
float[] coorZ;
float[] multXZ;
void setup() {
size(640, 360, P3D);
background(0);
noStroke();
img=loadImage("world32k.jpg");
ptsW=30;
ptsH=30;
// Parameters below are the number of vertices around the width and height
initializeSphere(ptsW, ptsH);
}
// Use arrow keys to change detail settings
void keyPressed() {
if (keyCode == ENTER) saveFrame();
if (keyCode == UP) ptsH++;
if (keyCode == DOWN) ptsH--;
if (keyCode == LEFT) ptsW--;
if (keyCode == RIGHT) ptsW++;
if (ptsW == 0) ptsW = 1;
if (ptsH == 0) ptsH = 2;
// Parameters below are the number of vertices around the width and height
initializeSphere(ptsW, ptsH);
}
void draw() {
background(0);
camera(width/2+map(mouseX, 0, width, -2*width, 2*width),
height/2+map(mouseY, 0, height, -height, height),
height/2/tan(PI*30.0 / 180.0),
width, height/2.0, 0,
0, 1, 0);
pushMatrix();
translate(width/2, height/2, 0);
textureSphere(200, 200, 200, img);
popMatrix();
}
void initializeSphere(int numPtsW, int numPtsH_2pi) {
// The number of points around the width and height
numPointsW=numPtsW+1;
numPointsH_2pi=numPtsH_2pi; // How many actual pts around the sphere (not just from top to bottom)
numPointsH=ceil((float)numPointsH_2pi/2)+1; // How many pts from top to bottom (abs(....) b/c of the possibility of an odd numPointsH_2pi)
coorX=new float[numPointsW]; // All the x-coor in a horizontal circle radius 1
coorY=new float[numPointsH]; // All the y-coor in a vertical circle radius 1
coorZ=new float[numPointsW]; // All the z-coor in a horizontal circle radius 1
multXZ=new float[numPointsH]; // The radius of each horizontal circle (that you will multiply with coorX and coorZ)
for (int i=0; i<numPointsW ;i++) { // For all the points around the width
float thetaW=i*2*PI/(numPointsW-1);
coorX[i]=sin(thetaW);
coorZ[i]=cos(thetaW);
}
for (int i=0; i<numPointsH; i++) { // For all points from top to bottom
if (int(numPointsH_2pi/2) != (float)numPointsH_2pi/2 && i==numPointsH-1) { // If the numPointsH_2pi is odd and it is at the last pt
float thetaH=(i-1)*2*PI/(numPointsH_2pi);
coorY[i]=cos(PI+thetaH);
multXZ[i]=0;
}
else {
//The numPointsH_2pi and 2 below allows there to be a flat bottom if the numPointsH is odd
float thetaH=i*2*PI/(numPointsH_2pi);
//PI+ below makes the top always the point instead of the bottom.
coorY[i]=cos(PI+thetaH);
multXZ[i]=sin(thetaH);
}
}
}
void textureSphere(float rx, float ry, float rz, PImage t) {
// These are so we can map certain parts of the image on to the shape
float changeU=t.width/(float)(numPointsW-1);
float changeV=t.height/(float)(numPointsH-1);
float u=0; // Width variable for the texture
float v=0; // Height variable for the texture
beginShape(TRIANGLE_STRIP);
texture(t);
for (int i=0; i<(numPointsH-1); i++) { // For all the rings but top and bottom
// Goes into the array here instead of loop to save time
float coory=coorY[i];
float cooryPlus=coorY[i+1];
float multxz=multXZ[i];
float multxzPlus=multXZ[i+1];
for (int j=0; j<numPointsW; j++) { // For all the pts in the ring
normal(-coorX[j]*multxz, -coory, -coorZ[j]*multxz);
vertex(coorX[j]*multxz*rx, coory*ry, coorZ[j]*multxz*rz, u, v);
normal(-coorX[j]*multxzPlus, -cooryPlus, -coorZ[j]*multxzPlus);
vertex(coorX[j]*multxzPlus*rx, cooryPlus*ry, coorZ[j]*multxzPlus*rz, u, v+changeV);
u+=changeU;
}
v+=changeV;
u=0;
}
endShape();
}
/**
*纹理球
*吉莉安·拉姆齐
*
*由Gillian Ramsay改写以更好地展示波兰人。
*前一版本由迈克·张福禄(Aaron Koblin整理)。
*原始基于Toxi的代码。
*
*具有简单旋转控制的3D纹理球体。
*/
int ptsW,ptsH;
皮马杰;
int numPointsW;
int numPointsH_2pi;
int numPointsH;
浮动[]coorX;
浮动[]库里;
浮动[]库兹;
浮动[]multXZ;
无效设置(){
尺寸(640、360、P3D);
背景(0);
仰泳();
img=loadImage(“world32k.jpg”);
ptsW=30;
ptsH=30;
//下面的参数是围绕宽度和高度的顶点数
初始化此处(ptsW、ptsH);
}
//使用箭头键更改详细信息设置
按下void键(){
如果(keyCode==ENTER)saveFrame();
if(keyCode==UP)ptsH++;
如果(keyCode==向下)ptsH--;
如果(keyCode==左)ptsW--;
if(keyCode==右)ptsW++;
如果(ptsW==0)ptsW=1;
如果(ptsH==0)ptsH=2;
//下面的参数是围绕宽度和高度的顶点数
初始化此处(ptsW、ptsH);
}
作废提款(){
背景(0);
摄像头(宽度/2+贴图(鼠标,0,宽度,-2*宽度,2*宽度),
高度/2+贴图(鼠标,0,高度,-高度,高度),
高度/2/tan(PI*30.0/180.0),
宽度、高度/2.0、0、,
0, 1, 0);
pushMatrix();
平移(宽度/2,高度/2,0);
纹理(200200200200img);
popMatrix();
}
无效初始值此处(int numpsw,int numpsh_2pi){
//宽度和高度周围的点数
numPointsW=numPtsW+1;
numPointsH_2pi=numPtsH_2pi;//球体周围实际有多少个点(不仅仅是从上到下)
numPointsH=ceil((float)numPointsH_2pi/2)+1;//从上到下(可能出现奇数numPointsH_2pi的abs(..)b/c)有多少个点
coorX=new float[numPointsW];//水平圆半径1内的所有x-coor
coorY=new float[numPointsH];//垂直圆半径1中的所有y-coor
coorZ=new float[numPointsW];//水平圆半径1内的所有z-coor
multXZ=new float[numPointsH];//每个水平圆的半径(将与coorX和coorZ相乘)
对于(int i=0;i交叉柱之间的链接:堆栈溢出实际上不是为一般的“我该怎么做”类型问题而设计的。它更适合于特定的“我尝试了X,预期了Y,但得到了Z”键入问题。你能发布你尝试过的任何东西吗?你的笔记在哪里?如果你不知道如何开始,那么从较小的地方开始:你能得到一个映射到矩形的图像吗?从那里开始,如果你卡住了就发帖子。祝你好运。真的很感谢@Kevin,我也收到了你的笔记,实际上我是这里的新手,还没有完全认识你关于如何打开门票以及如何回应,请让我知道如何邀请那些现在可能会以特定方式回答问题的人topic@Hamidsk这并不是堆栈溢出的工作原理。你可以通过电子邮件向他们发送一个问题的链接,但如果你说的是通过堆栈溢出发送消息,那就真的不行了。