コード例 #1
0
        /// <summary>
        /// 背光不规则区域基准值保存
        /// </summary>
        /// <param name="index"></param>
        /// <param name="cellName"></param>
        /// <param name="htResult"></param>
        /// <returns></returns>
        public StateComprehensive_enum CalibStdValue(int index, string cellName, out Hashtable htResult)
        {
            htResult = null;
            try
            {
                StateComprehensive_enum stateComprehensive_e = g_BaseDealComprehensive.DealComprehensivePosNoDisplay(
                    g_UCDisplayCamera, g_HtUCDisplay, 1, out htResult);
                ResultBlob resultBlob = (ResultBlob)htResult[cellName];

                if (!DealTypeResult(resultBlob))
                {
                    ShowState(string.Format("精定位自动标定第{0}点拍照失败", index + 1));
                    return(StateComprehensive_enum.False);
                }
                //保存当前匹配结果
                pt2Calib[index] = new Point2D(resultBlob.X, resultBlob.Y);

                if (index == 1)
                {
                    LogicRobot.L_I.WriteRobotCMD(ModelParams.cmd_PreciseCalib2);

                    //第二次的话保存基准值到算子中
                    if (!(RecordStdValue(cellName, pt2Calib[0], pt2Calib[1])))
                    {
                        return(StateComprehensive_enum.False);
                    }
                }
                else
                {
                    ShowState(string.Format("相机{0}基准值标定第1点计算成功", g_NoCamera));
                    LogicRobot.L_I.WriteRobotCMD(ModelParams.cmd_PreciseCalib1);
                }

                return(StateComprehensive_enum.True);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(StateComprehensive_enum.False);
            }
        }
コード例 #2
0
ファイル: ZipfLearningModel.cs プロジェクト: boobooo42/LX4
        public void Run()
        {
            /* Read from the corpus */
            var corpusBlob = m_context.CorpusBlobRepository
                             .GetByCorpusID(m_corpusID);

            /* Iterate over all corpus content */
            m_progress = 0.0f;
            var dictionary = new SortedDictionary <string, RankFrequencyPair>();

            for (int i = 0; i < corpusBlob.Content.Count(); ++i)
            {
                var cont = corpusBlob.Content[i];

                /* Note that we only have the content hash at this point. We
                 * must retrieve the actual content from the
                 * ContentBlobRepository. */
                var content =
                    m_context.ContentBlobRepository.GetByHash(cont.Hash);
                var text = content.Contents;

                /* TODO: We split the text into words and compute the frequency
                 * of each */
                /* From: http://stackoverflow.com/a/16734675 */
                var punctuation = text.Where(Char.IsPunctuation).Distinct().ToArray();
                var words       = text.Split().Select(x => x.Trim(punctuation));
                foreach (var word in words)
                {
                    if (!dictionary.ContainsKey(word))
                    {
                        dictionary.Add(word, new RankFrequencyPair(
                                           word, /* name */
                                           -1,   /* rank */
                                           0     /* frequency */
                                           ));
                    }
                    dictionary[word].Frequency += 1;
                }
                m_progress = 0.9f * ((float)i / (float)corpusBlob.Content.Count());
            }

            /* We sort the words by frequency to determine the rank of each
             * word */
            var rankedWords = dictionary.Values.OrderBy(word => word.Frequency);

            m_progress = 0.93f;
            int j = 0;

            foreach (var word in rankedWords)
            {
                word.Rank = rankedWords.Count() - j;
                j        += 1;
            }
            m_progress = 0.96f;

            /* TODO: Implement thread safety here */
            m_words    = new List <RankFrequencyPair>(rankedWords);
            m_progress = 1.0f;

            /* Store the result in the Merkle tree */
            var resultBlob = new ResultBlob(this.Result);

            resultBlob.Children = new List <MerkleNode> {
                corpusBlob
            };
            resultBlob.Pinned = true;  /* Not subject to garbage collection */
            m_context.ResultBlobRepository.Add(resultBlob);

            this.Status = "done";
        }
