示例#1
0
int CFrmPlayer::TestCamera()
{
    static Hander* pHander = NULL;
    if(pHander)
        return 0;
    std::vector<CCameraInfo::CamerInfo> lstInfo;
    int nRet = CCameraFactory::Instance()->EnumDevice(lstInfo);
    std::vector<CCameraInfo::CamerInfo>::iterator it;
    for (it = lstInfo.begin(); it != lstInfo.end(); it++)
    {
        LOG_MODEL_DEBUG("CFrmPlayer", "index:%d;name:%s",
                        it->nIndex,
                        it->szName.c_str()
                        );
        
    }
    CFrameProcess* pProcess = new CFrameProcess();
    bool check = connect(
                pProcess, SIGNAL(sigCaptureFrame(QVideoFrame)),
            /*pProcess, SLOT(slotFrameConvertedToRGB32(QVideoFrame)));
    Q_ASSERT(check);
    check = connect(pProcess,
                    SIGNAL(sigFrameConvertedToRGB32Frame(QVideoFrame)),*/
                    this, SLOT(slotPresent(QVideoFrame)));
    Q_ASSERT(check);
    pHander = new Hander(this, pProcess);
    VideoInfo vi;
    vi.Format = VIDEO_FORMAT_RGB24;
    vi.nHeight = 480;
    vi.nWidth = 640;
    vi.nRatio = 15;
    CCameraFactory::Instance()->GetCamera(0)->Open(pHander);
    CCameraFactory::Instance()->GetCamera(0)->Start();
    return nRet;
}
示例#2
0
void CCameraOpencv::slotTimeOut()
{
#ifdef DEBUG_VIDEO_TIME
    LOG_MODEL_DEBUG("CCameraOpencv", "CCameraOpencv::slotTimeOut threadid:0x%X", QThread::currentThread());
#endif

    cv::Mat frame;
#ifdef ANDROID
    if(!m_videoCapture.grab())
        return;
     m_videoCapture.retrieve(frame, CV_CAP_ANDROID_COLOR_FRAME_RGB);//cv::CAP_ANDROID_COLOR_FRAME_RGB
#else
    m_videoCapture >> frame;
    //因为opencv会在内部把图像转化为BGR格式  
    cv::cvtColor(frame, frame, cv::COLOR_BGR2RGB);  
#endif
    if(frame.empty())
        return;
    /*LOG_MODEL_DEBUG("CCameraOpencv", "frame.type:%d;format:%d", frame.type(), 
                #ifdef ANDROID
                    m_videoCapture.get(cv::CAP_PROP_ANDROID_PREVIEW_FORMAT)
                #else
                    m_videoCapture.get(cv::CAP_PROP_FORMAT)
                #endif
                    );
    */

    /*第一种转换方法:用QImage  
    QImage image((uchar*)(frame.data), frame.cols, frame.rows, QImage::Format_RGB888);  //RGB888就是RGB24即RGB  
    QVideoFrame outFrame(image);//*/

    //*第二种转换方法:用CDataVideoBuffer  
    QByteArray outData((const char*)frame.data, (int)(frame.total() * frame.channels()));
    //frame.total指图片像素个数,总字节数(dst.data)=dst.total*dst.channels()  
    //由QVideoFrame进行释放  
    CDataVideoBuffer* pBuffer = new CDataVideoBuffer(outData,
                            frame.cols,
                            frame.rows);
    //LOG_MODEL_DEBUG("CCameraOpencv", "CCameraOpencv format:%d", dbFormat);
    QVideoFrame outFrame(pBuffer,
                         QSize(frame.cols,
                               frame.rows),
                         QVideoFrame::Format_RGB24);//*/
#ifdef ANDROID
    emit sigCaptureRawFrame(outFrame);
#else
    emit sigCaptureFrame(outFrame);//opencv已经做过镜像了  
#endif
}
/*
bool CCameraQtCaptureVideoFrame::isFormatSupported(const QVideoSurfaceFormat &format) const
{
    const QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
    const QSize size = format.frameSize();
    LOG_MODEL_DEBUG("CCameraQtCaptureVideoFrame", "format:%d;size:%s;handleType:%d", imageFormat, size, format.handleType());
    return imageFormat != QImage::Format_Invalid
            && !size.isEmpty()
            && format.handleType() == QAbstractVideoBuffer::NoHandle;
}
*/
bool CCameraQtCaptureVideoFrame::present(const QVideoFrame &frame)
{
#ifdef DEBUG_VIDEO_TIME
    static QTime preTime = QTime::currentTime();
    QTime curTime = QTime::currentTime();
    LOG_MODEL_DEBUG("Video", "CCameraQtCaptureVideoFrame::present:threadid:0x%X, preTime:%s, currTime:%s, space:%d",
           QThread::currentThreadId(),
           qPrintable(preTime.toString("hh:mm:ss.zzz")),
           qPrintable(curTime.toString("hh:mm:ss.zzz")),
           preTime.msecsTo(curTime));
    preTime = curTime;
#endif
    if(m_pCamera)
        m_pCamera->Present(frame);
    emit sigCaptureFrame(frame);
    return true;
}