Esempio n. 1
0
        private void setRoi(TUCAM_ROI_ATTR roiAttr)
        {
            WaitForFrameThread.Abort();

            TUCamera.TUCAM_Buf_AbortWait(mainform.m_opCamList[mainform.m_nCamIndex].hIdxTUCam);             // If you called TUCAM_Buf_WaitForFrames()


            TUCamera.TUCAM_Cap_Stop(mainform.m_opCamList[mainform.m_nCamIndex].hIdxTUCam);                  // Stop capture
            TUCamera.TUCAM_Buf_Release(mainform.m_opCamList[mainform.m_nCamIndex].hIdxTUCam);               // Release alloc buffer after stop capture and quit drawing thread


            TUCamera.TUCAM_Cap_SetROI(mainform.m_opCamList[mainform.m_nCamIndex].hIdxTUCam, roiAttr);


            TUCamera.TUCAM_Cap_GetROI(/*m_opCam.hIdxTUCam*/ mainform.m_opCamList[mainform.m_nCamIndex].hIdxTUCam, ref roiAttr);


            mainform.m_drawframe.pBuffer     = IntPtr.Zero;
            mainform.m_drawframe.ucFormatGet = (byte)TUFRM_FORMATS.TUFRM_FMT_RGB888;
            mainform.m_drawframe.uiRsdSize   = 1U;
            TUCamera.TUCAM_Buf_Alloc(mainform.m_opCamList[mainform.m_nCamIndex].hIdxTUCam, ref mainform.m_drawframe);                                                   // Alloc buffer after set resolution or set ROI attribute
            TUCamera.TUCAM_Cap_Start(mainform.m_opCamList[mainform.m_nCamIndex].hIdxTUCam, 0U);


            WaitForFrameThread = new System.Threading.Thread(new ThreadStart(WaitForFrame));
            WaitForFrameThread.Start();

            ShowpictureBoxCamera.Refresh();
        }
