qt之开发大恒usb3.0相机三

上一篇大恒相机的开发 是基于Qt Creator msvc工具链编译的,大恒相机msvc使用的的lib库是c++版的。如果想要使用mingw工具链开发大恒相机,那么找连接对相应的lib库。mingw对应的库是c的。

配置如下:

图像获取核心代码如下

cpp 复制代码
void __stdcall Widget::OnFrameCallbackFun(GX_FRAME_CALLBACK_PARAM* pFrame)
{
    Widget *pDlg = (Widget*)(pFrame->pUserParam);
    int nImageHeight = pDlg->m_nImageHeight;
    int nImageWidth  = pDlg->m_nImageWidth;

    if (pFrame->status == 0)
    {
        memcpy(pDlg->m_pBufferRaw,pFrame->pImgBuf,pFrame->nImgSize);

        // 黑白相机需要翻转数据后显示
        for(int i =0;i <nImageHeight;i++)
        {
            memcpy(pDlg->m_pImageBuffer+i*nImageWidth, pDlg->m_pBufferRaw+(nImageHeight-i-1)*nImageWidth,(size_t)nImageWidth);
        }

        //pDlg->DrawImg();

        // 图像保存处理
        QImage img(pDlg->m_pImageBuffer,pDlg->m_nImageWidth,pDlg->m_nImageHeight,QImage::Format_Indexed8);
        emit pDlg->imageReady(img);
    }
}
bool  Widget::PrepareForShowImg()
{
    //---------------------------------------------------------------------
    //----------------------初始化bitmap头---------------------------------
    m_pBmpInfo								= (BITMAPINFO *)m_chBmpBuf;
    m_pBmpInfo->bmiHeader.biSize			= sizeof(BITMAPINFOHEADER);
    m_pBmpInfo->bmiHeader.biWidth			= (LONG)m_nImageWidth;
    m_pBmpInfo->bmiHeader.biHeight			= (LONG)m_nImageHeight;

    m_pBmpInfo->bmiHeader.biPlanes			= 1;
    m_pBmpInfo->bmiHeader.biBitCount		= 8; // 黑白图像为8
    m_pBmpInfo->bmiHeader.biCompression		= BI_RGB;
    m_pBmpInfo->bmiHeader.biSizeImage		= 0;
    m_pBmpInfo->bmiHeader.biXPelsPerMeter	= 0;
    m_pBmpInfo->bmiHeader.biYPelsPerMeter	= 0;
    m_pBmpInfo->bmiHeader.biClrUsed			= 0;
    m_pBmpInfo->bmiHeader.biClrImportant	= 0;

    // 黑白图像需要初始化调色板
    for(int i=0;i<256;i++)
    {
        m_pBmpInfo->bmiColors[i].rgbBlue	=i;
        m_pBmpInfo->bmiColors[i].rgbGreen	=i;
        m_pBmpInfo->bmiColors[i].rgbRed		=i;
        m_pBmpInfo->bmiColors[i].rgbReserved=0;
    }

    //--------------------------------------------------------------------------
    //------------------------图像数据Buffer分配---------------------------------
    //为原始图像数据分配空间
    m_pBufferRaw = new BYTE[(size_t)m_nPayLoadSize];
    if (m_pBufferRaw == NULL)
    {
        return false;
    }

    //为经过翻转后的图像数据分配空间
    m_pImageBuffer = new BYTE[(size_t)(m_nImageWidth * m_nImageHeight)];
    if (m_pImageBuffer == NULL)
    {
        delete []m_pBufferRaw;
        m_pBufferRaw = NULL;

        return false;
    }

    return true;
}

有需要源码的话联系咸鱼号 solar.

相关推荐
用户805533698034 天前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner4 天前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz9 天前
QML Hello World 入门示例
qt
xcyxiner12 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner13 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner13 天前
DicomViewer (添加模型类)3
qt
xcyxiner14 天前
DicomViewer (目录调整) 2
qt
xcyxiner14 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
LDR00616 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术16 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript