//update the terrain mesh with height data from Kinect sensor public void UpdateMesh() { ushort[] heightData = manager.GetData(); spacing = scale / frameHeight; if (useSensor) { // Populate vertex array using sensor data for (int i = 0; i < frameHeight / downsampleSize; i++) { for (int j = 0; j < frameWidth / downsampleSize; j++) { ushort y = heightData [j * downsampleSize + frameWidth * i * downsampleSize]; // Get Y value from Kinect height data float yNorm = ((float)y - maxHeight) / (minHeight - maxHeight); // Normalize height vertices [j + frameWidth / downsampleSize * i] = new Vector3(j * spacing, yNorm * magnitude, i * spacing); } } } else { // Populate vertex array using placeholder heightmap for debugging for (int i = 0; i < frameHeight / downsampleSize; i++) { for (int j = 0; j < frameWidth / downsampleSize; j++) { float y = heightmap.GetPixel(i, j).r; // Get Y value from heightmap vertices [j + frameWidth / downsampleSize * i] = new Vector3(j * spacing, y * magnitude, i * spacing); } } } mesh.vertices = vertices; mesh.RecalculateNormals(); }
//update the terrain mesh with height data from Kinect sensor public void UpdateMesh() { heightmapFromSensor = new Texture2D(frameWidth / downsampleSize, frameHeight / downsampleSize, TextureFormat.RGB24, false); spacing = scale / frameHeight; if (sensor != null) { ushort[] heightData = manager.GetData(); // Populate vertex array using sensor data for (int i = 0; i < frameHeight / downsampleSize; i++) { for (int j = 0; j < frameWidth / downsampleSize; j++) { ushort y = heightData [j * downsampleSize + frameWidth * i * downsampleSize]; // Get Y value from Kinect height data float yNorm = ((float)y - maxHeight) / (minHeight - maxHeight); // Normalize height Color height = new Color(yNorm, yNorm, yNorm, 1); heightmapFromSensor.SetPixel(j, i, height); // If we are loading terrain if (loadTerrain) { // if current height is higher than the heightmap. if (heightmapFromSensor.GetPixel(j, i).r > loadedHeightmap.GetPixel(j, i).r) { // show red to lower. yNorm -= 1.0f; } // if current height is lower than the heightmap. else if (heightmapFromSensor.GetPixel(j, i).r < loadedHeightmap.GetPixel(j, i).r) { // show blue to raise. yNorm += 1.0f; } // if the current height is the same as the heightmap. } vertices [j + frameWidth / downsampleSize * i] = new Vector3(j * spacing, yNorm * magnitude, i * spacing); } } } else { // Populate vertex array using placeholder heightmap for debugging for (int i = 0; i < frameHeight / downsampleSize; i++) { for (int j = 0; j < frameWidth / downsampleSize; j++) { float y = heightmap.GetPixel(i, j).r; // Get Y value from heightmap vertices [j + frameWidth / downsampleSize * i] = new Vector3(j * spacing, y * magnitude, i * spacing); } } } mesh.vertices = vertices; mesh.RecalculateNormals(); }
void updateTexture() { // get new depth data from DepthSourceManager. ushort[] rawdata = depthSourceManagerScript.GetData(); // convert to byte data ( for (int i = 0; i < rawdata.Length; i++) { byte value = (byte)(rawdata[i] * scale); // byte value2 = (byte)255; if (value < 0.05f) { value = 0; value = 255; } int colorindex = i * 3; depthBitmapBuffer[colorindex + 0] = value; depthBitmapBuffer[colorindex + 1] = value; depthBitmapBuffer[colorindex + 2] = value; } // make texture from byte array texture.LoadRawTextureData(depthBitmapBuffer); texture.Apply(); }
void Update() { if (_DepthManager == null) { return; } //only process every 500 ms if (deltaTime < updateFrequency) { deltaTime += Time.deltaTime; return; } else { deltaTime = 0; } MeshData d = _DepthManager.GetData(); if (d.Triangles != null && d.Vertices != null) { ShowInBounds(d); } else { //if the kinect doesn't see anything, //just fall back to setting the point to the kinect's position KinectAvatarLogic.MyAvatar.PlaceAvatar(null, transform); } }
void Update() { //depthBuffer の更新 if (DepthSourceManager == null) { return; } _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>(); depthBuffer = _DepthManager.GetData(); // 指の判定 checkPoint(); // 初期化キー待機 if (Input.GetKey(KeyCode.I)) { Invoke("setFirstPoint", 0.5f); } if (Input.GetKey(KeyCode.C)) { // 球体の半径取得 IndexDatas indexDatasObj = GetComponent <IndexDatas>(); int radius = checkCircleLength(indexDatasObj.indexes_Y[3]); GameObject gameobject = Instantiate(painter, new Vector3(indexDatasObj.indexes_X[3], indexDatasObj.indexes_Y[3], 1), Quaternion.identity); gameobject.transform.localScale = new Vector3(radius, radius, 1); } }
void Update() { // get new depth data from DepthSourceManager. ushort[] rawdata = depthSourceManagerScript.GetData(); // map to camera space coordinate mapper.MapDepthFrameToCameraSpace(rawdata, cameraSpacePoints); for (int i = 0; i < cameraSpacePoints.Length; i++) { if (cameraSpacePoints[i].X <= 1 && cameraSpacePoints[i].X >= -1) //X座標の1~-1を表示 { particles[i].position = new Vector3(cameraSpacePoints[i].X * scale, cameraSpacePoints[i].Y * scale, cameraSpacePoints[i].Z * scale); particles[i].color = color; particles[i].size = size; if (rawdata[i] == 0) { particles[i].size = 0; //データの値が0ならばサイズを0にする } } else if (particles[i].position != null) //particles[i].positionのデータが空じゃなければサイズを0にする { particles[i].size = 0; } } // update particle system GetComponent <ParticleSystem>().SetParticles(particles, particles.Length); }
void UpdatePointCloud() { ushort[] depthMap = depthManager.GetData(); CameraSpacePoint[] realWorldPoints = new CameraSpacePoint[depthMap.Length]; mapper.MapDepthFrameToCameraSpace(depthMap, realWorldPoints); // Update Real world to kinect position. for (int ty = 0; ty < depthHeight; ty += downSample) { for (int tx = 0; tx < depthWidth; tx += downSample) { int index = ty * depthWidth + tx; CameraSpacePoint point = realWorldPoints[index]; Vector3 pointV3 = new Vector3(mirror ? -point.X : point.X, point.Y, point.Z); pointV3 = transform.TransformPoint(pointV3); realWorldPoints[index].X = pointV3.x; realWorldPoints[index].Y = pointV3.y; realWorldPoints[index].Z = pointV3.z; } } OnPointCloudUpdate(realWorldPoints, depthWidth, depthHeight, downSample); }
// referred the code below. thx kaorun55-san // https://github.com/kaorun55/Kinect-for-Windows-SDK-v2.0-Samples/blob/master/C%23(WinRT)/02_Depth/KinectV2-Depth-01/KinectV2/MainPage.xaml.cs void updateTexture() { // get new depth data from DepthSourceManager. ushort[] rawdata = depthSourceManagerScript.GetData(); // convert to byte data ( for (int i = 0; i < rawdata.Length; i++) { // 0-8000を0-256に変換する byte value = (byte)(rawdata[i] * 255 / 8000); if (rawdata[i] > 1000) { value = 0; } int colorindex = i * 3; depthBitmapBuffer[colorindex + 0] = value; depthBitmapBuffer[colorindex + 1] = value; depthBitmapBuffer[colorindex + 2] = value; } // make texture from byte array texture.LoadRawTextureData(depthBitmapBuffer); texture.Apply(); }
// Update is called once per frame void Update() { if (_Sensor == null || _ColorSourceManager == null || _DepthSourceManager == null) { return; } Mat colorMat = _ColorSourceManager.GetColorMat(); ushort[] depthData = _DepthSourceManager.GetData(); _colorTexture = _ColorSourceManager.GetColorTexture(); if (_mapperMat == null) { _mapperMat = new Mat(_colorTexture.height, _colorTexture.width, CvType.CV_8UC3); } //mapper colorSpace = new ColorSpacePoint[depthData.Length]; depthSpace = new DepthSpacePoint[_colorTexture.width * _colorTexture.height]; _Mapper.MapDepthFrameToColorSpace(depthData, colorSpace); _Mapper.MapColorFrameToDepthSpace(depthData, depthSpace); //_mapperMat = colorMat; }
// Update is called once per frame void Update() { ushort[] depthData = _DepthManager.GetData(); for (int y = 0; y < frameDesc.Height; y++) { for (int x = 0; x < frameDesc.Width; x++) { int fullIndex = (y * frameDesc.Width) + x; double depth = MAX_DEPTH - depthData[fullIndex]; // So 0 is most distant one! if (depth == 0) { Color color = new Color(0, 0, 0); texture.SetPixel(x, y, color); } else { float heightValue = (float)(depth / 4500f); //Debug.Log("Height for pixel: " + x + " " + y + " = " + depth + " >> " + heightValue); Color color = new Color(heightValue, heightValue, heightValue); texture.SetPixel(x, y, color); } } } texture.Apply(); }
// Update is called once per frame void Update() { if (once) { //Debug.Log(dsm.Width); //Debug.Log(dsm.Height); once = false; //initializing all the lists startMap = new byte[424 * 424]; //the map that constantly gets changed on frame update finalMap = new byte[424 * 424]; //the obsticle map passed into the pathfinder colourDepth = new byte[424 * 424 * 4]; texture = new Texture2D(424, 424, TextureFormat.RGBA32, false); return; } if (fromText == true) { depth = dsm.GetData(); } else { depth = defaultMap; } /////Updating map with Kinect///// //Putting kinect data into an array int m = 0; //The loop which converts depth into terran colour for (int i = 0; i < 424; i++) { for (int j = 0; j < 512; j++) { int k = j + 512 * i; if (k > 43 + (512 * i) && k < 468 + (512 * i)) { //Debug.Log("test"); if (depth[k] == null) { Debug.Log("F**K!"); } else { Mapcolour(depth[k], m); m++; } } } } //Debug.Log(depth.Length + " " + a + " " + b); texture.LoadRawTextureData(colourDepth); texture.Apply(); renderer.material.mainTexture = texture; finalMap = startMap; }
// Use this for initialization void Start() { //cam設定與啟用 MatchWidth = 0; MatchHeight = 0; //取得螢幕與輸入cam的影像大小 _inputWidth = ColorSourceManager.ColorWidth; _inputHeight = ColorSourceManager.ColorHeight; _depthData = DepthSourceManager.GetData(); //Debug.Log(_depthData.Length); //螢幕大小與來源比例初始化 _currentWidth = Screen.width; _currentHeight = Screen.height; _positionTrans = new clickPositionTrans(_currentWidth, _currentHeight, _inputWidth, _inputHeight); //創造mat儲存輸出影像 _sourceMat = new Mat(_inputHeight, _inputWidth, CvType.CV_8UC3); _sourceMat_backup = new Mat(_inputHeight, _inputWidth, CvType.CV_8UC3); _sourceMatDepth = new Mat(_inputHeight, _inputWidth, CvType.CV_8UC1); _blockImageBuffer = new Mat(_inputHeight, _inputWidth, CvType.CV_8UC1); //創造mat儲存比對用mat(原始比對圖形為未改變比例) _blockImage = new Mat(_inputHeight, _inputWidth, CvType.CV_8UC3); _souceOut = new Texture2D(_inputWidth, _inputHeight); _blockTexture = new Texture2D(320, 180); _blockDepthTexture = new Texture2D(320, 180); _blockDepthTextureBg = new Texture2D(320, 180); isInput = false; //設定同步旗標 _SyncFlag = false; //thread _thread = new Thread(drawDepthSourceMat); //設定是否完成影像背景偵測 _ScreenSettingCompletionFlag = false; //選擇範圍初始化 _minX = 0; _maxX = 0; _minY = 0; _maxY = 0; //設定影像改變旗標 _DepthImageChangeFlag = true; //try //{ // System.IO.StreamReader fileData = new System.IO.StreamReader("DrawBlockData.txt", System.Text.Encoding.Default); // _pointOne.x = double.Parse(fileData.ReadLine()); // _pointOne.y = double.Parse(fileData.ReadLine()); // _pointTwo.x = double.Parse(fileData.ReadLine()); // _pointTwo.y = double.Parse(fileData.ReadLine()); // fileData.Close(); // //_ScreenSettingCompletionFlag = false; // isInput = !isInput; // pointUp(); //} //catch //{ // Debug.Log("Drawblock File error"); //} }
void Update() { if (!IsFrameValid()) { return; } ushort[] rawDepthData = CropRawDepth(DepthSourceManager.GetData(), activeWidth, activeHeight); UpdateDepthMesh(kinectDepthMesh, rawDepthData, depthRescale, KINECTMESH_DOWNSAMPLING); kinectMeshFilter.mesh.vertices = kinectDepthMesh.mesh.vertices; }
//update the terrain mesh with height data from Kinect sensor public void UpdateMesh() { ushort[] heightData = manager.GetData(); Texture2D img = new Texture2D(frameWidth, frameHeight, TextureFormat.RGB24, false); spacing = scale / frameHeight; if (useSensor) { // Populate vertex array using sensor data for (int i = 0; i < frameHeight / downsampleSize; i++) { for (int j = 0; j < frameWidth / downsampleSize; j++) { ushort y = heightData [j * downsampleSize + frameWidth * i * downsampleSize]; // Get Y value from Kinect height data float yNorm = ((float)y - maxHeight) / (minHeight - maxHeight); // Normalize height vertices [j + frameWidth / downsampleSize * i] = new Vector3(j * spacing, yNorm * magnitude, i * spacing); } } byte[] b = img.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/Resources/terrainSave.png", b); } else { // Populate vertex array using placeholder heightmap for debugging for (int i = 0; i < frameHeight / downsampleSize; i++) { for (int j = 0; j < frameWidth / downsampleSize; j++) { float y = heightmap.GetPixel(i, j).r; // Get Y value from heightmap vertices [j + frameWidth / downsampleSize * i] = new Vector3(j * spacing, y * magnitude, i * spacing); } } } mesh.vertices = vertices; mesh.RecalculateNormals(); }
void Update() { // Track Body bodyData = bodyManager.GetData(); if (bodyData == null) { return; } // Get Joint foreach (Kinect.Body b in bodyData) { if (b.IsTracked) { joints = b.Joints; break; } } if (joints == null) { return; } // Get Depth ushort[] depthData = depthManager.GetData(); // Calculate Sticks Index bool[] stickIndex = getStickIndex(depthData); bool useCache = stickIndex == null; /* * if (useCache) * { * * if (depthDataCache != null) * depthData = (ushort[])depthDataCache.Clone(); * * if (stickIndexCache != null) * stickIndex = (bool[])stickIndexCache.Clone(); * } */ if (!useCache) { printDepthImg(depthData, stickIndex); } }
public void Test() { ushort[] depth = dsm.GetData(); Debug.Log(path); using (FileStream fs = new FileStream(path, FileMode.Truncate, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs)) { foreach (ushort value in depth) { sw.Write(Convert.ToString(value) + ","); } } } }
// Update is called once per frame void Update() { if (_Sensor == null) { return; } if (_DepthManager == null) { return; } //if (_DepthManager == null) //{ // return; //} RefreshData(_DepthManager.GetData()); }
void Update() { if (_Sensor == null) { return; } if (Input.GetButtonDown("Fire1")) { if (ViewMode == DepthViewMode.MultiSourceReader) { ViewMode = DepthViewMode.SeparateSourceReaders; } else { ViewMode = DepthViewMode.MultiSourceReader; } } float yVal = Input.GetAxis("Horizontal"); float xVal = -Input.GetAxis("Vertical"); transform.Rotate( (xVal * Time.deltaTime * _Speed), (yVal * Time.deltaTime * _Speed), 0, Space.Self); if (ViewMode == DepthViewMode.SeparateSourceReaders) { gameObject.GetComponent <Renderer>().material.mainTexture = _ColorManager.GetColorTexture(); RefreshData(_DepthManager.GetData(), _ColorManager.ColorWidth, _ColorManager.ColorHeight); } else { gameObject.GetComponent <Renderer>().material.mainTexture = _MultiManager.GetColorTexture(); RefreshData(_MultiManager.GetDepthData(), _MultiManager.ColorWidth, _MultiManager.ColorHeight); } }
void Update() { // get new depth data from DepthSourceManager. ushort[] rawdata = depthSourceManagerScript.GetData(); // map to camera space coordinate mapper.MapDepthFrameToCameraSpace(rawdata, cameraSpacePoints); for (int i = 0; i < cameraSpacePoints.Length; i++) { particles[i].position = new Vector3(cameraSpacePoints[i].X * scale, cameraSpacePoints[i].Y * scale, cameraSpacePoints[i].Z * scale); particles[i].color = color; particles[i].size = size; if (rawdata[i] == 0) { particles[i].size = 0; } } // update particle system GetComponent <ParticleSystem>().SetParticles(particles, particles.Length); }
void Update() { if (_Sensor == null) { return; } //點擊滑鼠右鍵切換單組資源配置或是多組資源配置。 if (Input.GetButtonDown("Fire1")) { if (ViewMode == DepthViewMode.MultiSourceReader) { ViewMode = DepthViewMode.SeparateSourceReaders; } else { ViewMode = DepthViewMode.MultiSourceReader; } } //使用上下左右鍵旋轉Mesh物件。 float yVal = Input.GetAxis("Horizontal"); float xVal = -Input.GetAxis("Vertical"); transform.Rotate( (xVal * Time.deltaTime * _Speed), (yVal * Time.deltaTime * _Speed), 0, Space.Self); //如果切換到了單組資源配置的執行工作。 if (ViewMode == DepthViewMode.SeparateSourceReaders) { if (ColorSourceManager == null) { return; } _ColorManager = ColorSourceManager.GetComponent <ColorSourceManager>(); if (_ColorManager == null) { return; } if (DepthSourceManager == null) { return; } _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>(); if (_DepthManager == null) { return; } gameObject.renderer.material.mainTexture = _ColorManager.GetColorTexture(); RefreshData(_DepthManager.GetData(), _ColorManager.ColorWidth, _ColorManager.ColorHeight); } else //如果切換到了多組資源配置的執行工作。 { if (MultiSourceManager == null) { return; } _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>(); if (_MultiManager == null) { return; } gameObject.renderer.material.mainTexture = _MultiManager.GetColorTexture(); RefreshData(_MultiManager.GetDepthData(), _MultiManager.ColorWidth, _MultiManager.ColorHeight); } }
// Update is called once per frame void Update() { if (once) { //Debug.Log(dsm.Width); //Debug.Log(dsm.Height); once = false; //initializing all the lists startMap = new byte[424 * 424]; //the map that constantly gets changed on frame update finalMap = new byte[424 * 424]; //the obsticle map passed into the pathfinder colourDepth = new byte[424 * 424 * 4]; texture = new Texture2D(424, 424, TextureFormat.RGBA32, false); standardDepth = new ushort[424 * 424]; maskingLayer = new bool[424 * 424]; lavaMap = new bool[424 * 424]; DrawMaskingCircle(); return; } if (fromText == true) { depth = dsm.GetData(); } else { depth = defaultMap; } /////Updating map with Kinect///// //Putting kinect data into an array int m = 0; //The loop which converts depth into terran colour for (int i = 0; i < 424; i++) { for (int j = 0; j < 512;j++) { int k = j + 512 * i; if (k > 43+(512*i) && k < 468+(512*i)) { //Debug.Log("test"); if (depth[k] == null) { Debug.Log("F**K!"); } else { Mapcolour(depth[k], m); m++; } } } } //Debug.Log(depth.Length + " " + a + " " + b); texture.LoadRawTextureData(colourDepth); texture.Apply(); renderer.material.mainTexture = texture; finalMap = startMap; timer += Time.deltaTime; if (timer > delay && lavaStart == true) { count+=2; Debug.Log(count); getLavaMap(); timer = 0; } //getting value of highest point of sand //Debug.Log (highestPoint); //Debug.Log (lowestPoint); }
void updateTexture() { resultMat1 = Mat.zeros(texture.height, texture.width, CvType.CV_8UC1); resultMat2 = Mat.zeros(texture.height, texture.width, CvType.CV_8UC1); resultMat3 = Mat.zeros(texture.height, texture.width, CvType.CV_8UC1); // get new depth data from DepthSourceManager. ushort[] rawdata = depthSourceManagerScript.GetData(); v = 2500; for (int r = 0; r < f_DepthMapHeight; r += 1) //위에서 아래로 { for (int c = 0; c < f_DepthMapWidth; c += 1) //오른쪽에서 왼쪽으로 { //value / (v / 256) ushort value = rawdata[r * f_DepthMapWidth + c]; depthBitmapBuffer[(r * f_DepthMapWidth + c) * 4 + 1] = (byte)((500 < value) && (value < 2500) ? 255 - (256 * value / (v)) : 0); // G // COMMON depthBitmapBuffer[(r * f_DepthMapWidth + c) * 4 + 3] = (byte)((500 < value) && (value < 2500) ? 255 - (256 * value / (v)) : 0); // A // COMMON } } // make texture from byte array texture.LoadRawTextureData(depthBitmapBuffer); texture.Apply(); resultMat1 = avgMatReturn(texture, matBuffer, ref sumCount1); v = 3200; for (int r = 0; r < f_DepthMapHeight; r += 1) //위에서 아래로 { for (int c = 0; c < f_DepthMapWidth; c += 1) //오른쪽에서 왼쪽으로 { ushort value = rawdata[r * f_DepthMapWidth + c]; depthBitmapBuffer[(r * f_DepthMapWidth + c) * 4 + 1] = (byte)((2500 < value) && (value < 3200) ? 255 - (256 * value / (v)) : 0); // G // COMMON depthBitmapBuffer[(r * f_DepthMapWidth + c) * 4 + 3] = (byte)((2500 < value) && (value < 3200) ? 255 - (256 * value / (v)) : 0); // A // COMMON } } // make texture from byte array texture.LoadRawTextureData(depthBitmapBuffer); texture.Apply(); resultMat2 = avgMatReturn(texture, matBuffer2, ref sumCount2); v = 5000; for (int r = 0; r < f_DepthMapHeight; r += 1) //위에서 아래로 { for (int c = 0; c < f_DepthMapWidth; c += 1) //오른쪽에서 왼쪽으로 { ushort value = rawdata[r * f_DepthMapWidth + c]; depthBitmapBuffer[(r * f_DepthMapWidth + c) * 4 + 1] = (byte)((3200 < value) && (value < 5000) ? 255 - (256 * value / (v)) : 0); // G // COMMON depthBitmapBuffer[(r * f_DepthMapWidth + c) * 4 + 3] = (byte)((3200 < value) && (value < 5000) ? 255 - (256 * value / (v)) : 0); // A // COMMON } } // make texture from byte array texture.LoadRawTextureData(depthBitmapBuffer); texture.Apply(); resultMat3 = avgMatReturn(texture, matBuffer3, ref sumCount3); Mat totalMat = new Mat(texture.height, texture.width, CvType.CV_8UC1); totalMat = Mat.zeros(texture.height, texture.width, CvType.CV_8UC1); Core.add(totalMat, resultMat1, totalMat); //합영상 구하기. Core.add(totalMat, resultMat2, totalMat); //합영상 구하기. Core.add(totalMat, resultMat3, totalMat); //합영상 구하기. Utils.matToTexture2D(totalMat, texture); //원본 깊이값 영상 텍스쳐로 전환 texture.Apply(); //텍스쳐 적용 Mat kernel = new Mat(7, 7, CvType.CV_8U, new Scalar(1)); Imgproc.threshold(convert8Mat, convert8Mat, 5, 255, Imgproc.THRESH_BINARY | Imgproc.THRESH_OTSU); Imgproc.threshold(totalMat, totalMat, 5, 255, Imgproc.THRESH_BINARY | Imgproc.THRESH_OTSU); Imgproc.erode(totalMat, totalMat, kernel); //병목 Imgproc.dilate(totalMat, totalMat, kernel); //팽창. Imgproc.dilate(totalMat, totalMat, kernel); //팽창. List <Point> touchPoints = new List <Point>(); Mat hierarchy = new Mat(); List <MatOfPoint> contours = new List <MatOfPoint>(); //RETR_EXTERNAL Imgproc.findContours(totalMat, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); for (int i = 0; i < contours.Count; i++) { Mat contourMat = new Mat(); contourMat = contours[i]; double contourArea = Imgproc.contourArea(contourMat); if (contourArea > footMinArea //&& contourArea < footMaxArea ) { Scalar center = Core.mean(contourMat); Point footPoint = new Point(center.val[0], center.val[1]); touchPoints.Add(footPoint); } Scalar color = new Scalar(255, 0, 0); Imgproc.drawContours(totalMat, contours, i, color, 7); } for (int i = 0; i < touchPoints.Count; i++) { // touch points Scalar color = new Scalar(255, 0, 0); Imgproc.circle(totalMat, touchPoints[i], 50, color, 7); int delta_x = (int)touchPoints[i].x; int delta_y = (int)touchPoints[i].y; OnParticleObjActive(delta_x, delta_y); } //현재 활성화중인 ParticleObj의 lifeTime을 확인하기 위해! OnParticleObjTimeCheck(); Utils.matToTexture2D(totalMat, subTexture); //원본 깊이값 영상 텍스쳐로 전환 subTexture.Apply(); //텍스쳐 적용 }
void Update() { if (_Sensor == null) { return; } if (Input.GetButtonDown("Fire1")) { if (updateTerrain == true) { updateTerrain = false; } else { updateTerrain = true; } } // // // // if(ViewMode == DepthViewMode.MultiSourceReader) // { // ViewMode = DepthViewMode.SeparateSourceReaders; // } // else // { // ViewMode = DepthViewMode.MultiSourceReader; // } // } float yVal = Input.GetAxis("Horizontal"); float xVal = -Input.GetAxis("Vertical"); //transform.Rotate (xVal, yVal, 0.0f); if (updateTerrain == true) { if (ViewMode == DepthViewMode.SeparateSourceReaders) { if (ColorSourceManager == null) { return; } _ColorManager = ColorSourceManager.GetComponent <ColorSourceManager>(); if (_ColorManager == null) { return; } if (DepthSourceManager == null) { return; } _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>(); if (_DepthManager == null) { return; } gameObject.GetComponent <Renderer>().material.mainTexture = _ColorManager.GetColorTexture(); RefreshData(_DepthManager.GetData(), _ColorManager.ColorWidth, _ColorManager.ColorHeight); } else { if (MultiSourceManager == null) { return; } _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>(); if (_MultiManager == null) { return; } gameObject.GetComponent <Renderer>().material.mainTexture = _MultiManager.GetColorTexture(); RefreshData(_MultiManager.GetDepthData(), _MultiManager.ColorWidth, _MultiManager.ColorHeight); } } UpdateTransform(); }
void Update() { if (_Sensor == null) { return; } /*if (Input.GetButtonDown("Fire1")) * { * * if (ViewMode == DepthViewMode.MultiSourceReader) * { * ViewMode = DepthViewMode.SeparateSourceReaders; * } * else * { * ViewMode = DepthViewMode.MultiSourceReader; * } * } * * float yVal = Input.GetAxis("Horizontal"); * float xVal = -Input.GetAxis("Vertical"); * * transform.Rotate( * (xVal * Time.deltaTime * _Speed), * (yVal * Time.deltaTime * _Speed), * 0, * Space.Self);*/ if (ViewMode == DepthViewMode.SeparateSourceReaders) { if (ColorSourceManager == null) { return; } _ColorManager = ColorSourceManager.GetComponent <ColorSourceManager>(); if (_ColorManager == null) { return; } if (DepthSourceManager == null) { return; } _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>(); if (_DepthManager == null) { return; } gameObject.GetComponent <Renderer>().material.mainTexture = _ColorManager.GetColorTexture(); RefreshData(_DepthManager.GetData(), //デプスマネージャーからushortのデプスデータ取ってきてる _ColorManager.ColorWidth, _ColorManager.ColorHeight); } else { if (MultiSourceManager == null) { return; } _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>(); if (_MultiManager == null) { return; } gameObject.GetComponent <Renderer>().material.mainTexture = _MultiManager.GetColorTexture(); RefreshData(_MultiManager.GetDepthData(), //デプスマネージャーからushortのデプスデータ取ってきてる _MultiManager.ColorWidth, _MultiManager.ColorHeight); } for (int i = 0; i < detectedx.Count; i++) //複数手判定 { if (hand1x.Count == 0) { hand1x.Add(detectedx[i]); hand1y.Add(detectedy[i]); } else { if (Mathf.Abs(detectedx[i] - hand1x[0]) + Mathf.Abs(detectedy[i] - hand1y[0]) < avilabledistance) //計算量短縮のために二乗を使わないで距離判定 { hand1x.Add(detectedx[i]); hand1y.Add(detectedy[i]); } else { if (hand2x.Count == 0) { hand2x.Add(detectedx[i]); hand2y.Add(detectedy[i]); } else { if (Mathf.Abs(detectedx[i] - hand2x[0]) + Mathf.Abs(detectedy[i] - hand2y[0]) < avilabledistance) { hand2x.Add(detectedx[i]); hand2y.Add(detectedy[i]); } else { if (hand3x.Count == 0) { hand3x.Add(detectedx[i]); hand3y.Add(detectedy[i]); } else { if (Mathf.Abs(detectedx[i] - hand3x[0]) + Mathf.Abs(detectedy[i] - hand3y[0]) < avilabledistance) { hand3x.Add(detectedx[i]); hand3y.Add(detectedy[i]); } else { if (hand4x.Count == 0) { hand4x.Add(detectedx[i]); hand4y.Add(detectedy[i]); } else { if (Mathf.Abs(detectedx[i] - hand4x[0]) + Mathf.Abs(detectedy[i] - hand4y[0]) < avilabledistance) { hand4x.Add(detectedx[i]); hand4y.Add(detectedy[i]); } else { if (hand5x.Count == 0) { hand5x.Add(detectedx[i]); hand5y.Add(detectedy[i]); } else { if (Mathf.Abs(detectedx[i] - hand5x[0]) + Mathf.Abs(detectedy[i] - hand5y[0]) < avilabledistance) { hand5x.Add(detectedx[i]); hand5y.Add(detectedy[i]); } else { if (hand6x.Count == 0) { hand6x.Add(detectedx[i]); hand6y.Add(detectedy[i]); } else { if (Mathf.Abs(detectedx[i] - hand6x[0]) + Mathf.Abs(detectedy[i] - hand6y[0]) < avilabledistance) { hand6x.Add(detectedx[i]); hand6y.Add(detectedy[i]); } } } } } } } } } } } } } hand1ave(); hand2ave(); hand3ave(); hand4ave(); hand5ave(); hand6ave(); detectedx.Clear(); detectedy.Clear(); hand1x.Clear(); hand1y.Clear(); hand2x.Clear(); hand2y.Clear(); hand3x.Clear(); hand3y.Clear(); hand4x.Clear(); hand4y.Clear(); hand5x.Clear(); hand5y.Clear(); hand6x.Clear(); hand6y.Clear(); }
void Update() { if (_Sensor == null) { return; } if (ScanSceneButton.scan) { if (ViewMode == DepthViewMode.MultiSourceReader) { ViewMode = DepthViewMode.SeparateSourceReaders; ScanSceneButton.scan = false; } else { ViewMode = DepthViewMode.MultiSourceReader; ScanSceneButton.scan = false; } } float yVal = Input.GetAxis("Horizontal"); float xVal = -Input.GetAxis("Vertical"); transform.Rotate( (xVal * Time.deltaTime * _Speed), (yVal * Time.deltaTime * _Speed), 0, Space.Self); if (ViewMode == DepthViewMode.SeparateSourceReaders) { if (ColorSourceManager == null) { return; } _ColorManager = ColorSourceManager.GetComponent <ColorSourceManager>(); if (_ColorManager == null) { return; } if (DepthSourceManager == null) { return; } _DepthManager = DepthSourceManager.GetComponent <DepthSourceManager>(); if (_DepthManager == null) { return; } gameObject.GetComponent <Renderer>().material.mainTexture = _ColorManager.GetColorTexture(); RefreshData(_DepthManager.GetData(), _ColorManager.ColorWidth, _ColorManager.ColorHeight); } else { if (MultiSourceManager == null) { return; } _MultiManager = MultiSourceManager.GetComponent <MultiSourceManager>(); if (_MultiManager == null) { return; } // gameObject.GetComponent<Renderer>().material.mainTexture = _MultiManager.GetColorTexture(); RefreshData(_MultiManager.GetDepthData(), _MultiManager.ColorWidth, _MultiManager.ColorHeight); } }
void Update() { if (_Sensor == null) { return; } //點擊滑鼠右鍵切換單組資源配置或是多組資源配置。 if (Input.GetButtonDown("Fire1")) { if(ViewMode == DepthViewMode.MultiSourceReader) { ViewMode = DepthViewMode.SeparateSourceReaders; } else { ViewMode = DepthViewMode.MultiSourceReader; } } //使用上下左右鍵旋轉Mesh物件。 float yVal = Input.GetAxis("Horizontal"); float xVal = -Input.GetAxis("Vertical"); transform.Rotate( (xVal * Time.deltaTime * _Speed), (yVal * Time.deltaTime * _Speed), 0, Space.Self); //如果切換到了單組資源配置的執行工作。 if (ViewMode == DepthViewMode.SeparateSourceReaders) { if (ColorSourceManager == null) { return; } _ColorManager = ColorSourceManager.GetComponent<ColorSourceManager>(); if (_ColorManager == null) { return; } if (DepthSourceManager == null) { return; } _DepthManager = DepthSourceManager.GetComponent<DepthSourceManager>(); if (_DepthManager == null) { return; } gameObject.renderer.material.mainTexture = _ColorManager.GetColorTexture(); RefreshData(_DepthManager.GetData(), _ColorManager.ColorWidth, _ColorManager.ColorHeight); } else//如果切換到了多組資源配置的執行工作。 { if (MultiSourceManager == null) { return; } _MultiManager = MultiSourceManager.GetComponent<MultiSourceManager>(); if (_MultiManager == null) { return; } gameObject.renderer.material.mainTexture = _MultiManager.GetColorTexture(); RefreshData(_MultiManager.GetDepthData(), _MultiManager.ColorWidth, _MultiManager.ColorHeight); } }
void Update() { // get new depth data from DepthSourceManager. ushort[] rawdata = depthSourceManagerScript.GetData(); Debug.Log(rawdata.Length); if (color_reader == null) { Debug.Log("error"); } if (color_reader != null) { var Reference = color_reader.AcquireLatestFrame(); //Debug.Log(color_reader.AcquireLatestFrame()); // if (Reference == null) //{ // Reference = ColorSourceManager_copy.frame; // } if (Reference != null) { try { Reference.CopyConvertedFrameDataToArray(color_array, ColorImageFormat.Rgba); CHECK_GETDATA = true; Debug.Log(color_array.Length); Reference.Dispose(); Reference = null; } catch (Exception e) { Debug.Log(e); } } } // map to camera space coordinate //Debug.Log ("particle"); mapper.MapDepthFrameToCameraSpace(rawdata, cameraSpacePoints); mapper.MapDepthFrameToColorSpace(rawdata, colorSpacePoints); Debug.Log(colorSpacePoints.Length); for (int i = 0; i < cameraSpacePoints.Length; i++) { long colorX = float.IsInfinity(colorSpacePoints[i].X) ? 0 : (int)Mathf.Floor(colorSpacePoints[i].X); long colorY = float.IsInfinity(colorSpacePoints[i].Y) ? 0 : (int)Mathf.Floor(colorSpacePoints[i].Y); if (colorX < 0) { colorX = 0; } if (colorY < 0) { colorY = 0; } if (i % 1000 == 0) { Debug.Log("X:" + colorX + " Y:" + colorY); Debug.Log(colorSpacePoints[i].X); } long colorIndex = ((colorY * colorFrameDesc.Width) + colorX) * 4; if (CHECK_GETDATA == true) { if (colorIndex < 0) { Debug.Log("error" + colorIndex); } try { byte r = color_array[colorIndex]; byte g = color_array[colorIndex + 1]; byte b = color_array[colorIndex + 2]; byte alpha = 255; particles[i].color = new Color32(r, g, b, alpha); } catch (Exception e) { } } //if (cameraSpacePoints [i].X <= 1 && cameraSpacePoints[i].X >= -1) {//X座標の1~-1を表示 particles[i].position = new Vector3(cameraSpacePoints[i].X * scale, cameraSpacePoints[i].Y * scale, cameraSpacePoints[i].Z * scale); particles[i].size = size; //particles[i].color=new Color32(0,(byte)(cameraSpacePoints[i].Z*50),0,255); // if (rawdata [i] == 0) // particles [i].size = 0;//データの値が0ならばサイズを0にする //} else if (particles [i].position != null) {//particles[x].positionのデータが空じゃなければサイズを0にする // particles [i].size = 0; //} if (i % 10000 == 0) { //Debug.Log (particles [i].color); } } // update particle system GetComponent <ParticleSystem>().SetParticles(particles, particles.Length); }