Qt环境下利用OpenCV采集摄像头图像并保存

 
  
void MainWindow::opencamera()
{
    QCamera *cam = new QCamera(this);
    if(!cam->isAvailable()){
        QMessageBox::warning(this,"Warning","Cameras are not found.");
        return;
    }
    cam_1 = cvCreateCameraCapture(0);
    cam_2 = cvCreateCameraCapture(1);
    cameraWidth = cvGetCaptureProperty(cam_1,3);
    cameraHeight = cvGetCaptureProperty(cam_1,4);
    timer->start(30);
    if(cam_1&&cam_2){
        cameraOpened = true;
    }
    else
        cameraOpened = false;
}
void MainWindow::readfarme()
{
    frame_1 = cvQueryFrame(cam_1);
    frame_2 = cvQueryFrame(cam_2);
    QImage image_1 = QImage((const uchar*)frame_1->imageData, frame_1->width, frame_1->height, QImage::Format_RGB888).rgbSwapped();
    QImage image_2 = QImage((const uchar*)frame_2->imageData, frame_2->width, frame_2->height, QImage::Format_RGB888).rgbSwapped();
    int viewWidth = 320;
    QImage scaledImage_1 = image_1.scaledToWidth(viewWidth);
    QImage scaledImage_2 = image_2.scaledToWidth(viewWidth);
    leftViewLabel->setPixmap(QPixmap::fromImage(scaledImage_1));//use label to show the image
    rightViewLabel->setPixmap(QPixmap::fromImage(scaledImage_2));
}


 
 

你可能感兴趣的:(Qt环境下利用OpenCV采集摄像头图像并保存)