using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public Texture2D t;
public Color drawColor = new Color32(240, 190, 170, 255);
public Color defaultColor = new Color32(0, 0, 0, 0);
Color minValveColor = new Color32(245, 237, 210, 255);
Color maxValveColor = new Color32(255, 248, 230, 255);
float minR = 0;
float minG = 0;
float minB = 0;
float maxR = 0;
float maxG = 0;
float maxB = 0;
Texture2D tt;
void Start () {
minR = minValveColor.r ;
minG = minValveColor.g ;
minB = minValveColor.b ;
maxR = maxValveColor.r ;
maxG = maxValveColor.g ;
maxB = maxValveColor.b ;
transform.localScale = new Vector3 ((float)t.width/(float)t.height, 1);
InvokeRepeating ("MyUpdate", 0, 1);
}
string z = "";
void MyUpdate () {
if(tt != null){
Destroy(tt);
}
tt = new Texture2D (t.width, t.height);
for(int y = 0; y < t.height; y++){
for(int x = 0; x < t.width; x++){
Color c = t.GetPixel(x, y);
float r = c.r ;
float g = c.g ;
float b = c.b ;
if(r >= minR && r <= maxR && g >= minG && g <= maxG && b >= minB && b <= maxB){
tt.SetPixel(x, y, drawColor);
}else{
tt.SetPixel(x, y, defaultColor);
}
}
}
tt.Apply ();
renderer.material.mainTexture = tt;
}
}
公告版位
需要找什麼嗎? 左邊分類或許可以幫助你...
- Jan 28 Wed 2015 21:57
Unity 影像處理:特定顏色範圍二值化
全站熱搜
留言列表