Пример #1
0
int CenterOfFocus::getCOF() {
	Mat circleImg = Mat::zeros(w, w, CV_8UC3);
	drawCircle(circleImg, Point( w / 2, w / 2));
	state++;
	namedWindow("firstWindow", CV_WINDOW_NORMAL);
	setWindowProperty("firstWindow", CV_WND_PROP_FULLSCREEN,
			CV_WINDOW_FULLSCREEN);

	VideoCapture cap(0);
	if (!cap.isOpened())
		return -1;

	Mat frame;
	while (true) {
		cap >> frame;
		if (waitKey(15) >= 0) {
			std::ostringstream stm;
			stm << state;
			string fileName = stm.str();
			imwrite(fileName + ".jpg", frame);
			destroyWindow("firstWindow");
			namedWindow("firstWindow", CV_WINDOW_NORMAL);
			setWindowProperty("firstWindow", CV_WND_PROP_FULLSCREEN,
					CV_WINDOW_FULLSCREEN);
			if (state == 1) {
				circleImg = Mat::zeros(w, w, CV_8UC3);
				drawCircle(circleImg, Point((w / 32), (w / 32)));
			} else if (state == 2) {
				circleImg = Mat::zeros(w, w, CV_8UC3);
				drawCircle(circleImg, Point(w - (w / 32), (w / 32)));
			} else if (state == 3) {
				circleImg = Mat::zeros(w, w, CV_8UC3);
				drawCircle(circleImg, Point(w / 32, w - (w / 32)));
			} else if (state == 4) {
				circleImg = Mat::zeros(w, w, CV_8UC3);
				drawCircle(circleImg, Point(w - (w / 32), w - (w / 32)));
			} else {
				destroyWindow("firstWindow");
				cap.release();
				return -1;
			}
			state++;
		}
		imshow("firstWindow", circleImg);
	}
	return 1;
}
Пример #2
0
bool ExtCamControl::start(JSON* pJson)
{
	g_pExtCamControl = this;

	//Init Camera
	m_pCamFront = new _CamStream();
	CHECK_FATAL(m_pCamFront->init(pJson, "FRONTL"));

	//Init Marker Detector
	m_pMD = new _MarkerDetector();
	CHECK_FATAL(m_pMD->init(pJson, "RED_CIRCLE"));
	m_pMD->m_pCamStream = m_pCamFront;
	m_pCamFront->m_bHSV = true;

	//Init BgFg Detector
	m_pBgFgD = new _BgFgDetector();
	CHECK_FATAL(m_pBgFgD->init(pJson, ""));
	m_pBgFgD->m_pCamStream = m_pCamFront;

	//Init Autopilot
/*	m_pAP = new _AutoPilot();
	CHECK_FATAL(m_pAP->setup(&m_Json, ""));
	m_pAP->init();
	m_pAP->setCamStream(m_pCamFront, CAM_FRONT);
	m_pAP->m_pOD = m_pOD;
	m_pAP->m_pFD = m_pFD;
//	m_pMD = m_pAP->m_pCamStream[CAM_FRONT].m_pCam->m_pMarkerDetect;
*/

	//Connect to Mavlink
/*	m_pMavlink = new _MavlinkInterface();
	CHECK_FATAL(m_pMavlink->setup(&m_Json, "FC"));
	CHECK_INFO(m_pMavlink->open());
*/

	//Main window
	m_pShow = new CamFrame();
	m_pMat = new CamFrame();
	m_pMat2 = new CamFrame();

	//Init UI Monitor
	m_pUIMonitor = new UIMonitor();
	m_pUIMonitor->init("OpenKAI demo", pJson);
	m_pUIMonitor->addFullFrame(m_pShow);

	//Start threads
	m_pCamFront->start();
//	m_pMavlink->start();
//	m_pDF->start();
	m_pMD->start();
//	m_pAP->start();
	m_pBgFgD->start();

	//UI thread
	m_bRun = true;
	namedWindow(APP_NAME, CV_WINDOW_NORMAL);
	setWindowProperty(APP_NAME, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
	setMouseCallback(APP_NAME, onMouseExtCamControl, NULL);

	while (m_bRun)
	{
//		Mavlink_Messages mMsg;
//		mMsg = m_pMavlink->current_messages;
//		m_pCamFront->m_pCamL->m_bGimbal = true;
//		m_pCamFront->m_pCamL->setAttitude(mMsg.attitude.roll, 0, mMsg.time_stamps.attitude);

		if(!showScreenMarkerDetector())
		{
			showScreenBgFgDetector();
		}

		//Handle key input
		m_key = waitKey(30);
		handleKey(m_key);
	}

//	m_pAP->stop();
	m_pMD->stop();
//	m_pMavlink->stop();
	m_pBgFgD->stop();

	m_pMD->complete();
	m_pBgFgD->complete();
//	m_pDF->complete();
//	m_pAP->complete();
//	m_pCamFront->complete();
//	m_pMavlink->complete();
//	m_pMavlink->close();

//	delete m_pAP;
//	delete m_pMavlink;
//	delete m_pDF;
	delete m_pCamFront;

	return 0;

}
void calibrateEyeGaze()
{
	//Note: Keep head fixed entire time

	//1. Display entire screen
	Mat screenImage(Size(640, 480), CV_8UC3, Scalar(255, 255, 255));
	namedWindow("Calibration Screen", CV_WINDOW_NORMAL);
	setWindowProperty("Calibration Screen", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
	imshow("Calibration Screen", screenImage);
	waitKey(0);

	//2. Display circles at 4 corners.
	circle(screenImage, Point(630, 10), 10, Scalar(255, 0, 0), -1);
	imshow("Calibration Screen", screenImage);
	waitKey(1000);
	calibrateStart = 1;
	thread thread1(aggregateEyeShift);
	waitKey(1000);
	calibrateStart = 0;	
	thread1.join(); 
	TopRight.x = threadReturn[0]; TopRight.y = threadReturn[1];

	screenImage.setTo(Scalar(255, 255, 255));
	circle(screenImage, Point(10, 10), 10, Scalar(255, 0, 0), -1);
	imshow("Calibration Screen", screenImage);
	waitKey(1000);
	calibrateStart = 1;
	thread thread2(aggregateEyeShift);
	waitKey(1000);
	calibrateStart = 0;
	thread2.join(); 
	TopLeft.x = threadReturn[0]; TopLeft.y = threadReturn[1];

	screenImage.setTo(Scalar(255, 255, 255));
	circle(screenImage, Point(10, 470), 10, Scalar(255, 0, 0), -1);
	imshow("Calibration Screen", screenImage);
	waitKey(1000);
	calibrateStart = 1;
	thread thread3(aggregateEyeShift);
	waitKey(1000);
	calibrateStart = 0;
	thread3.join();
	BottomLeft.x = threadReturn[0]; BottomLeft.y = threadReturn[1];
	
	screenImage.setTo(Scalar(255, 255, 255));
	circle(screenImage, Point(630, 470), 10, Scalar(255, 0, 0), -1);
	imshow("Calibration Screen", screenImage);
	waitKey(1000);
	calibrateStart = 1;
	thread thread4(aggregateEyeShift);
	waitKey(1000);
	calibrateStart = 0;
	thread4.join();
	BottomRight.x = threadReturn[0]; BottomRight.y = threadReturn[1];
	
	cout << "Top Right: " << TopRight.x << " " << TopRight.y << endl;
	cout << "Top Left: " << TopLeft.x << " " << TopLeft.y << endl;
	cout << "Bottom left: " << BottomLeft.x << " " << BottomLeft.y << endl;
	cout << "Bottom Right: " << BottomRight.x << " " << BottomRight.y << endl;

	screenImage.setTo(Scalar(255, 255, 255));
	
	//3. Record the eye shift in all 4 locations

	//4. Linearly interpolate eye shifts to find gaze position

}
void WebApplicationWindow::createAndSetup()
{
    if (mTrustScope == TrustScopeSystem) {
        mUserScripts.append(QUrl("qrc:///qml/webos-api.js"));
        createDefaultExtensions();
    }

    if (mWindowType == "dashboard")
        mLoadingAnimationDisabled = true;

    if (mHeadless) {
        qDebug() << __PRETTY_FUNCTION__ << "Creating application container for headless ...";

        mEngine = new QQmlEngine;
        configureQmlEngine();

        QQmlComponent component(mEngine, QUrl(QString("qrc:///qml/ApplicationContainer.qml")));
        mRootItem = qobject_cast<QQuickItem*>(component.create());
    }
    else {
        QQuickWebViewExperimental::setFlickableViewportEnabled(mApplication->desc().flickable());

        mWindow = new QQuickView;
        mWindow->installEventFilter(this);


        mEngine = mWindow->engine();
        configureQmlEngine();

        connect(mWindow, &QObject::destroyed,  [=](QObject *obj) {
            qDebug() << "Window destroyed";
        });

        mWindow->setColor(Qt::transparent);

        mWindow->reportContentOrientationChange(QGuiApplication::primaryScreen()->primaryOrientation());

        mWindow->setSurfaceType(QSurface::OpenGLSurface);
        QSurfaceFormat surfaceFormat = mWindow->format();
        surfaceFormat.setAlphaBufferSize(8);
        surfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES);
        mWindow->setFormat(surfaceFormat);

        // make sure the platform window gets created to be able to set it's
        // window properties
        mWindow->create();

        // set different information bits for our window
        setWindowProperty(QString("_LUNE_WINDOW_TYPE"), QVariant(mWindowType));
        setWindowProperty(QString("_LUNE_WINDOW_PARENT_ID"), QVariant(mParentWindowId));
        setWindowProperty(QString("_LUNE_WINDOW_LOADING_ANIMATION_DISABLED"), QVariant(mApplication->loadingAnimationDisabled()));
        setWindowProperty(QString("_LUNE_APP_ICON"), QVariant(mApplication->icon()));
        setWindowProperty(QString("_LUNE_APP_ID"), QVariant(mApplication->id()));

        connect(mWindow, SIGNAL(visibleChanged(bool)), this, SLOT(onVisibleChanged(bool)));

        QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
        connect(nativeInterface, SIGNAL(windowPropertyChanged(QPlatformWindow*, const QString&)),
                this, SLOT(onWindowPropertyChanged(QPlatformWindow*, const QString&)));

        mWindow->setSource(QUrl(QString("qrc:///qml/ApplicationContainer.qml")));

        mRootItem = mWindow->rootObject();

        mWindow->resize(mSize);
    }
}