-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.cpp
96 lines (77 loc) · 2.56 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* @file main.cpp
* @author Christoph Göttert
* @version 0.1
*/
#include <iostream>
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osg/PositionAttitudeTransform>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "BackgroundCamera.h"
#include "VirtualCamera.h"
int main( int argc, char** argv )
{
int screenWidth,screenHeight,textureWidth,textureHeight;
screenWidth = 640;
screenHeight = 480;
textureWidth = 640;
textureHeight = 480;
// OPENCV STUFF
// OpenCV Webcam
cv::VideoCapture cap(0);
if(!cap.isOpened())
{
std::cout << "Webcam cannot open!\n";
return 0;
}
// OSG STUFF
// Create viewer
osgViewer::Viewer viewer;
viewer.setUpViewInWindow(50,50,screenWidth,screenHeight);
// Main Camera
osg::ref_ptr<osg::Camera> camera = viewer.getCamera();
VirtualCamera* vCamera = new VirtualCamera(camera);
// Background-Camera (OpenCV Feed)
BackgroundCamera bgCamera;
osg::Camera* backgroundCamera = bgCamera.createCamera(textureWidth, textureHeight);
// Load Truck Model as Example Scene
osg::ref_ptr<osg::Node> truckModel = osgDB::readNodeFile("dumptruck.osgt");
osg::Group* truckGroup = new osg::Group();
// Position of truck
osg::PositionAttitudeTransform* position = new osg::PositionAttitudeTransform();
truckGroup->addChild(position);
position->addChild(truckModel);
// Set Position of Model
osg::Vec3 modelPosition(0,80,0);
position->setPosition( modelPosition );
// Create new group node
osg::ref_ptr<osg::Group> group = new osg::Group;
osg::Node* background = backgroundCamera;
osg::Node* foreground = truckGroup;
background->getOrCreateStateSet()->setRenderBinDetails(1,"RenderBin");
foreground->getOrCreateStateSet()->setRenderBinDetails(2,"RenderBin");
group->addChild(background);
group->addChild(foreground);
background->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
foreground->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::ON);
// Add the groud to the viewer
viewer.setSceneData(group.get());
double angleRoll( 0. );
while (!viewer.done())
{
// Refresh Background Image
cv::Mat frame;
cap >> frame;
bgCamera.update(frame);
angleRoll += 0.5;
// Update Virtual Camera (these Coordinates should be determined by some AR-Framework/Functionality)
// They are just updated for demonstration purposes..
// Position Parameters: Roll, Pitch, Heading, X, Y, Z
vCamera->updatePosition(angleRoll,0,0, 0, 0, 0);
//osg::notify(osg::WARN)<<"Angle: "<< angleRoll <<std::endl;
viewer.frame();
}
return 0;
}