예제 #1
0
 /// <summary>
 /// detect bulb flicker
 /// </summary>
 /// <param name="cam">camera object, derive from openCamera()</param>
 /// <param name="h**o">derive from getAlignment()</param>
 /// <param name="detectionDurationMs">detection duration in msec</param>
 /// <param name="leastFlikerCount">least filker times</param>
 /// <param name="threshold">bulb threshold, smaller value are more sensitive to noise. 0-255</param>
 /// <param name="erodeTimes">erode filter</param>
 /// <param name="debug">if true, will show intermediate debug image</param>
 /// <returns>Points array contains bulb cordinate</returns>
 public static MarkerManager.BulbPoint[] detectFilcker(VideoCapture cam,
                                                       MarkerManager.HomoTrans h**o,
                                                       int detectionDurationMs, int leastFlikerCount,
                                                       int threshold = 80, int erodeTimes = 2,
                                                       bool debug    = false)
 {
     return(MarkerManager.findFlicker(cam, h**o, detectionDurationMs, leastFlikerCount,
                                      threshold, erodeTimes, debug));
 }
예제 #2
0
        /// <summary>
        /// align an image and save the aligned image to file
        /// </summary>
        /// <param name="originImagePath">input image</param>
        /// <param name="alignedImageSavePath">output image path</param>
        /// <param name="h**o">homography, using getHomo() to obtain one</param>
        /// <param name="debug">if true, will show intermediate debug image</param>
        public static void getAlignedImage(string originImagePath, string alignedImageSavePath,
                                           MarkerManager.HomoTrans h**o, bool debug = false)
        {
            Image <Bgr, byte> img        = new Image <Bgr, byte>(originImagePath);
            Image <Bgr, byte> alignedImg = MarkerManager.getAlignedImage(img, h**o);

            alignedImg.Save(alignedImageSavePath);
            if (debug)
            {
                CvInvoke.Imshow("aligned img", alignedImg);
            }
        }
예제 #3
0
        /// <summary>
        /// detect bulb from a new image and aligned image get from getAlignment().
        /// </summary>
        /// <param name="alignedImgPath">derive from getAlignment()</param>
        /// <param name="h**o">derive from getAlignment()</param>
        /// <param name="compareImgPath">new image to compare with</param>
        /// <param name="threshold">bulb threshold, smaller value are more sensitive to noise. 0-255</param>
        /// <param name="erodeTimes">erode filter</param>
        /// <param name="debug">if true, will show intermediate debug image</param>
        /// <returns>
        /// MarkerManager.BulbPoint[][] { (BulbPoint[])litBulbs, (BulbPoint[])litoffBulbs }
        /// </returns>
        public static MarkerManager.BulbPoint[][] detectBulb(
            string alignedImgPath, MarkerManager.HomoTrans h**o,
            string compareImgPath, int threshold = 80, int erodeTimes = 2,
            bool debug = false)
        {
            Image <Bgr, byte> alignedImg = new Image <Bgr, byte>(alignedImgPath);
            Image <Bgr, byte> compareImg = new Image <Bgr, byte>(compareImgPath);

            compareImg = MarkerManager.getAlignedImage(compareImg, h**o);
            MarkerManager.BulbPoint[] lit = MarkerManager.findBulb(
                compareImg.Sub(alignedImg), threshold, erodeTimes, debug);
            MarkerManager.BulbPoint[] litoff = MarkerManager.findBulb(
                alignedImg.Sub(compareImg), threshold, erodeTimes, debug);
            return(new MarkerManager.BulbPoint[][] { lit, litoff });
        }
예제 #4
0
        /// <summary>
        /// calculate homography transformation struct
        /// </summary>
        /// <param name="originImagePath">input image</param>
        /// <param name="markerLowRange">marker detection low hue range</param>
        /// <param name="markerHighRange">marker detection high hue range</param>
        /// <param name="resolution">
        /// expected resolution of the markered rectangle,
        /// while using Size.Empty, adaptive size will applied (not precise in lenght-width ratio)</param>
        /// <param name="zoomX">
        /// homography zoom ratio, smaller value means draw closer to the plane.
        /// 1.0 is default. Must greater than 0.</param>
        /// <param name="offsetX">homography offset X in pixel</param>
        /// <param name="offsetY">homography offset Y in pixel</param>
        /// <param name="markerErodeTimes">marker erode filter times</param>
        /// <param name="debug">if true, will show intermediate debug image</param>
        /// <returns>
        /// if four and only four markers are found, a HomoTrans struct will be returned.
        /// Otherwise, an empty homotrans struct will be returned.
        /// Set debug=true to adjust input parameters.
        /// </returns>
        public static MarkerManager.HomoTrans getHomo(string originImagePath,
                                                      Hsv markerLowRange, Hsv markerHighRange, Size resolution,
                                                      float zoomX          = 1.0f, float zoomY = 1.0f, int offsetX = 0, int offsetY = 0,
                                                      int markerErodeTimes = 2,
                                                      bool debug           = false)
        {
            Image <Bgr, byte> img = new Image <Bgr, byte>(originImagePath);
            MarkerManager     mm  = new MarkerManager();

            Point[] pts = MarkerManager.findMarkers(img,
                                                    markerLowRange, markerHighRange, markerErodeTimes, debug);
            MarkerManager.HomoTrans h**o = MarkerManager.getHomography(
                img, pts, resolution, zoomX, zoomY, offsetX, offsetY);
            return(h**o);
        }