FlyCapture2 Qt5 MinGW Configuration

Install FlyCatprue2 to the folder "C:\PointGreyResearch\"

Add the following to the .pro file:

# Add FlyCapture2
INCLUDEPATH += C:\PointGreyResearch\FlyCapture2\include
INCLUDEPATH += C:\PointGreyResearch\FlyCapture2\include\C

LIBS += "C:\PointGreyResearch\FlyCapture2\lib\C\FlyCapture2_C.lib"
LIBS += "C:\PointGreyResearch\FlyCapture2\lib\C\FlyCapture2GUI_C.lib"

Note:

The C++ library only works with visual studio on Windows, not MinGW. So if we want to use MinGW, only the C library would work!

Sample FlyCapture2 API C Code:

#include "C/FlyCapture2_C.h"
#include <stdio.h>

typedef enum _AviType
{
    UNCOMPRESSED,
    MJPG,
    H264
} AviType;

void PrintCameraInfo( fc2Context context )
{
    fc2Error error;
    fc2CameraInfo camInfo;
    error = fc2GetCameraInfo( context, &camInfo );
    if ( error != FC2_ERROR_OK )
    {
        // Error
    }

    printf(
        "\n*** CAMERA INFORMATION ***\n"
        "Serial number - %u\n"
        "Camera model - %s\n"
        "Camera vendor - %s\n"
        "Sensor - %s\n"
        "Resolution - %s\n"
        "Firmware version - %s\n"
        "Firmware build time - %s\n\n",
        camInfo.serialNumber,
        camInfo.modelName,
        camInfo.vendorName,
        camInfo.sensorInfo,
        camInfo.sensorResolution,
        camInfo.firmwareVersion,
        camInfo.firmwareBuildTime );
}

int SaveAVIHelper(fc2Context context, AviType aviType, float frameRate)
{
    fc2Error error;
    const int k_numImagesToGrab = 100;
    fc2Image rawImage;
    fc2AVIContext aviContext;
    fc2AVIOption aviOption;
    fc2H264Option h264Option;
    fc2MJPGOption mjpgOption;
    int i;

    error = fc2CreateAVI(&aviContext);
    if (error != FC2_ERROR_OK)
    {
        printf("Error in fc2CreateAVI: %d\n", error);
        return -1;
    }

    error = fc2CreateImage( &rawImage );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2CreateImage: %d\n", error );
        fc2DestroyAVI(aviContext);
        return -1;
    }

    for (i=0; i < k_numImagesToGrab; i++)
    {
        // Retrieve the image
        error = fc2RetrieveBuffer(context, &rawImage);
        if (error != FC2_ERROR_OK)
        {
            printf("Error in retrieveBuffer: %d\n", error);
            continue;
        }

        // Perform some initialization for the first time
        if (i == 0)
        {
            switch (aviType)
            {
            case UNCOMPRESSED:
                aviOption.frameRate = frameRate;
                error = fc2AVIOpen(aviContext, "SaveImageToAviEx_C-Uncompressed", &aviOption);
                if (error != FC2_ERROR_OK)
                {
                    printf("Error opening AVI: %d\n", error);
                }
                break;

            case MJPG:
                mjpgOption.frameRate = frameRate;
                mjpgOption.quality = 75;
                error = fc2MJPGOpen(aviContext, "SaveImageToAviEx_C-MJPG", &mjpgOption);
                if (error != FC2_ERROR_OK)
                {
                    printf("Error opening AVI: %d\n", error);
                }
                break;

            case H264:
                h264Option.frameRate = frameRate;
                h264Option.bitrate = 1000000;
                h264Option.width = rawImage.cols;
                h264Option.height = rawImage.rows;
                error = fc2H264Open(aviContext, "SaveImageToAviEx_C-H264", &h264Option);
                if (error != FC2_ERROR_OK)
                {
                    printf("Error opening AVI: %d\n", error);
                }
                break;
            }
        }

        error = fc2AVIAppend(aviContext, &rawImage);
        if (error != FC2_ERROR_OK)
        {
            printf("Error appending to AVI: %d\n", error);
        }

        printf("Appended image %d\n", i);
    }  

    error = fc2DestroyImage(&rawImage);
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2CreateImaged: %d\n", error );
        fc2DestroyAVI(aviContext);
        return -1;
    }

    error = fc2DestroyAVI(aviContext);
    if (error != FC2_ERROR_OK)
    {
        printf("Error in fc2DestroyAVI: %d\n", error);
        return -1;
    }

    return 0;
}