コード例 #3
0
        public bool BlobAngleCalc(string cellName, out Hashtable htResult)
        {
            htResult = null;
            double[] dblResult = new double[2];
            bool     blResult  = true;

            try
            {
                #region 空跑
                if (ParStateSoft.StateMachine_e == StateMachine_enum.NullRun)
                {
                    ShowState(string.Format("相机{0}空跑,默认发送OK", g_NoCamera));
                    LogicRobot.L_I.WriteRobotCMD(ModelParams.PrecisePos, ModelParams.cmd_PreciseAngle);
                    return(true);
                }
                #endregion

                StateComprehensive_enum stateComprehensive_e = g_BaseDealComprehensive.DealComprehensivePosNoDisplay(
                    g_UCDisplayCamera, g_HtUCDisplay, Pos_enum.Pos1, out htResult);
                ResultBlob resultBlob = (ResultBlob)htResult[cellName];

                //算子基准值记录到基准值当中
                if (ModelParams.PreciseStdValue.DblValue1 == 0)
                {
                    ModelParams.PreciseStdValue = new Point2D(resultBlob.StdX, resultBlob.StdY);
                }
                //面积判断
                #region 面积检测
                if (!BlobAreaDetect(resultBlob.Area, out dblResult))
                {
                    ShowState("精定位第一次拍照失败");
                    blResult = false;
                    return(false);
                }
                #endregion

                //一次拍照计算偏差,目前用于和二次拍照进行对比
                BackLightLocation.Verify(new Point2D(resultBlob.X, resultBlob.Y),
                                         new Point2D(resultBlob.StdX, resultBlob.StdY), //不规则区域基准值,即旋转中心
                                         resultBlob.R_J,                                //不规则区域角度
                                         ParCalibWorld.V_I[g_NoCamera],                 //相机系数
                                         ModelParams.BLDisplayType,                     //背光在相机显示中的方向
                                         ModelParams.PreciseRobotAngle,                 //精定位机器人u轴角度
                                         ModelParams.BotWastageAngle,                   //机器人残材平台放片角度
                                         ModelParams.BotPlaceAngle,                     //机器人放置角度
                                         ModelParams.DisplayAngle,                      //相机显示角度
                                         ModelParams.BLPlaceAngle);                     //背光放置方向

                blResult = BackLightLocation.BlobAngleCalc(
                    resultBlob.R_J,                //不规则区域角度
                    ModelParams.PrecisePos,        //机器人精定位位置
                    ModelParams.cmd_PreciseAngle,  //精定位角度调整指令
                    ModelParams.cmd_PreciseFailed, //精定位失败指令
                    ModelParams.PreciseThreadR,    //精定位角度偏差阈值
                    ModelParams.BLDisplayType,     //背光在相机显示中的方向
                    RegeditMain.R_I.ID,            //UniqueID
                    ModelParams.IfRecordData,      //是否进行数据记录
                    out phi);                      //输出实际给机器人补偿的角度
                return(blResult);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(false);
            }
            finally
            {
                string strResult = "OK";
                if (!blResult)
                {
                    strResult = "NG";
                }
                g_UCDisplayCamera.ShowResult("面积比例:" + dblResult[1].ToString(ReservDigits) +
                                             "\n角度补正:" + phi.ToString(ReservDigits) +
                                             "\n角度阈值:" + ModelParams.PreciseThreadR.ToString(ReservDigits) +
                                             "\n" + strResult, blResult);
            }
        }
コード例 #4
0
        /// <summary>
        /// 不规则区域偏差计算
        /// </summary>
        /// <param name="cellName"></param>
        /// <param name="htResult"></param>
        /// <returns></returns>
        public bool BlobDeviation(string cellName, out Hashtable htResult)
        {
            htResult = null;
            Point2D pDelta   = new Point2D();
            bool    blResult = true;

            double[] dblResult = new double[2];
            try
            {
                #region 空跑
                if (ParStateSoft.StateMachine_e == StateMachine_enum.NullRun)
                {
                    ShowState("空跑默认发送平台1坐标");
                    LogicRobot.L_I.WriteRobotCMD(ModelParams.PosWastagePlat1, ModelParams.cmd_PreciseResult);
                    return(true);
                }
                #endregion

                StateComprehensive_enum stateComprehensive_e = g_BaseDealComprehensive.DealComprehensivePosNoDisplay(
                    g_UCDisplayCamera, g_HtUCDisplay, Pos_enum.Pos1, out htResult);
                ResultBlob resultBlob = (ResultBlob)htResult[cellName];

                #region 面积检测
                if (!BlobAreaDetect(resultBlob.Area, out dblResult))
                {
                    blResult = false;
                    return(false);
                }
                #endregion

                //获取像素偏差
                //Point2D delta = new Point2D((ModelParams.isMirrorX ? 1 : -1) * resultBlob.DeltaX * AMP,
                //    (ModelParams.isMirrorY ? 1 : -1) * resultBlob.DeltaY * AMP);
                double  deltaX = resultBlob.X - ModelParams.PreciseStdValue.DblValue1;
                double  deltaY = resultBlob.Y - ModelParams.PreciseStdValue.DblValue2;
                Point2D delta  = new Point2D((ModelParams.isMirrorX ? 1 : -1) * deltaX * AMP,
                                             (ModelParams.isMirrorY ? 1 : -1) * deltaY * AMP);
                //将像素偏差代入计算
                blResult = BolbDevationCalc(phi, delta, out pDelta);
                return(blResult);
            }
            catch (Exception ex)
            {
                blResult = false;
                Log.L_I.WriteError(NameClass, ex);
                return(false);
            }
            finally
            {
                string strResult = "OK";
                if (!blResult)
                {
                    strResult = "NG";
                }
                g_UCDisplayCamera.ShowResult(
                    "面积比例:" + dblResult[1].ToString("f3") +
                    "  阈值:" + ModelParams.AreaMin.ToString(ReservDigits) + "-" + ModelParams.AreaMax.ToString(ReservDigits) +
                    "\n补正值X:" + pDelta.DblValue1.ToString("f3") +
                    "  阈值:" + ModelParams.PreciseThreadX.ToString(ReservDigits) +
                    "\n补正值Y:" + pDelta.DblValue2.ToString("f3") +
                    "  阈值:" + ModelParams.PreciseThreadY.ToString(ReservDigits) +
                    "\n" + strResult, blResult);
            }
        }