private void MenuItem_Zoom_Click(object sender, EventArgs e)
 {
     try
     {
         zoomOption = ZoomOption.MouseMove;
         if (sender == MenuItem_ZoomFitSize)
         {
             FitSize(true);
         }
         else if (sender == MenuItem_ZoomFullSize)
         {
             FullSize(true);
         }
         else
         {
             SetScrollBarLocationBeforeZoom();
             string value_Str = ((ToolStripMenuItem)sender).Text;
             float  zoomValue = float.Parse(Regex.Match(value_Str, @"\d+").Value);
             zoomValue = zoomValue / 100;
             SetZoom(zoomValue);
         }
     }
     catch (Exception ex)
     {
         VisionLogger.Log(WaftechLibraries.Log.LogType.Exception, sender.ToString(), ex);
         VisionNotifier.AddNotification(ex.Message);
     }
 }
Example #2
0
        private static void AcqFailureCallback(MC.SIGNALINFO signalInfo)
        {
            uint currentChannel = (uint)signalInfo.Context;

            try
            {
                isImageReady = false;
            }
            catch (System.Exception ex)
            {
                VisionLogger.Log(WaftechLibraries.Log.LogType.Exception, "E2VCameraHelper", ex);
                VisionNotifier.AddNotification("System Exception: " + ex.Message);
                errorMessage = ex.Message;
            }
        }
Example #3
0
 public static void Disconnect()
 {
     try
     {
         if (isCameraConnected && channel != 0)
         {
             MC.SetParam(channel, "ChannelState", "IDLE");
         }
         VisionLogger.Log(WaftechLibraries.Log.LogType.Log, "E2VCameraHelper", "Camera Disconnected");
     }
     catch (Exception ex)
     {
         errorMessage = ex.Message;
         throw ex;
     }
 }
Example #4
0
 public static void Connect()
 {
     try
     {
         // Activating the channel
         string channelState;
         MC.GetParam(channel, "ChannelState", out channelState);
         if (channelState != "ACTIVE")
         {
             MC.SetParam(channel, "ChannelState", "ACTIVE");
         }
         isCameraConnected = true;
         VisionLogger.Log(WaftechLibraries.Log.LogType.Log, "E2VCameraHelper", "Camera Connected");
     }
     catch (Exception ex)
     {
         errorMessage = ex.Message;
         throw ex;
     }
 }
Example #5
0
        /// <summary>
        /// Find the proper settings for the given device.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="deviceConfigFile">allow using a custom devices for testing.</param>
        public void Init(VisionLogger logger, string deviceConfigFile)
        {
            Logger = logger;

            persistentDataStorage = new PersistentDataStorage(Game.ForceVision);

            // Hardware
            TextAsset headsets = Resources.Load <TextAsset>("Profiles/headset_list");

            if (headsets == null)
            {
                Log.Error("Error: Fail to load hardware list");
                return;
            }

            HeadsetList = JsonUtility.FromJson <HeadsetList>(headsets.text);

            HeadsetSettings = GetRecomendedSettingsForHeadset();

            // Devices
            string devices = LoadFromCdnOrSdkResources(deviceConfigFile);

            if (devices == null)
            {
                Log.Error("Error: Fail to load device list " + deviceConfigFile);
                return;
            }
            DeviceList = JsonUtility.FromJson <Devices>(devices);

            PlatformName = (Application.platform == RuntimePlatform.IPhonePlayer) ? "iOS" : "Android";

                        #if UNITY_EDITOR
            PlatformName = EditorPlatform;
                        #endif

            DeviceSettings = GetRecomendedSettingsForDevice();
            Log.Debug("JCSettingsManager inited with " + CurrentDevice.Name + " supported " + HasDeviceProfile);
        }