float GetFrameRate(fc2Context context)
{
    fc2Error error;
    fc2PropertyInfo propInfo;
    fc2Property prop;

    // Check if the camera supports the FRAME_RATE property
    printf( "Detecting frame rate from camera... \n" );
    propInfo.type = FC2_FRAME_RATE;
    error = fc2GetPropertyInfo(context, &propInfo);
    if (error != FC2_ERROR_OK)
    {
        return 0.0f;
    }

    if (propInfo.present)
    {
        // Get the frame rate
        prop.type = FC2_FRAME_RATE;
        error = fc2GetProperty(context, &prop);
        if (error != FC2_ERROR_OK)
        {
            return 0.0f;
        }

        // Set the frame rate.
        // Note that the actual recording frame rate may be slower,
        // depending on the bus speed and disk writing speed.
        return prop.absValue;
    }

    return 0.0f;
}

int RunCamera(fc2Context context, fc2PGRGuid guid)
{
    fc2Error error;
    float frameRate = 0.0f;

    error = fc2Connect( context, &guid );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2Connect: %d\n", error );
        return -1;
    }

    PrintCameraInfo( context );    

    error = fc2StartCapture( context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2StartCapture: %d\n", error );
        return -1;
    }

    frameRate = GetFrameRate(context);
    if (frameRate == 0.0f)
    {
        printf("Invalid frame rate returned\n");
        return -1;
    }

    SaveAVIHelper(context, UNCOMPRESSED, frameRate);
    SaveAVIHelper(context, H264, frameRate);
    SaveAVIHelper(context, MJPG, frameRate);

    error = fc2StopCapture( context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2StopCapture: %d\n", error );
        return -1;
    }

    return 0;
}

int main(int argc, char** argv)
{
    fc2Error error;
    fc2Context context;
    fc2PGRGuid guid;
    unsigned int numCameras = 0;      

    //PrintBuildInfo();

    error = fc2CreateContext( &context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2CreateContext: %d\n", error );
        return 0;
    }        

    error = fc2GetNumOfCameras( context, &numCameras );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2GetNumOfCameras: %d\n", error );
        return 0;
    }

    if ( numCameras == 0 )
    {
        // No cameras detected
        printf( "No cameras detected.\n");
        return -1;
    }

    // Get the 0th camera
    error = fc2GetCameraFromIndex( context, 0, &guid );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2GetCameraFromIndex: %d\n", error );
        return -1;
    }    

    if (RunCamera(context, guid) != 0)
    {
        printf("Error running camera\n");
        return -1;
    }

    error = fc2DestroyContext( context );
    if ( error != FC2_ERROR_OK )
    {
        printf( "Error in fc2DestroyContext: %d\n", error );
        return -1;
    }

    printf( "Done! Press Enter to exit...\n" );
    getchar();

    return 0;
}
时间: 2024-10-14 04:03:34

FlyCapture2 Qt5 MinGW Configuration的相关文章

Qt5+VS2010的安装及使用

在我的博客<Win7下Qt5的安装及使用>中讲解了win7下Qt5+MinGW的安装及使用,本节再讲解win7下Qt5+VS2010的安装及使用.利用Qt5+MinGW开发应用程序比较麻烦的是,每次都要编写.pro文件(项目配置文件,类似于makefile),而用Qt5+VS2010则不再需要编写.pro文件,尤其对于习惯于VS2010且电脑上已装了VS2010的程序员来说还是比较好的. 所需软件: VS2010(企业版) Qt Library:qt-opensource-windows-x8