Esempio n. 2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            //IntPtr strPath = Marshal.StringToHGlobalAnsi(System.Environment.CurrentDirectory);
            m_opCamList = new List <TUCAM_OPEN>();

            m_itApi.uiCamCount = 0;
            //m_itApi.pstrConfigPath = strPath;

            TUCamera.TUCAM_Api_Init(ref m_itApi);

            if (0 == m_itApi.uiCamCount)
            {
                MessageBox.Show("Init Camera Error!");
                return;
            }

            for (int i = 0; i < m_itApi.uiCamCount; i++)
            {
                m_opCam.uiIdxOpen = (uint)i;
                TUCamera.TUCAM_Dev_Open(ref m_opCam);
                m_opCamList.Add(m_opCam);

                valueinfo.nValue = 1;
                valueinfo.nID    = (int)TUCAM_IDINFO.TUIDI_CAMERA_CHANNELS;
                TUCamera.TUCAM_Dev_GetInfo(m_opCam.hIdxTUCam, ref valueinfo);

                if (1 < m_itApi.uiCamCount)
                {
                    TUCamera.TUCAM_Capa_SetValue(m_opCamList[m_nCamIndex].hIdxTUCam, (int)TUCAM_IDCAPA.TUIDC_CAM_MULTIPLE, (int)m_itApi.uiCamCount);
                }

                //m_itDraw.hWnd = ShowpictureBox.Handle;
                m_itDraw.ucChannels = (sbyte)valueinfo.nValue;
                m_itDraw.nWidth     = 2048;
                m_itDraw.nHeight    = 2048;
                m_itDraw.nMode      = 0;
                TUCamera.TUCAM_Draw_Init(m_opCam.hIdxTUCam, m_itDraw);
            }

            if (0 == (long)m_opCam.hIdxTUCam)
            {
                MessageBox.Show("Open Camera Faild!");
                return;
            }
            m_nCamIndex = 0;
            m_opCam     = m_opCamList[m_nCamIndex];



            double dbGain = 0;

            // 获取增益值
            TUCamera.TUCAM_Prop_GetValue(m_opCam.hIdxTUCam, (int)TUCAM_IDPROP.TUIDP_GLOBALGAIN, ref dbGain, 0);

            // 获取曝光时间
            TUCamera.TUCAM_Prop_GetValue(m_opCam.hIdxTUCam, (int)TUCAM_IDPROP.TUIDP_EXPOSURETM, ref dbExp, 0);

            // 关闭自动曝光
            TUCamera.TUCAM_Capa_SetValue(m_opCam.hIdxTUCam, (int)TUCAM_IDCAPA.TUIDC_ATEXPOSURE, 0);
            // 关闭自动白平衡
            TUCamera.TUCAM_Capa_SetValue(m_opCam.hIdxTUCam, (int)TUCAM_IDCAPA.TUIDC_ATWBALANCE, 0);

            // 设置曝光时间
            // TUCamera.TUCAM_Prop_SetValue(m_opCam.hIdxTUCam, (int)TUCAM_IDPROP.TUIDP_EXPOSURETM, dbExp, 0);

            // 设置增益值
            //TUCamera.TUCAM_Prop_SetValue(m_opCam.hIdxTUCam, (int)TUCAM_IDPROP.TUIDP_GLOBALGAIN, dbGain, 0);

            valText.nTextSize = 64;
            string strp = "000000000000000000000000000";

            valText.pText = Marshal.StringToHGlobalAnsi(strp);

            // 获取分辨率范围
            attrCapa.idCapa = (int)TUCAM_IDCAPA.TUIDC_RESOLUTION;
            if (TUCAMRET.TUCAMRET_SUCCESS == TUCamera.TUCAM_Capa_GetAttr(/*m_opCam.hIdxTUCam*/ m_opCam.hIdxTUCam, ref attrCapa))
            {
                int      nCnt  = attrCapa.nValMax - attrCapa.nValMin + 1;
                string[] szRes = new string[nCnt];

                valText.nID = (int)TUCAM_IDCAPA.TUIDC_RESOLUTION;
                for (int i = 0; i < nCnt; ++i)
                {
                    valText.dbValue = i;
                    TUCamera.TUCAM_Capa_GetValueText(/*m_opCam.hIdxTUCam*/ m_opCam.hIdxTUCam, ref valText);
                    szRes[i] = Marshal.PtrToStringAnsi(valText.pText);
                }
            }

            InitDrawingResource();


            timer          = new Timer();
            timer.Interval = 50;
            timer.Tick    += timer1_Tick;
            timer.Start();

            //Init_Layout(tableLayoutPanel, NumTube, NumSeries);
            //InitDataCache(NumTube, NumSeries);
            StartWaitForFrame(m_opCamList[m_nCamIndex]);

            // InitChart(NumChartArea, 10);

            m_drawframe.ucFormatGet = (byte)TUFRM_FORMATS.TUFRM_FMT_RGB888;
            if (TUCAMRET.TUCAMRET_SUCCESS == TUCamera.TUCAM_Buf_WaitForFrame(m_opCamList[m_nCamIndex].hIdxTUCam, ref m_drawframe))
            {
                m_nCurWidth  = m_bmpInfo.biWidth = m_drawframe.usWidth;
                m_nCurHeight = m_bmpInfo.biHeight = m_drawframe.usHeight;
            }


            TUCamera.TUCAM_Cap_GetROI(/*m_opCam.hIdxTUCam*/ m_opCamList[m_nCamIndex].hIdxTUCam, ref roiAttr);
            //
            roiAttr.bEnable  = false;
            roiAttr.nVOffset = 0;
            roiAttr.nHOffset = 0;
            roiAttr.nWidth   = m_bmpInfo.biWidth;
            roiAttr.nHeight  = m_bmpInfo.biHeight;

            TUCamera.TUCAM_Cap_SetROI(/*m_opCam.hIdxTUCam*/ m_opCamList[m_nCamIndex].hIdxTUCam, roiAttr);


            //camConfigForm = new CamConfigForm(this);
        }