예제 #1
0
// カメラ開始
void COpenCVStitch2013Dlg::DoOpen()
{
	//if (fileOpened)
	//{
	//	return;
	//}
	camera.clear();
	for (int id = IDC_CAM1; id <= IDC_CAM4; id++)
	{
		CButton *item = (CButton*)GetDlgItem(id);
		if (item->GetCheck() == BST_CHECKED)
		{
			WCHAR	wname[80];
			char name[80];// , buffer[100];
			size_t len;
			bool res;
			item->GetWindowText(wname, 80);
			wcstombs_s(&len, name, 80, wname, 80);

			WebCam cam = WebCam();
			res = cam.open(id - IDC_CAM1);
			if (res) {
				CString buffer;
				res = cam.set(CV_CAP_PROP_FRAME_WIDTH, WIDTH);
				res = cam.set(CV_CAP_PROP_FRAME_HEIGHT, HEIGHT);
				buffer.Format(L"%d %s", id - IDC_CAM1 + 1, name);
				res = cam.set(CV_CAP_PROP_FPS, FPS);
				res = cam.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
				cam.SetName(name);
				camera.push_back(cam);
			}
		}
	}
}
MainWindow::MainWindow(QWidget *parent, int cameratype) : QMainWindow(parent), ui(new Ui::MainWindow)
{

    ui->setupUi(this);

    // set the desired camera type (current webcam and DSLR
    this->cameraType = cameratype;
    switch (cameratype)
    {
        case CAMERA_WEBCAM: {
            this->webcam = WebCam(ui->frame);
            setupUIWebcam();
            bool ret = this->webcam.openCamera();
            if (ret == false) {
                QMessageBox msgBox;
                msgBox.setIcon(QMessageBox::Critical);
                msgBox.setText("The camera cannot be opened, check device number or connection.");
                msgBox.exec();
                ui->frame->setText("error opening camera, check device number or if any other program is accessing the camera.");
                return;
            }
        }
        break;

        case CAMERA_DSLR: {
            this->dslr = DSLR(ui);
            setupUIDSLR();
            bool ret = this->dslr.openCamera(&this->dslr);
            if (ret == false) {
                QMessageBox msgBox;
                msgBox.setIcon(QMessageBox::Critical);
                msgBox.setText("The camera cannot be opened! Please check if camera is in PTP mode and unmount memory card");
                msgBox.exec();
                ui->frame->setText("error opening camera, please check if camera is setup to PTP mode and unmount memory card from the system. Quit any application that browses the memory card. In doubt remove flash card and try again.");
                return;
            }
        }
        break;

        default:
            exit(1);
    }
    resizeFrame = false;
    resizeFrame100Percent = false;

    tmrTimer = new QTimer(this);

    // Start the main "loop" that processes the frame update
    connect(tmrTimer, SIGNAL(timeout()), this, SLOT(processFrameAndUpdateGUI()));

    startCapture();

}