Esempio n. 1
0
            public void removeNext()            //head의 next포인트를 삭제
            {
                TouchPoint T = next();

                if (T == null)
                {
                    return;
                }
                //this.nextPoint = null;
                T.setX(-10.0);
                T.setY(-10.0);
                this.nextPoint = T.next();
                //T.nextPoint = null;
            }
Esempio n. 2
0
        private void nui_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())
            {
                if (depthImageFrame != null)
                {
                    depthImageFrame.CopyDepthImagePixelDataTo(depthPixels);


                    int minDepth = depthImageFrame.MinDepth;
                    int maxDepth = depthImageFrame.MaxDepth;
                    if (init == true)
                    {
                        depthImageFrame.CopyDepthImagePixelDataTo(initDepthPixels);

                        /*
                         * for (int i = 0; i < depthPixels.Length; ++i)
                         * {
                         *  if (i % 640 == 0 || i % 640 == 1 || i % 640 == 638 || i % 640 == 639)
                         *      continue;
                         *  initDepthPixels[i].Depth = (short)((depthPixels[i - 2].Depth + depthPixels[i - 1].Depth + depthPixels[i].Depth + depthPixels[i + 1].Depth + depthPixels[i + 2].Depth) / 5.0);
                         * }*/
                        init = false;
                    }
                    int colorPixelIndex = 0;

                    for (int i = 0; i < depthPixels.Length; ++i)                //depth값에 따라 색깔을 달리해서 출력한다.
                    {                                                           //최초 인식된 벽값과 비교하여 터치가 일어났을 경우 빨간색으로 출력하고
                        short currentDepth     = depthPixels[i].Depth;          //최초 인식된 벽값과 같을경우 파란색으로 표시한다.
                        short initDepth        = initDepthPixels[i].Depth;
                        byte  currentIntensity = (byte)(currentDepth >= minDepth && currentDepth <= maxDepth ? currentDepth : 0);
                        byte  initIntensity    = (byte)(initDepth >= minDepth && initDepth <= maxDepth ? initDepth : 0);
                        short subDepth         = (short)(initDepth - currentDepth);


                        /*
                         * if (0 <= subDepth && subDepth < 15)
                         * {
                         *  colorPixels[colorPixelIndex++] = colorMap[subDepth, 0];
                         *  colorPixels[colorPixelIndex++] = colorMap[subDepth, 1];
                         *  colorPixels[colorPixelIndex++] = colorMap[subDepth, 2];
                         * }
                         * else
                         * {
                         *  colorPixels[colorPixelIndex++] = 255;
                         *  colorPixels[colorPixelIndex++] = 0;
                         *  colorPixels[colorPixelIndex++] = 0;
                         * }
                         */


                        if (subDepth < 0)
                        {
                            subDepth = 0;
                        }
                        if (0 <= subDepth && subDepth <= 10)      //initDepth - currentDepth < 3)//initIntensity - currentIntensity == 0)
                        {
                            colorPixels[colorPixelIndex++] = 255; //(byte)(initIntensity - currentIntensity);
                            colorPixels[colorPixelIndex++] = 0;   // (byte)(initIntensity - currentIntensity);
                            colorPixels[colorPixelIndex++] = 0;   // (byte)(initIntensity - currentIntensity);
                        }
                        else if (10 < subDepth && subDepth <= 15)
                        {
                            colorPixels[colorPixelIndex++] = 0;   //(byte)(initIntensity - currentIntensity);
                            colorPixels[colorPixelIndex++] = 0;   // (byte)(initIntensity - currentIntensity);
                            colorPixels[colorPixelIndex++] = 255; // (byte)(initIntensity - currentIntensity);
                        }
                        else
                        {
                            colorPixels[colorPixelIndex++] = 0; //(byte)(initIntensity - currentIntensity);
                            colorPixels[colorPixelIndex++] = 0; // (byte)(initIntensity - currentIntensity);
                            colorPixels[colorPixelIndex++] = 0; // (byte)(initIntensity - currentIntensity);
                        }
                        ++colorPixelIndex;
                    }
                    for (int i = 0; i < depthPixels.Length; ++i)        //모든 픽셀들에서 검사한다.
                    {
                        if (pointCnt > 5)
                        {
                            break;
                        }
                        if (colorPixels[i * 4 + 1] == 0 && colorPixels[i * 4 + 2] == 255 && i % 640 >= 159 && i % 640 <= 479 && i / 640 >= 119 && i / 640 <= 359) //필요한 부분만 검사한다.
                        {
                            setPoint(i);                                                                                                                          //
                            if (pixelCnt > 30)                                                                                                                    //&& pixelCnt < 100)         //빨간색 픽셀이 30개 이상 검출된 포인트의 경우
                            {                                                                                                                                     //새로고침 해주거나 최초의 포인트인경우 add해준다.
                                if (head.next() != null)
                                {
                                    refresh(s_Row / pixelCnt, s_Col / pixelCnt);
                                }
                                else
                                {
                                    add(s_Row / pixelCnt, s_Col / pixelCnt);
                                }
                            }
                            s_Row    = 0;
                            s_Col    = 0;
                            pixelCnt = 0;
                        }
                    }

                    removeNoneExist();          //없어진 포인트를 지운다.
                    setEllipse();
                    if (head.next() != null)
                    {
                        textBox1.Text = string.Format("( {0:0.00}, {1:0.00}, {2:0.00}))", head.next().getX(), head.next().getY(), f);
                        if (head.next().next() != null)
                        {
                            textBox2.Text = string.Format("( {0:0.00}, {1:0.00})", head.next().next().getX(), head.next().next().getY());
                            if (head.next().next().next() != null)
                            {
                                textBox3.Text = string.Format("( {0:0.00}, {1:0.00})", head.next().next().next().getX(), head.next().next().next().getY());
                            }
                        }
                    }

                    colorBitmap.WritePixels(new Int32Rect(0, 0, colorBitmap.PixelWidth, colorBitmap.PixelHeight), colorPixels, colorBitmap.PixelWidth * sizeof(int), 0);
                }
            }
        }