Example #6
0
 /// <summary>
 /// Find the proper settings for the given device.
 /// </summary>
 /// <param name="logger">The logger.</param>
 public override void Init(VisionLogger logger)
 {
     Init(logger, DeviceConfig);
 }
        /// <summary>
        /// Calculate the midpoint of point1 and point2
        /// Draw a line from the midpoint to referencePoint
        ///
        /// CCW -> positive
        /// CW  -> negative
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <returns></returns>
        public static double Execute(
            PointF p1,
            PointF p2,
            PointF centerpoint,
            double referenceAngle_deg,
            bool IsConvertToDegree,
            WaferOrientation patternOrientation)
        {
            VisionLogger.Log(WaftechLibraries.Log.LogType.Log,
                             "CalculateAngleBetween3Points",
                             "Calculate Angle Between Three Points Started");

            double midPointX = (p1.X + p2.X) / 2.0;
            double midPointY = (p1.Y + p2.Y) / 2.0;
            double centerX   = centerpoint.X;
            double centerY   = centerpoint.Y;

            double deltaX = midPointX - centerX;
            double deltaY = midPointY - centerY;
            double theta_rad;

            if (patternOrientation == WaferOrientation.Bottom)
            {
                if (deltaX < 0)
                {
                    theta_rad = Math.Atan(Math.Abs(deltaX / deltaY));
                }                                                                         // CCW
                else
                {
                    theta_rad = -Math.Atan(Math.Abs(deltaX / deltaY));
                }                                                                         // CW
            }
            else if (patternOrientation == WaferOrientation.Right)
            {
                if (deltaY > 0)
                {
                    theta_rad = Math.Atan(Math.Abs(deltaY / deltaX));
                }                                                                        // CCW
                else
                {
                    theta_rad = -Math.Atan(Math.Abs(deltaY / deltaX));
                }                                                                        // CW
            }
            else if (patternOrientation == WaferOrientation.Top)
            {
                if (deltaX > 0)
                {
                    theta_rad = Math.Atan(Math.Abs(deltaX / deltaY));
                }                                                                         // CCW
                else
                {
                    theta_rad = -Math.Atan(Math.Abs(deltaX / deltaY));
                }                                                                         // CW
            }

            else if (patternOrientation == WaferOrientation.Left)
            {
                if (deltaY < 0)
                {
                    theta_rad = Math.Atan(Math.Abs(deltaY / deltaX));
                }                                                                        // CCW
                else
                {
                    theta_rad = -Math.Atan(Math.Abs(deltaY / deltaX));
                }                                                                        // CW
            }

            else
            {
                throw new Exception("Invalid notch Orientation");
            }

            double thetaOffset_rad;

            thetaOffset_rad = theta_rad - ConvertToRad(referenceAngle_deg);
            if (IsConvertToDegree)
            {
                return(ConvertToDeg(thetaOffset_rad));
            }
            else
            {
                return(thetaOffset_rad);
            }
        }
        public static bool TeachTeacherROI(
            string RecipeName,
            EuresysDoublePatternMatcher PatternMatcher_,
            PatternMatcherParameters PatternMatcherParameters_,
            EROIBW8 eROIForPatternTeaching1_,
            EROIBW8 eROIForPatternTeaching2_,
            iEuresysROI MatcherEROI,
            PointF WaferCenterPoint,
            WaferOrientation patternOrientation)
        {
            string PatternFilePath_One      = PatternMatcherParameterHelper.GetLeftPatternFilePath(RecipeName);
            string PatternFilePath_Two      = PatternMatcherParameterHelper.GetRightPatternFilePath(RecipeName);
            string PatternImageFilePath_One = PatternMatcherParameterHelper.GetLeftPatternImageFilePath(RecipeName);
            string PatternImageFilePath_Two = PatternMatcherParameterHelper.GetRightPatternImageFilePath(RecipeName);

            PatternMatcher_.TeachAndSaveEMatcher(
                PatternMatcherParameters_,
                eROIForPatternTeaching1_,
                eROIForPatternTeaching2_,
                PatternFilePath_One,
                PatternFilePath_Two,
                PatternImageFilePath_One,
                PatternImageFilePath_Two);

            if (PatternMatcher_.Pattern1.IsVoid)
            {
                goto Fail;
            }
            if (PatternMatcher_.Pattern2.IsVoid)
            {
                goto Fail;
            }

            // Match
            EROIBW8 matcherROI = MatcherEROI.GetROI(0);

            PatternMatcher_.MatchPatterns(matcherROI);

            EMatcher eMatcher1 = PatternMatcher_.EMatcher1;
            EMatcher eMatcher2 = PatternMatcher_.EMatcher2;

            if (eMatcher1.NumPositions != 1)
            {
                string errorMessage = "Pattern 1: Number of patterns matched is not equal to one";
                VisionLogger.Log(LogType.Exception, "PatternMatcherManager", errorMessage);
                VisionNotifier.AddNotification(errorMessage);
                goto Fail;
            }

            if (eMatcher2.NumPositions != 1)
            {
                string errorMessage = "Pattern 2: Number of patterns matched is not equal to one";
                VisionLogger.Log(LogType.Exception, "PatternMatcherManager", errorMessage);
                VisionNotifier.AddNotification(errorMessage);
                goto Fail;
            }

            EROIBW8 matcherEROI_1 = MatcherEROI.GetROI(0);

            float OriginalXPos_pattern1 = eMatcher1.GetPosition(0).CenterX + (matcherEROI_1.OrgX);
            float OriginalYPos_pattern1 = eMatcher1.GetPosition(0).CenterY + (matcherEROI_1.OrgY);
            float OriginalXPos_pattern2 = eMatcher2.GetPosition(0).CenterX + (matcherEROI_1.OrgX);
            float OriginalYPos_pattern2 = eMatcher2.GetPosition(0).CenterY + (matcherEROI_1.OrgY);
            float WaferCenterXPos       = WaferCenterPoint.X;
            float WaferCenterYPos       = WaferCenterPoint.Y;

            PointF p1 = new PointF(OriginalXPos_pattern1, OriginalYPos_pattern1);
            PointF p2 = new PointF(OriginalXPos_pattern2, OriginalYPos_pattern2);
            float  PatternDefaultAngleOffset = (float)CalculateAngleBetween3Points.Execute(
                p1,
                p2,
                WaferCenterPoint,
                0,
                true,
                patternOrientation);

            // Replace value
            PatternMatcherParameters_.OriginalXPos_pattern1 = OriginalXPos_pattern1;
            PatternMatcherParameters_.OriginalYPos_pattern1 = OriginalYPos_pattern1;
            PatternMatcherParameters_.OriginalXPos_pattern2 = OriginalXPos_pattern2;
            PatternMatcherParameters_.OriginalYPos_pattern2 = OriginalYPos_pattern2;
            PatternMatcherParameters_.WaferCenterXPos       = WaferCenterXPos;
            PatternMatcherParameters_.WaferCenterYPos       = WaferCenterYPos;
            PatternMatcherParameters_.DefaultAngleOffset    = PatternDefaultAngleOffset;
            return(true);

Fail:
            return(false);
        }
        /// <summary>
        /// Calculate angle from point 1 to point 2, point 1 as origin
        ///
        /// Positive/Negative
        /// (0,0) -- | (X,0) +-
        /// (0,Y) -+ | (X,Y) ++
        ///
        /// Quadrant
        /// 3rd | 4th
        /// 2nd | 1st
        ///
        /// Rotation
        /// Positive offset -> rotateCCW
        /// Negative offset -> rotateCW
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <returns></returns>
        public static double Execute(
            Point p1,
            Point p2,
            bool IsConvertToDegree)
        {
            VisionLogger.Log(WaftechLibraries.Log.LogType.Log, "CalculateAngleBetweenTwoPoints", "Calculate Angle Between Two Points Started");

            double angle_rad    = 0;
            double angle_deg_CW = 0;
            double deltaX;
            double deltaY;

            // 1st quadrant
            //      |
            //      |
            // ____ p1 ____
            //      |
            //      |    p2
            //
            // Rotate CCW to remove offset
            if (p2.X >= p1.X && p2.Y >= p1.Y)
            {
                VisionLogger.Log(
                    WaftechLibraries.Log.LogType.Log,
                    "CalculateAngleBetweenTwoPoints",
                    "Point 2 falls on first quadrant");

                deltaY    = p2.Y - p1.Y;
                deltaX    = p2.X - p1.X;
                angle_rad = Math.Atan(deltaY / deltaX);
                if (angle_rad < 0)
                {
                    throw new Exception("angle_rad should be positive");
                }
            }

            // 2nd quadrant
            //      |
            //      |
            // ____ p1 ____
            //      |
            // p2   |
            else if (p2.X < p1.X && p2.Y >= p1.Y)
            {
                VisionLogger.Log(
                    WaftechLibraries.Log.LogType.Log,
                    "CalculateAngleBetweenTwoPoints",
                    "Point 2 falls on second quadrant");

                throw new Exception("point 2 should not be in 2nd quadrant");
                //deltaY = p2.Y - p1.Y;
                //deltaX = -(p2.X - p1.X);
                //angle_rad_CW = Math.PI - Math.Atan(deltaY / deltaX);
                //if(angle_rad_CW > 0) throw new Exception("angle_rad_CW should be negative");
            }

            // 3rd quadrant
            // p2   |
            //      |
            // ____ p1 ____
            //      |
            //      |
            else if (p2.X < p1.X && p2.Y < p1.Y)
            {
                VisionLogger.Log(
                    WaftechLibraries.Log.LogType.Log,
                    "CalculateAngleBetweenTwoPoints",
                    "Point 2 falls on third quadrant");

                throw new Exception("point 2 should not be in 3rd quadrant");

                //deltaY = p2.Y - p1.Y;
                //deltaX = p2.X - p1.X;
                //angle_rad_CW = Math.Atan(deltaY / deltaX);
                //if (angle_rad_CW > 0) throw new Exception("angle_rad_CW should be negative");
            }

            // 4th quadrant
            //      |    p2
            //      |
            // ____ p1 ____
            //      |
            //      |
            // Rotate CW to remove offset
            else if (p2.X >= p1.X && p2.Y - p1.Y < 0)
            {
                VisionLogger.Log(
                    WaftechLibraries.Log.LogType.Log,
                    "CalculateAngleBetweenTwoPoints",
                    "Point 2 falls on fourth quadrant");

                deltaY    = -(p2.Y - p1.Y);
                deltaX    = (p2.X - p1.X);
                angle_rad = -(Math.Atan(deltaY / deltaX));
                if (angle_rad > 0)
                {
                    throw new Exception("angle_rad should be negative");
                }
            }

            angle_rad    = -angle_rad;
            angle_deg_CW = ConvertToDeg(angle_rad);

            if (IsConvertToDegree)
            {
                return(angle_deg_CW);
            }
            else
            {
                return(angle_rad);
            }
        }
