示例#1
0
        public (int, int) TestCC(NPPImage_32fC1 img, int shiftX, int shiftY)
        {
            Matrix3x3 mat = Matrix3x3.ShiftAffine(shiftX, shiftY);

            img.WarpAffine(imgToTrackRotated, mat.ToAffine(), InterpolationMode.NearestNeighbor);

            forward.Exec(imgToTrackRotated.DevicePointerRoi, imgToTrackCplx.DevicePointer);
            conjKernel.RunSafe(imgRefCplx, imgToTrackCplx);
            fftshiftKernel.RunSafe(imgToTrackCplx, width, height);
            backward.Exec(imgToTrackCplx.DevicePointer, img.DevicePointerRoi);
            img.Div(img.WidthRoi * img.HeightRoi);

            img.MaxIndex(val, x, y);

            float v  = val;
            int   hx = x;
            int   hy = y;

            hx -= imgToTrackRotated.WidthRoi / 2;
            hy -= imgToTrackRotated.HeightRoi / 2;


            CudaDeviceVariable <float> minVal = new CudaDeviceVariable <float>(x.DevicePointer, 4);
            CudaDeviceVariable <float> maxVal = new CudaDeviceVariable <float>(y.DevicePointer, 4);

            img.MinMax(minVal, maxVal, buffer);
            float min = minVal;
            float max = maxVal;

            img.Sub(min);
            img.Div(max - min);


            img.ThresholdLTGT(0, 0, 1, 1);

            return(hx, hy);
        }
示例#2
0
        public double4 ScanAngles(NPPImage_32fC1 img, double incr, double range, double zero)
        {
            NppiRect saveRoi = new NppiRect(img.PointRoi, img.SizeRoi);
            NppiRect roi     = new NppiRect();

            roi.x      = 0;
            roi.y      = 0;
            roi.width  = imgToTrackRotated.WidthRoi;
            roi.height = imgToTrackRotated.HeightRoi;
            img.SetRoi(roi);

            double maxVal = -double.MaxValue;
            double maxAng = 0;
            double maxX   = 0;
            double maxY   = 0;

            //first perform a coarse search
            for (double ang = zero - range; ang <= zero + range; ang += 5 * incr)
            {
                Matrix3x3 mat = Matrix3x3.RotAroundCenter(ang, imgToTrackRotated.Width, imgToTrackRotated.Height);
                imgToTrackRotated.Set(0);
                img.WarpAffine(imgToTrackRotated, mat.ToAffine(), InterpolationMode.Cubic);

                forward.Exec(imgToTrackRotated.DevicePointerRoi, imgToTrackCplx.DevicePointer);

                conjKernel.RunSafe(imgRefCplx, imgToTrackCplx);
                backward.Exec(imgToTrackCplx.DevicePointer, imgToTrackRotated.DevicePointerRoi);
                imgToTrackRotated.Div(imgToTrackRotated.WidthRoi * imgToTrackRotated.HeightRoi);

                imgToTrackRotated.MaxIndex(val, x, y);
                float v  = val;
                int   hx = x;
                int   hy = y;
                //Console.WriteLine("Found Max at " + ang.ToString("0.000") + " deg (" + hx + ", " + hy + ") = " + v);
                if (v > maxVal)
                {
                    maxVal = v;
                    maxAng = ang;
                    maxX   = x;
                    maxY   = y;
                    //Console.WriteLine("Max set!");
                }
            }

            zero  = maxAng;
            range = 10 * incr;
            //now perform a fine search but only around the previously found peak
            for (double ang = zero - range; ang <= zero + range; ang += incr)
            {
                Matrix3x3 mat = Matrix3x3.RotAroundCenter(ang, imgToTrackRotated.Width, imgToTrackRotated.Height);
                imgToTrackRotated.Set(0);
                img.WarpAffine(imgToTrackRotated, mat.ToAffine(), InterpolationMode.Cubic);

                int fftWidth = width / 2 + 1;
                forward.Exec(imgToTrackRotated.DevicePointerRoi, imgToTrackCplx.DevicePointer);
                conjKernel.RunSafe(imgRefCplx, imgToTrackCplx);
                backward.Exec(imgToTrackCplx.DevicePointer, imgToTrackRotated.DevicePointerRoi);
                imgToTrackRotated.Div(imgToTrackRotated.WidthRoi * imgToTrackRotated.HeightRoi);

                imgToTrackRotated.MaxIndex(val, x, y);

                float v  = val;
                int   hx = x;
                int   hy = y;
                if (v > maxVal)
                {
                    maxVal = v;
                    maxAng = ang;
                    maxX   = x;
                    maxY   = y;
                    //Console.WriteLine("Found Max at " + ang.ToString("0.000") + " deg (" + hx + ", " + hy + ") = " + v);
                    //Console.WriteLine("Max set!");
                }
            }

            if (maxX > imgToTrackRotated.WidthRoi / 2)
            {
                maxX -= imgToTrackRotated.WidthRoi;
            }
            if (maxY > imgToTrackRotated.HeightRoi / 2)
            {
                maxY -= imgToTrackRotated.HeightRoi;
            }

            img.SetRoi(saveRoi);
            return(new double4(-maxX, -maxY, maxAng, maxVal));
        }