用mingw静态编译Qt4.8.2和Qt5.1.1(需要修改不少源码)

因为一些乱七八糟的原因,我需要用mingw静态编译Qt4.8.2和Qt5.1.1.经历了一天的折腾之后,自觉编译一下Qt还是件颇为麻烦的事情,故将过程略作总结,以备不时之需. 首先,在编译之前,我需要下载mingw.qt-everywhere-opensource-src-4.8.2和qt-everywhere-opensource-src-5.1.1. 然后,准备开始编译了,当然先得把压缩包解压到一个合适的地方.我这里的路径是"C:\Qt"下面. 解压完毕后,先试着编译Qt4.8.2

FLTK 1.3.3 MinGW 4.9.1 Configuration 配置

Download FLTK 1.3.3 Download CMake 3.2.0 Start CMake 3.2.0, fill the source and destination: source: C:/FLTK/fltk-1.1.10 destination: C:/FLTK/build Click Configure and use MinGW Makefiles to complie. Change the following item: CMAKE_INSTALL_PREFIX [C

VTK 6.3.0 Qt 5.4 MinGW 4.9.1 Configuration 配置

Download VTK 6.3.0 Download Qt 5.4 with MinGW 4.9.1 Download CMake 3.2.0 I assume you've already installed Qt 5.4 with MinGW 4.9.1 and CMake 3.2.0 correctly. Pre-process the VTK: Open CMakeLists.txt in your extracted VTK-6.3.0 folder, find set(VTK_US

Configuration of FlyCapture2 with VS2010

Add in the system Path: C:\Program Files\Point Grey Research\FlyCapture2\bin Project->Project Property->Configuration Properties->VC++Directories ->Include Directories: C:\Program Files\Point Grey Research\FlyCapture2\includeC:\Program Files\P

Qt5 OpenCV2.4 Configuration

Download CMake 2.8.2 Download OpenCV 2.4.11 Download Qt 5.4 Open CMake 2.8.2, set the source and build directory: Click "Configure", choose "MinGW Makefiles" and "Specify native compliers" Set the C and C++ compiler from the

linux下编译qt5.6.0静态库——configure配置

 随笔 - 116  文章 - 4  评论 - 7 linux下编译qt5.6.0静态库--configure配置 linux下编译qt5.6.0静态库 linux下编译qt5.6.0静态库 configure生成makefile 安装选项 Configure选项 第三方库: 附加选项: QNX/Blackberry选项: Android 选项: 生成makefile 遇到链接检查失败的情况 生成makefile后进行编译 编译时的错误 多重定义'QT_MODBUS()'和'QT_MODBU

win7 Qt-5.3.1 cmake-2.8.11.2 opencv-2.4.11平台搭建

在Qt平台上使用OpenCV方法 首先下载好安装程序: 1.qt-opensource-windows-x86-mingw482_opengl-5.3.1.exe 2.cmake-2.8.11.2-win32-x86.exe 3.opencv-2.4.11.exe   (下载地址百度即可) Qt完全安装包含MinGW和OpenGL,安装(解压)OpenCV2.4.11,安装cmake2.8.11.2. 开始编译MinGW下的OpenCV,运行cmake-gui,源码路径为安装(解压)后的Open

qt-5.6.0 移植之编译

其实这只是给自己看的一个configure选项笔记,没有太多的东西. 首先: 下载qt5.6的源码: 地址: http://download.qt.io/archive/qt/5.6/ 下载完解压: tar  -xvf   qt-everywhere-opensource-src-5.6.0.tar.gz 解压完进入源代码 : 修改几个东西: 1. 进入qtbase/mkspecs 里面, 复制一份linux-arm-gnueabi-g++    ,名字为linux-arm 在进入 linux-