Example #10
0
        private static void ProcessingCallback(MC.SIGNALINFO signalInfo)
        {
            isImageReady = false;

            UInt32 currentChannel = (UInt32)signalInfo.Context;

            currentSurface = signalInfo.SignalInfo;

            // + GrablinkSnapshotTrigger Sample Program

            try
            {
                // Update the image with the acquired image buffer data
                Int32  width, height, bufferPitch;
                IntPtr bufferAddress;
                MC.GetParam(currentChannel, "ImageSizeX", out width);
                MC.GetParam(currentChannel, "ImageSizeY", out height);
                MC.GetParam(currentChannel, "BufferPitch", out bufferPitch);
                MC.GetParam(currentSurface, "SurfaceAddr", out bufferAddress);

                try
                {
                    imageMutex.WaitOne();

                    image  = new System.Drawing.Bitmap(width, height, bufferPitch, PixelFormat.Format8bppIndexed, bufferAddress);
                    imgpal = image.Palette;

                    // Build bitmap palette Y8
                    for (uint i = 0; i < 256; i++)
                    {
                        imgpal.Entries[i] = Color.FromArgb(
                            (byte)0xFF,
                            (byte)i,
                            (byte)i,
                            (byte)i);
                    }

                    image.Palette = imgpal;

                    string path_directory = @"D:\Waftech\BDMVision\Log\Temp\";
                    System.IO.Directory.CreateDirectory(path_directory);
                    string fullPath = path_directory + "test.jpg";

                    image.Save(fullPath);
                    eImage = new EImageBW8();
                    eImage.SetSize(image.Width, image.Height);
                    eImage.Load(fullPath);
                }
                finally
                {
                    imageMutex.ReleaseMutex();
                }

                isImageReady = true;

                // Retrieve the frame rate
                double frameRate_Hz;
                MC.GetParam(channel, "PerSecond_Fr", out frameRate_Hz);

                // Retrieve the channel state
                string channelState;
                MC.GetParam(channel, "ChannelState", out channelState);

                // Log frame rate and channel state
                VisionLogger.Log(WaftechLibraries.Log.LogType.Log, "E2VCameraHelper", string.Format("Frame Rate: {0:f2}, Channel State: {1}", frameRate_Hz, channelState));
            }
            catch (Euresys.MultiCamException ex)
            {
                VisionLogger.Log(WaftechLibraries.Log.LogType.Exception, "E2VCameraHelper", ex);
                VisionNotifier.AddNotification("MultiCam Exception: " + ex.Message);
                errorMessage = "MultiCam Exception: " + ex.Message;
            }
            catch (System.Exception ex)
            {
                VisionLogger.Log(WaftechLibraries.Log.LogType.Exception, "E2VCameraHelper", ex);
                VisionNotifier.AddNotification("System Exception: " + ex.Message);
                errorMessage = "System Exception: " + ex.Message;
            }
        }