Esempio n. 1
0
        public Scanner(DeviceController device, double platformStep, VideoCaptureDevice camera, HighlitedPointDetector pointDetector, PointScanner pointScanner, Cylinder cylinder)
        {
            Device        = device;
            PlatformStep  = platformStep;
            Camera        = camera;
            PointDetector = pointDetector;
            PointScanner  = pointScanner;
            Cylinder      = cylinder;

            FrameRequested   = false;
            camera.NewFrame += Camera_NewFrame;
        }
Esempio n. 2
0
        private void HandleNewFrame(Bitmap frame)
        {
            var       unmanaged       = UnmanagedImage.FromManagedImage(frame);
            Grayscale grayscaleFilter = new Grayscale(1, 0, 0);
            var       grayscaleUnm    = grayscaleFilter.Apply(unmanaged);

            float      rotationAngle = (float)(-Slices.Count * PlatformStep);
            Quaternion rotation      = Quaternion.CreateFromYawPitchRoll(rotationAngle, 0, 0);

            Vector2[] points        = PointDetector.FindHighlitedPoints(grayscaleUnm.ImageData, frame.Width, frame.Height);
            var       sliceVertices = from point in points
                                      select PointScanner.ConvertTo3D(point, frame.Width, frame.Height) into vertex
                                          where Cylinder.Contains(vertex)
                                      select Vector3.Transform(vertex, rotation);

            AddSlice(sliceVertices.ToArray());
        }
Esempio n. 3
0
        private void CopyTexture(Bitmap frame, int stripeIndex, double modelRotation)
        {
            FaceInfo[] faces = Stripes[stripeIndex];

            int        w        = Texture.Width - 1;
            int        h        = Texture.Height - 1;
            Quaternion rotation = Quaternion.CreateFromYawPitchRoll((float)modelRotation, 0, 0);
            BitmapData data     = frame.LockBits(new Rectangle(Point.Empty, frame.Size), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

            foreach (var face in faces)
            {
                Triangle src = Triangle.FromVertices(
                    from info in face
                    select Vector3.Transform(Vertices[info.VertexIndex], rotation) into vertex
                    select PointScanner.ConvertTo2D(vertex, frame.Width, frame.Height));
                Triangle dst = Triangle.FromVertices(
                    from info in face
                    select TexVertices[info.TextureIndex] into point
                    select new Vector2(w * point.X, h * (1 - point.Y)));
                src.MapTexture(data, TextureData, dst);
            }

            frame.UnlockBits(data);
        }