Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added brandts code

  • Loading branch information...
commit 1e255f4a0274fbdc962a77ae83fdb62ac843d9e4 1 parent 5e8e8de
@HalfdanJ HalfdanJ authored
Showing with 306,013 additions and 0 deletions.
  1. +673 −0 brandts/ButtonMatrixMode.cpp
  2. +63 −0 brandts/ButtonMatrixMode.h
  3. +177 −0 brandts/DrawingMode.cpp
  4. +35 −0 brandts/DrawingMode.h
  5. +239 −0 brandts/FaceTrackerMode.cpp
  6. +37 −0 brandts/FaceTrackerMode.h
  7. +61 −0 brandts/IdleMode.cpp
  8. +17 −0 brandts/IdleMode.h
  9. +20 −0 brandts/Info.plist
  10. +127 −0 brandts/KeyboardMode.cpp
  11. +24 −0 brandts/KeyboardMode.h
  12. +75 −0 brandts/LightButtonMode.cpp
  13. +19 −0 brandts/LightButtonMode.h
  14. +17 −0 brandts/Mode.cpp
  15. +31 −0 brandts/Mode.h
  16. +440 −0 brandts/PaperTracker.cpp
  17. +140 −0 brandts/PaperTracker.h
  18. +112 −0 brandts/SoundInput.cpp
  19. +42 −0 brandts/SoundInput.h
  20. +26,161 −0 brandts/data/haarXML/haarcascade_frontalface_alt.xml
  21. +23,550 −0 brandts/data/haarXML/haarcascade_frontalface_alt2.xml
  22. +103,493 −0 brandts/data/haarXML/haarcascade_frontalface_alt_tree.xml
  23. +35,712 −0 brandts/data/haarXML/haarcascade_frontalface_default.xml
  24. +18,118 −0 brandts/data/haarXML/haarcascade_fullbody.xml
  25. +15,085 −0 brandts/data/haarXML/haarcascade_lowerbody.xml
  26. +31,930 −0 brandts/data/haarXML/haarcascade_profileface.xml
  27. +29,767 −0 brandts/data/haarXML/haarcascade_upperbody.xml
  28. +56 −0 brandts/data/irb60.xml
  29. BIN  brandts/data/lock.png
  30. BIN  brandts/data/unlock.png
  31. +465 −0 brandts/of1394VideoGrabber.cpp
  32. +122 −0 brandts/of1394VideoGrabber.h
  33. +579 −0 brandts/ofAppQtWindow.cpp
  34. +107 −0 brandts/ofAppQtWindow.h
  35. +41 −0 brandts/ofxTwitter.h
  36. BIN  brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/bin/win32/FlyCapture2.dll
  37. +96 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/include/FlyCapture/AVIRecorder.h
  38. +178 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/include/FlyCapture/BusManager.h
  39. +981 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/include/FlyCapture/Camera.h
  40. +148 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/include/FlyCapture/Error.h
  41. +64 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/include/FlyCapture/FlyCapture2.h
  42. +1,246 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/include/FlyCapture/FlyCapture2Defs.h
  43. +125 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/include/FlyCapture/FlyCapture2GUI.h
  44. +57 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/include/FlyCapture/FlyCapture2Platform.h
  45. +492 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/include/FlyCapture/Image.h
  46. +238 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/include/FlyCapture/ImageStatistics.h
  47. +190 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/include/FlyCapture/TopologyNode.h
  48. +198 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/include/FlyCapture/Utilities.h
  49. BIN  brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/FlyCapture/lib/win32/FlyCapture2.lib
  50. +245 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/camera.h
  51. +107 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/capture.h
  52. +456 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/control.h
  53. +215 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/conversions.h
  54. +57 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/dc1394.h
  55. +231 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/format7.h
  56. +167 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/iso.h
  57. +42 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/linux/capture.h
  58. +37 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/linux/control.h
  59. +255 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/log.h
  60. +229 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/register.h
  61. +166 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/types.h
  62. +105 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/utils.h
  63. +467 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/vendor/avt.h
  64. +95 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/vendor/basler.h
  65. +303 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/vendor/basler_sff.h
  66. +225 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/vendor/pixelink.h
  67. +256 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/include/dc1394/video.h
  68. BIN  brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/lib/linux/libdc1394.a
  69. BIN  brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/libs/dc1394/lib/osx/libdc1394.a
  70. +327 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/src/ofxVideoGrabberDc1394.cpp
  71. +88 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/src/ofxVideoGrabberDc1394.h
  72. +429 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/src/ofxVideoGrabberFlyCapture.cpp
  73. +98 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/src/ofxVideoGrabberFlyCapture.h
  74. +13 −0 brandts/ofxvideograbberptgrey/ofxVideoGrabberPtgrey/src/ofxVideoGrabberPtgrey.h
  75. +20 −0 brandts/openFrameworks-Info.plist
  76. +14 −0 brandts/openframeworksQT.pro
  77. +2,475 −0 brandts/openframeworksQT.xcodeproj/project.pbxproj
  78. +7 −0 brandts/openframeworksQT.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  79. +71 −0 brandts/openframeworksQT.xcodeproj/qt_makeqmake.mak
  80. +60 −0 brandts/openframeworksQT.xcodeproj/qt_preprocess.mak
  81. +198 −0 brandts/src/BasePlugin.cpp
  82. +65 −0 brandts/src/BasePlugin.h
  83. +141 −0 brandts/src/Controller.cpp
  84. +38 −0 brandts/src/Controller.h
  85. +33 −0 brandts/src/Data.cpp
  86. +29 −0 brandts/src/Data.h
  87. +36 −0 brandts/src/Defines.h
  88. +118 −0 brandts/src/DrawTestPattern.cpp
  89. +31 −0 brandts/src/DrawTestPattern.h
  90. +251 −0 brandts/src/FaceTracker.cpp
  91. +50 −0 brandts/src/FaceTracker.h
  92. +221 −0 brandts/src/Fiducials.cpp
  93. +38 −0 brandts/src/Fiducials.h
  94. +260 −0 brandts/src/GrabTheDrawing.cpp
  95. +62 −0 brandts/src/GrabTheDrawing.h
  96. +249 −0 brandts/src/InteractionDesign.cpp
  97. +71 −0 brandts/src/InteractionDesign.h
  98. +225 −0 brandts/src/Joystick.cpp
  99. +55 −0 brandts/src/Joystick.h
  100. +153 −0 brandts/src/MotionDetector.cpp
  101. +56 −0 brandts/src/MotionDetector.h
  102. +703 −0 brandts/src/Robot.cpp
  103. +90 −0 brandts/src/Robot.h
  104. +28 −0 brandts/src/RobotControllerItem.h
  105. +127 −0 brandts/src/VideoGrabber.cpp
  106. +42 −0 brandts/src/VideoGrabber.h
  107. +194 −0 brandts/src/glwidget.cpp
  108. +97 −0 brandts/src/glwidget.h
  109. +23 −0 brandts/src/main.cpp
  110. +171 −0 brandts/src/ofxCvHaarFinder/ofxCvHaarFinder.cpp
  111. +55 −0 brandts/src/ofxCvHaarFinder/ofxCvHaarFinder.h
  112. BIN  brandts/src/ofxEasyGui/data/fonts/Helvetica Neue Bold.ttf
  113. +16 −0 brandts/src/ofxEasyGui/example/main.cpp
  114. +142 −0 brandts/src/ofxEasyGui/example/testApp.cpp
  115. +53 −0 brandts/src/ofxEasyGui/example/testApp.h
  116. +209 −0 brandts/src/ofxEasyGui/src/Button.cpp
  117. +38 −0 brandts/src/ofxEasyGui/src/Button.h
  118. +221 −0 brandts/src/ofxEasyGui/src/FileList.cpp
  119. +44 −0 brandts/src/ofxEasyGui/src/FileList.h
  120. +431 −0 brandts/src/ofxEasyGui/src/GuiHandler.cpp
  121. +78 −0 brandts/src/ofxEasyGui/src/GuiHandler.h
  122. +354 −0 brandts/src/ofxEasyGui/src/GuiPanel.cpp
  123. +81 −0 brandts/src/ofxEasyGui/src/GuiPanel.h
  124. +18 −0 brandts/src/ofxEasyGui/src/Meter.cpp
  125. +29 −0 brandts/src/ofxEasyGui/src/Meter.h
  126. +207 −0 brandts/src/ofxEasyGui/src/Radio.cpp
  127. +51 −0 brandts/src/ofxEasyGui/src/Radio.h
  128. +177 −0 brandts/src/ofxEasyGui/src/Slider.cpp
  129. +65 −0 brandts/src/ofxEasyGui/src/Slider.h
  130. +35 −0 brandts/src/ofxEasyGui/src/Spacer.h
  131. +104 −0 brandts/src/ofxEasyGui/src/TextField.cpp
  132. +40 −0 brandts/src/ofxEasyGui/src/TextField.h
  133. +240 −0 brandts/src/ofxEasyGui/src/UiObject.cpp
  134. +84 −0 brandts/src/ofxEasyGui/src/UiObject.h
  135. +14 −0 brandts/src/ofxEasyGui/src/ofxEasyGui.h
  136. +18 −0 brandts/src/src-1.moved-aside/PluginController.h
  137. +11 −0 brandts/src/src-2.moved-aside/RobotControllerItem.cpp
  138. +121 −0 brandts/src/testApp.cpp
  139. +54 −0 brandts/src/testApp.h
  140. +206 −0 brandts/src/window.cpp
  141. +98 −0 brandts/src/window.h
  142. +56 −0 simpleExample/bin/data/irb60.xml
View
673 brandts/ButtonMatrixMode.cpp
@@ -0,0 +1,673 @@
+#include "ButtonMatrixMode.h"
+
+
+ButtonMatrixMode::ButtonMatrixMode(Robot * _robot, myData * _data){
+ name = "ButtonMatrix";
+ robot = _robot;
+ robotData = _data;
+ rate = 0;
+
+ pressedTimer = 0;
+ curButton = -1;
+ foundMasterSafePos = false;
+ init();
+
+ QVBoxLayout * tabLayout = new QVBoxLayout();
+ widget->setLayout(tabLayout);
+
+ QWidget * grid = new QWidget();
+ gridLayout = new QGridLayout();
+ gridLayout->setContentsMargins(0,0,0,0);
+ gridLayout->setAlignment(Qt::AlignCenter);
+
+ grid->setFixedHeight(320*8.0/12-80);
+ grid->setLayout(gridLayout);
+ gridLayout->setAlignment(Qt::AlignTop);
+
+ tabLayout->addWidget(grid);
+ tabLayout->setAlignment(Qt::AlignTop);
+
+ QWidget * gridButton = new QWidget();
+ QGridLayout * gridButtonLayout = new QGridLayout();
+ gridButtonLayout->setAlignment(Qt::AlignTop);
+ gridButtonLayout->setAlignment(Qt::AlignCenter);
+ gridButton->setLayout(gridButtonLayout);
+ gridButton->setFixedHeight(50);
+ gridButton->setContentsMargins(0,0,0,0);
+
+ tabLayout->addWidget(gridButton);
+
+
+ QWidget * gridSliders = new QWidget();
+ QGridLayout * gridSlidersLayout = new QGridLayout();
+ gridSlidersLayout->setAlignment(Qt::AlignTop);
+ gridSlidersLayout->setAlignment(Qt::AlignCenter);
+ gridSliders->setLayout(gridSlidersLayout);
+ // gridSliders->setFixedHeight(50);
+ gridSliders->setContentsMargins(0,0,0,0);
+
+ tabLayout->addWidget(gridSliders);
+
+ int row = 0, column = 0;
+
+ for(int i=0;i<96;i++){
+ checkboxes[i] = new QCheckBox();
+ checkboxes[i]->setTristate(true);
+ gridLayout->addWidget(checkboxes[i], row, column);
+ column ++;
+ if(column == 12){
+ row++;
+ column = 0;
+ }
+
+ lightTurnedOn[i] = false;
+ }
+ lastButton = 0;
+ isLightOnImg.allocate(CAPWIDTH, CAPHEIGHT);
+ storePosition[0] = new QPushButton("top-left");
+ storePosition[1] = new QPushButton("top-right");
+ storePosition[2] = new QPushButton("bottom-left");
+
+ allOn = new QPushButton("All on");
+ allOff= new QPushButton("All off");;
+ resetFlags = new QPushButton("Reset flags");
+
+ // gridButtonLayout->addWidget(new QLabel("Store"), 0, 0);
+ for(int i=0;i<3;i++){
+ gridButtonLayout->addWidget(storePosition[i], 0, i+1);
+ }
+ gridButtonLayout->addWidget(allOn, 1, 1);
+ gridButtonLayout->addWidget(allOff, 1, 2);
+ gridButtonLayout->addWidget(resetFlags, 1, 3);
+
+ for(int n=0;n<3*3*2;n++){
+ positionInformation[n] = new float(0);
+ }
+
+ row=0;
+ int col=0;
+ for(int i=0;i<9;i++){
+ parSliders[i] = new QSlider(Qt::Horizontal);
+ parSliders[i]->setMaximum(1000);
+ gridSlidersLayout->addWidget(parSliders[i], row, col);
+ col ++;
+ if(col > 2){
+ col = 0;
+ row ++;
+ }
+ }
+
+ buttonRepeat = 0;
+}
+
+
+
+void ButtonMatrixMode::init(){
+ controllerItem = robot->addRobotController("ButtonMatrix", CONTROL_MODE_GRAVITY);
+}
+
+void ButtonMatrixMode::activate(){
+ robot->setRobotController(controllerItem);
+
+}
+bool ButtonMatrixMode::deactivate(){
+ if(controllerItem->locked){
+ return false;
+ }
+ return true;
+}
+
+void ButtonMatrixMode::securityCheck(){
+ if(isPointInBoundingbox(robot->industrialRobot->getCurrentTarget(),90)){
+ // cout<<"In safety area"<<endl;
+ // v = robot->industrialRobot->getVariantGoal();
+ robot->industrialRobot->lockVariant(true);
+// controllerItem->locked = true;
+ if(!robot->industrialRobot->isRobotFlagsReady() && controllerItem->isActive()){
+ if(isPointInBoundingbox(robot->industrialRobot->getCurrentTarget(),70)){
+
+ robot->industrialRobot->panic("OK Flag removed while in button matrix bounding box");
+ robot->industrialRobot->setGravityTarget(robot->industrialRobot->getCurrentTarget()-ofxVec3f(0,0,300), robot->industrialRobot->getCurrentDir(), 0.1, 1.0, ofxIndustrialRobotDefines::Auto);
+ }
+ }
+ // cout<<v<<endl;
+ } else {
+ robot->industrialRobot->lockVariant(false);
+ // controllerItem->locked = false;
+
+ }
+
+ if(isPointInBoundingbox(robot->industrialRobot->getCurrentTarget(),-20)){
+ robot->industrialRobot->panic("To close to panels.");
+ robot->industrialRobot->setGravityTarget(robot->industrialRobot->getCurrentTarget()-ofxVec3f(0,0,300), robot->industrialRobot->getCurrentDir(), 0.1, 1.0, ofxIndustrialRobotDefines::Auto);
+
+ }
+
+}
+
+void ButtonMatrixMode::step(){
+
+// cout<<"Light on "<<isLightOn()<<endl;
+ int closestButton = -1;
+ float closestButtonDistance = -1;
+
+ int numChanges = 0;
+ for(int i=0;i<96;i++){
+ if(lightTurnedOn[i]){
+ if(checkboxes[i]->checkState() != Qt::Checked){
+ checkboxes[i]->setCheckState(Qt::PartiallyChecked);
+
+ }
+ } else {
+ if(checkboxes[i]->checkState() != Qt::Unchecked){
+ if(checkboxes[i]->checkState() != Qt::PartiallyChecked){
+ checkboxes[i]->setCheckState(Qt::Unchecked);
+ } else {
+ checkboxes[i]->setCheckState(Qt::PartiallyChecked);
+ }
+ }
+ }
+ if(checkboxes[i]->checkState() == Qt::PartiallyChecked){
+ numChanges++;
+ ofxVec3f buttonPos = buttonPosition(i);
+ ofxVec3f curPosition = robot->industrialRobot->getCurrentTarget();
+
+ int rowC = closestButton / 12;
+ // int colC = closestButton-rowC*12;
+ int row = i / 12;
+ // int col = i-row*12;
+
+ int border = 3;
+
+ bool doit = false;
+ if(closestButton == -1){
+ doit = true;
+ } else if((v == ofxIndustrialRobotDefines::Up && rowC > border && row <= border)){
+ doit = true;
+ } else if((v == ofxIndustrialRobotDefines::Down && rowC <= border && row > border)){
+ doit = true;
+ } else if((buttonPos - curPosition).length() < closestButtonDistance){
+ if((v == ofxIndustrialRobotDefines::Up && row <= border) || (v == ofxIndustrialRobotDefines::Up && row > border && rowC > border)){
+ doit = true;
+ } else if((v == ofxIndustrialRobotDefines::Down && row > border) || (v == ofxIndustrialRobotDefines::Down && row <= border && rowC <= border)){
+ doit = true;
+ }
+ }
+
+ if(doit){
+ closestButton = i;
+ closestButtonDistance = (buttonPos - curPosition).length();
+
+ }
+ /* if(closestButton == -1 || (buttonPos - curPosition).length() < closestButtonDistance){
+ if(closestButton != -1){
+
+ if(v == ofxIndustrialRobotDefines::Up){
+ if(rowC
+ }
+ if(rowC > 3 && row <= 3){
+
+ } else {
+ closestButton = i;
+ closestButtonDistance = (buttonPos - curPosition).length();
+ }
+ } else {
+ closestButton = i;
+ closestButtonDistance = (buttonPos - curPosition).length();
+
+ }
+
+ }
+ }*/
+
+ /* if(checkboxes[i]->checkState() != Qt::PartiallyChecked){
+ if(ofRandom(0, 100) < 0.1){
+ checkboxes[i]->setCheckState(Qt::PartiallyChecked);
+
+ }
+ } */
+ }
+ }
+
+ if(numChanges > 0){
+ rate += 0.2;
+ if(rate > 80){
+ rate = 80;
+ }
+ }
+
+ if(curButton == -1 && closestButton != -1){
+ curButton = closestButton;
+ }
+
+
+
+ if(resetFlags->isDown()){
+ for(int i=0;i<96;i++){
+ checkboxes[i]->setCheckState(Qt::Unchecked);
+ lightTurnedOn[i] = false;
+
+ }
+ resetFlags->setDown(false);
+ }
+
+ if(allOn->isDown()){
+ for(int i=0;i<96;i++){
+ if(!lightTurnedOn[i]){
+ checkboxes[i]->setCheckState(Qt::PartiallyChecked);
+ } else {
+ checkboxes[i]->setCheckState(Qt::Checked);
+ }
+ }
+ allOn->setDown(false);
+ }
+ if(allOff->isDown()){
+ for(int i=0;i<96;i++){
+ if(lightTurnedOn[i]){
+ checkboxes[i]->setCheckState(Qt::PartiallyChecked);
+ } else {
+ checkboxes[i]->setCheckState(Qt::Unchecked);
+ }
+ }
+ allOff->setDown(false);
+ }
+
+
+ for(int n=0;n<3;n++){
+ if(storePosition[n]->isDown()){
+ QMessageBox msgBox;
+ msgBox.setText("You are about to change the coordinates of the buttons");
+ msgBox.setInformativeText("Are you sure you want to do it?");
+ msgBox.setStandardButtons(QMessageBox::Cancel | QMessageBox::Yes);
+ msgBox.setDefaultButton(QMessageBox::Cancel);
+ int reply = msgBox.exec();
+ if (reply == QMessageBox::Yes){
+ cout<<"Set "<<n<<endl;
+
+ *positionInformation[n*6] = robot->industrialRobot->getCurrentTarget().x;
+ *positionInformation[n*6+1] = robot->industrialRobot->getCurrentTarget().y;
+ *positionInformation[n*6+2] = robot->industrialRobot->getCurrentTarget().z;
+ *positionInformation[n*6+3] = robot->industrialRobot->getCurrentDir().x;
+ *positionInformation[n*6+4] = robot->industrialRobot->getCurrentDir().y;
+ *positionInformation[n*6+5] = robot->industrialRobot->getCurrentDir().z;
+ storePosition[n]->setDown(false);
+ } else {
+ storePosition[n]->setDown(false);
+ }
+ }
+ }
+ if(!isActive()){
+ foundMasterSafePos = false;
+ vidGrabber->setExposure(62);
+ }
+ if(isActive()){
+ if(numChanges > 0){
+ controllerItem->locked = true;
+ }
+// controllerItem->locked = t;
+
+ vidGrabber->setExposure(8);
+ if(curButton == -1){
+ //No changes to the matrix
+ cout<<"Set rate to zero"<<endl;
+ rate = 0;
+ v = ofxIndustrialRobotDefines::Up;
+ ofxVec3f safeDist = buttonPosition(3*12+1) - cornerDir(0)*300.0;
+ robot->industrialRobot->setGravityTarget(safeDist, cornerDir(3), 0.05, 1.0, v);
+ if(robot->industrialRobot->isRobotReady(100)){
+ controllerItem->locked = false;
+ }
+
+ }
+
+
+ int row = curButton / 12;
+ int col = curButton-row*12;
+ if(!foundMasterSafePos){
+ v = ofxIndustrialRobotDefines::Up;
+ ofxVec3f safeDist = buttonPosition(3*12+1) - cornerDir(0)*300.0;
+ cout<<robot->industrialRobot->setGravityTarget(safeDist, cornerDir(3), 0.05, 1.0, v)<<endl;
+ if(robot->industrialRobot->isRobotReady(30.0)){
+ foundMasterSafePos = true;
+ }
+
+ } else {
+ ofxIndustrialRobotDefines::HandVariant vOpp;
+ if(v == ofxIndustrialRobotDefines::Up){
+ vOpp = ofxIndustrialRobotDefines::Down;
+ }
+ else {
+ vOpp = ofxIndustrialRobotDefines::Up;
+ }
+
+ if(curButton > -1){
+ ofxVec3f xdir = ((cornerPos(1)+ofxVec3f(0,10,0)) - cornerPos(0))/11.0;
+ ofxVec3f ydir = ((cornerPos(2)) - cornerPos(0))/7.0;
+ ofxVec3f buttonPos = buttonPosition(curButton);
+
+ ofxVec3f buttonDir = cornerDir(curButton);
+ ofxVec3f safeDist = buttonPos - cornerDir(curButton)*60.0;
+
+ ofxVec3f camOffset = ofxVec3f(0,-100,0);
+ if(v == ofxIndustrialRobotDefines::Down){
+ camOffset *= -1;
+ }
+
+ //if(robot->industrialRobot->willChangeVariant()){
+ // cout<<robot->industrialRobot->getVariantGoal() <<" "<< v<<endl;
+ if(robot->industrialRobot->getVariantGoal() != v){
+ cout<<"Will change variant"<<endl;
+
+ if(robot->industrialRobot->thread.lock()){
+ cout<<"Will change variant"<<endl;
+
+ float rotations[5], rotationsTmp[5];
+ for(int i=0;i<5;i++){
+ rotations[i] = rotationsTmp[i] = robot->industrialRobot->thread.coreData.arms[i].rotation;
+ }
+ if(v == ofxIndustrialRobotDefines::Up){
+ if(rotations[0] < -90){
+ rotations[0] = -110;
+ } else {
+ rotations[0] = -50;
+ }
+ rotations[1] = -13.5;//robot->industrialRobot->thread.converter->getMinRotation(1, rotations)+5;
+// rotations[2] -= rotations[1] - rotationsTmp[1];
+ rotations[2] = 110.0;
+ rotations[3] -= rotations[1] - rotationsTmp[1];
+ rotations[3] -= rotations[2] - rotationsTmp[2];
+ } else {
+ if(rotations[0] < -90){
+ rotations[0] = -110;
+ } else {
+ rotations[0] = -50;
+ }
+ rotations[1] = -13.5 ;//robot->industrialRobot->thread.converter->getMinRotation(1, rotations)+5;
+// rotations[2] -= rotations[1] - rotationsTmp[1];
+ rotations[2] = 119.0;
+ rotations[3] -= rotations[1] - rotationsTmp[1];
+ rotations[3] -= rotations[2] - rotationsTmp[2];
+ }
+ // rotations[3] += 180;
+ // rotations[4] -= 180;
+ for(int i=0;i<5;i++){
+ robot->industrialRobot->thread.coreData.arms[i].rotation = rotations[i];
+ }
+ if(!robot->industrialRobot->setGravityTarget(robot->industrialRobot->thread.helper->getEndPosition(5), robot->industrialRobot->thread.helper->getTargetDir(), 0.05,2, vOpp, false)){
+ cout<<"Could not add safe rotations point"<<endl;
+ } else {
+ cout<<"Goto variant change position"<<endl;
+ }
+ for(int i=0;i<5;i++){
+ robot->industrialRobot->thread.coreData.arms[i].rotation = rotationsTmp[i];
+ }
+
+
+ if(robot->industrialRobot->isRobotReady(5.0,false)){
+ if(v == ofxIndustrialRobotDefines::Up){
+ robot->industrialRobot->thread.controller->helper->data->reverseHeadPercentGoal = 1.0;
+ }
+
+ if(v == ofxIndustrialRobotDefines::Down){
+ robot->industrialRobot->thread.controller->helper->data->reverseHeadPercentGoal = 0.0;
+ }
+ cout<<"Change to "<<robot->industrialRobot->thread.controller->helper->data->reverseHeadPercentGoal<<" "<<robot->industrialRobot->thread.controller->helper->data->reverseHeadPercent<<endl;
+ }
+
+ robot->industrialRobot->thread.unlock();
+ }
+
+ } else {
+
+ if(pressedTimer == 0){
+ if(!foundToSafePos){
+ // controllerItem->locked = false;
+ if(robot->industrialRobot->isLegalTarget(safeDist, buttonDir, vOpp) && ((row > 3 && v == ofxIndustrialRobotDefines::Up) || (row <= 3 && v == ofxIndustrialRobotDefines::Down))){
+ if(row > 3){
+ v = ofxIndustrialRobotDefines::Down;
+ cout<<"Down"<<endl;
+ } else {
+ v = ofxIndustrialRobotDefines::Up;
+ cout<<"Up"<<endl;
+ }
+ }
+ else if(robot->industrialRobot->setGravityTarget(safeDist, buttonDir, parSliders[0]->value()/1000.0, 5.0*parSliders[1]->value()/1000.0, v)){
+ // cout<<"goto safe pos"<<endl;
+
+ if(robot->industrialRobot->isRobotReady(30.0*parSliders[2]->value()/1000.0)){
+ foundToSafePos = true;
+ // cout<<"Found safe pos"<<endl;
+ } else {
+ // cout<<"Not ready"<<endl;
+ }
+ } /*else if(robot->industrialRobot->isLegalTarget(safeDist, buttonDir, vOpp)){
+ v = vOpp;
+ }*/ else {
+ cout<<"Could not add safe pos point 1"<<endl;
+ }
+ } else {
+ // controllerItem->locked = true;
+ if(robot->industrialRobot->setGravityTarget(buttonPos, buttonDir,parSliders[3]->value()/1000.0, 3.0*parSliders[4]->value()/1000.0, v)){
+ if(robot->industrialRobot->isRobotReady(30.0*parSliders[5]->value()/1000.0)){
+ confirmedPress = false;
+ pressedTimer = 1;
+ cout<<"Found button pos"<<endl;
+
+
+ if(robot->industrialRobot->setGravityTarget(safeDist, buttonDir, parSliders[6]->value()/1000.0, 3.0*parSliders[7]->value()/1000.0, v)){
+
+ } else {
+ cout<<"Could not add safe pos point 2"<<endl;
+ }
+ }
+ } else {
+ cout<<"Could not add button pos point"<<endl;
+ }
+ }
+ } else {
+ foundToSafePos = false;
+ //controllerItem->locked = false;
+ if(!robot->industrialRobot->isRobotReady(20.0*parSliders[8]->value()/1000.0)){
+ // controllerItem->locked = true;
+ // robot->industrialRobot->setGravityTarget(safeDist, buttonDir, parSliders[6]->value()/1000.0, 3.0*parSliders[7]->value()/1000.0, v);
+ // cout<<"Go to safe back"<<endl;
+ } else {
+ if(!confirmedPress){
+ confirmedPress = true;
+
+ ofxVec3f camDir;
+ if(v == ofxIndustrialRobotDefines::Up){
+ camDir = buttonDir+ofxVec3f(0,-0.1,0);
+ }
+
+ if(v == ofxIndustrialRobotDefines::Down){
+ camDir = buttonDir+ofxVec3f(0,0.1,0);
+ }
+
+ if(robot->industrialRobot->setGravityTarget(safeDist+camOffset,camDir, parSliders[6]->value()/1000.0, 3.0*parSliders[7]->value()/1000.0, v)){
+
+ } else {
+ cout<<"Could not add confirmPos"<<endl;
+ }
+ } else {
+// cout<<"Check light: "<<isLightOn()<<" "<<lightTurnedOn[curButton]<<endl;
+ if(isLightOn() != lightTurnedOn[curButton] || buttonRepeat > 8 ){
+ lightTurnedOn[curButton] = !lightTurnedOn[curButton];
+ if(lightTurnedOn[curButton ])
+ checkboxes[curButton]->setCheckState(Qt::Checked);
+ else
+ checkboxes[curButton]->setCheckState(Qt::Unchecked);
+
+ buttonRepeat = 0;
+ } else {
+ buttonRepeat ++;
+ /* if(lightTurnedOn[curButton])
+ checkboxes[curButton]->setCheckState(Qt::Unchecked);
+ else
+ checkboxes[curButton]->setCheckState(Qt::Checked);
+ */
+ }
+ pressedTimer = 0;
+ // curButton ++;
+ lastButton = curButton;
+ curButton = -1;
+ // curButton = ofRandom(0, 95);
+ // curButton ++;
+ /* if(curButton > s.length()-1){
+ curButton = 0;
+ rate = 0;
+ }*/
+ // curButton = int( ofRandom(0, 10));
+ // curRow = int(ofRandom(0, 3));
+ cout<<"Done"<<endl;
+ }
+ }
+ }
+ }
+ }
+ else {
+ //No button
+ /* v = ofxIndustrialRobotDefines::Up;
+ ofxVec3f safeDist = cornerPos(lastButton) - cornerDir(lastButton)*300.0;
+ robot->industrialRobot->setGravityTarget(safeDist, cornerDir(0), 0.1, 1.0, v);
+ */
+ }
+ }
+
+ }
+
+ isLightOnImg = robotData->srcImgGray;
+ isLightOnImg.threshold(sliderLightOnThreshold1->value());
+ //isLightOn();
+}
+
+ofxVec3f ButtonMatrixMode::cornerPos(int n){
+ return ofxVec3f(*positionInformation[n*6], *positionInformation[n*6+1], *positionInformation[n*6+2] );
+}
+ofxVec3f ButtonMatrixMode::cornerDir(int n){
+ // cout<<*positionInformation[n*6]+3<<endl;
+ int row = n / 12;
+ int col = n-row*12;
+ if(col < 2){
+ return ofxVec3f(0.2,-0.09,0.95).normalized();
+ } else {
+ return ofxVec3f(0.0,-0.09,0.95).normalized();
+ }
+
+ // return ofxVec3f(*positionInformation[n*6+3], *positionInformation[n*6+4], *positionInformation[n*6+5] )+ofxVec3f(0.1,0,0);
+}
+
+ofxVec3f ButtonMatrixMode::buttonPosition(int n){
+ int row = n / 12;
+ int col = n-row*12;
+
+ // ofxVec3f xdir = ((cornerPos(1)+ofxVec3f(0,20,0)) - cornerPos(0))/11.0;
+ // ofxVec3f ydir = ((cornerPos(2)) - cornerPos(0))/7.0;
+
+ ofxVec3f pos = cornerPos(0) + xdir()*col + ydir()*row;
+ if(col < 6){
+ if(col%2 == 1){
+ pos -= ofxVec3f(0,10,0);
+ }
+ } else {
+ pos -= ofxVec3f(0,10,0);
+ if(col%2 == 1){
+ pos -= ofxVec3f(0,10,0);
+ }
+ }
+ return pos;
+
+}
+
+
+ofxVec3f ButtonMatrixMode::xdir(){
+ return ((cornerPos(1)+ofxVec3f(0,20,0)) - cornerPos(0))/11.0;
+}
+ofxVec3f ButtonMatrixMode::ydir (){
+ return ((cornerPos(2)) - cornerPos(0))/7.0;
+}
+
+
+bool ButtonMatrixMode::isPointInBoundingbox(ofxVec3f p, float depth){
+
+ ofxVec3f p0 = cornerPos(0);
+ ofxVec3f p1 = cornerPos(1);
+ ofxVec3f p2 = cornerPos(2)+xdir()*11;
+ ofxVec3f p3 = cornerPos(2);
+ // cout<<p0.z<<" "<<p1.z<<" "<<p2.z<<" "<<p3.z<<endl;
+
+ float xPercent = (p.x-p0.x)/(p1.x-p0.x);
+ float yPercent = (p.y-p0.y)/(p0.y-p3.y);
+
+ float dz = (p1.z-p0.z);
+ float dyz = (p3.z-p0.z);
+
+ float bz = p0.z + dyz*yPercent +dz*xPercent-depth;// - depth+robot->industrialRobot->getHandLength() + (robot->industrialRobot->getCurrentDir()*robot->industrialRobot->getHandLength()).z;
+ if(robot->industrialRobot->getCurrentDir().z < 0){
+ bz += (robot->industrialRobot->getCurrentDir()*robot->industrialRobot->getHandLength()).z;
+ }
+ if(p.z > bz){
+ return true;
+ }
+ return false;
+
+ // cout<<bz<<endl;
+
+ // if(p.
+}
+
+
+void ButtonMatrixMode::pictureReady(bool boolPoints[])
+{
+
+ int numChanges=0;
+ for(int x=0;x < LIGHTS_WIDTH*LIGHTS_HEIGHT;x++){
+ if(boolPoints[x] != lightTurnedOn[x]){
+ numChanges++;
+ }
+ }
+
+ if(numChanges > 4){
+ rate = 90;
+
+ int n = 0;
+
+ for(int x=0;x < LIGHTS_WIDTH*LIGHTS_HEIGHT;x++)
+
+ {
+
+ if(boolPoints[n])
+ {
+ //cout << "true";
+ }
+ if(boolPoints[n] != lightTurnedOn[n])
+ {
+ checkboxes[n]->setCheckState(Qt::PartiallyChecked);
+ }
+ if(boolPoints[n] == lightTurnedOn[n])
+ {
+ if(boolPoints[n]){
+ checkboxes[n]->setCheckState(Qt::Checked);
+ } else {
+ checkboxes[n]->setCheckState(Qt::Unchecked);
+ }
+
+ }
+
+ n++;
+
+ }
+ }
+
+
+
+}
+
+bool ButtonMatrixMode::isLightOn()
+{
+
+ cout << "lights ont:" << sliderLightOnThreshold2->value() <<" "<< cvCountNonZero(isLightOnImg.getCvImage()) << "\n";
+
+ return sliderLightOnThreshold2->value() < cvCountNonZero(isLightOnImg.getCvImage());
+
+}
View
63 brandts/ButtonMatrixMode.h
@@ -0,0 +1,63 @@
+#pragma once
+#include "Mode.h"
+
+#include "VideoGrabber.h"
+
+class ButtonMatrixMode : public Mode{
+public:
+ ButtonMatrixMode(Robot * robot, myData * data);
+
+ void init();
+ void activate();
+ bool deactivate();
+ void step();
+ void securityCheck();
+
+
+ float pressedTimer;
+
+ bool foundMasterSafePos;
+ bool foundToSafePos;
+
+ int curButton;
+
+ QCheckBox *checkboxes[96];
+ QPushButton * storePosition[3];
+ QSlider * parSliders[3*3];
+
+ QPushButton * allOn;
+ QPushButton * allOff;
+
+ QPushButton * resetFlags;
+
+ float lightTurnedOn[96];
+
+ float* positionInformation[3*3*2];
+
+ ofxVec3f cornerPos(int n);
+ ofxVec3f cornerDir(int n);
+ ofxVec3f buttonPosition(int n);
+
+ void pictureReady(bool points[]);
+
+
+ ofxCvGrayscaleImage isLightOnImg;
+ QSlider * sliderLightOnThreshold1;
+ QSlider * sliderLightOnThreshold2;
+ bool isLightOn();
+
+ QGridLayout * gridLayout;
+
+ bool isPointInBoundingbox(ofxVec3f p, float depth);
+
+ ofxVec3f xdir();
+ ofxVec3f ydir();
+
+ ofxIndustrialRobotDefines::HandVariant v;
+ int lastButton;
+
+ bool confirmedPress;
+ int buttonRepeat;
+ VideoGrabber * vidGrabber;
+
+};
View
177 brandts/DrawingMode.cpp
@@ -0,0 +1,177 @@
+/*
+ * LightButtonMode.cpp
+ * openframeworksQT
+ *
+ * Created by Jonas Jongejan on 27/07/09.
+ * Copyright 2009 HalfdanJ. All rights reserved.
+ *
+ */
+
+#include "DrawingMode.h"
+
+
+DrawingMode::DrawingMode(Robot * _robot, myData * _data){
+ name = "DrawingMode";
+ robot = _robot;
+ robotData = _data;
+ gotPicture = false;
+ timer = 0;
+ foundMasterSafePos = false;
+
+ init();
+
+ QVBoxLayout * tabLayout = new QVBoxLayout();
+ widget->setLayout(tabLayout);
+
+
+ QWidget * gridButton = new QWidget();
+ QGridLayout * gridButtonLayout = new QGridLayout();
+ gridButtonLayout->setAlignment(Qt::AlignTop);
+ gridButtonLayout->setAlignment(Qt::AlignCenter);
+ gridButton->setLayout(gridButtonLayout);
+ gridButton->setFixedHeight(50);
+ gridButton->setContentsMargins(0,0,0,0);
+
+ tabLayout->addWidget(gridButton);
+
+ lastCaptureTime = 0;
+ storePosition[0] = new QPushButton("grab_pos");
+
+ gridButtonLayout->addWidget(new QLabel("Store"), 0, 0);
+ for(int i=0;i<1;i++){
+ gridButtonLayout->addWidget(storePosition[i], 0, i+1);
+ }
+ for(int n=0;n<3*3*2;n++){
+ positionInformation[n] = new float(0);
+ }
+
+
+}
+
+
+
+void DrawingMode::init(){
+ controllerItem = robot->addRobotController("drawingMode", CONTROL_MODE_GRAVITY);
+}
+
+void DrawingMode::activate(){
+ robot->setRobotController(controllerItem);
+ rate = rate + 30;
+}
+bool DrawingMode::deactivate(){
+ if(controllerItem->locked){
+ return false;
+ }
+ return true;
+}
+
+void DrawingMode::step(){
+ rate +=0.03;
+
+
+ for(int n=0;n<1;n++){
+ if(storePosition[n]->isDown()){
+ QMessageBox msgBox;
+ msgBox.setText("You are about to change the coordinates of the buttons");
+ msgBox.setInformativeText("Are you sure you want to do it?");
+ msgBox.setStandardButtons(QMessageBox::Cancel | QMessageBox::Yes);
+ msgBox.setDefaultButton(QMessageBox::Cancel);
+ int reply = msgBox.exec();
+ if (reply == QMessageBox::Yes){
+ cout<<"Set"<<endl;
+
+ *positionInformation[n*6] = robot->industrialRobot->getCurrentTarget().x;
+ *positionInformation[n*6+1] = robot->industrialRobot->getCurrentTarget().y;
+ *positionInformation[n*6+2] = robot->industrialRobot->getCurrentTarget().z;
+ *positionInformation[n*6+3] = robot->industrialRobot->getCurrentDir().x;
+ *positionInformation[n*6+4] = robot->industrialRobot->getCurrentDir().y;
+ *positionInformation[n*6+5] = robot->industrialRobot->getCurrentDir().z;
+ storePosition[n]->setDown(false);
+ } else {
+ storePosition[n]->setDown(false);
+ }
+ }
+ }
+
+ if(isActive()){
+
+ if (!gotPicture)
+ {
+
+ if((robot->industrialRobot->getCurrentTarget()-getPos(0)).length() > 500){
+ if(!robot->industrialRobot->setGravityTarget(getPos(0), getPos(0).normalized()*ofxVec3f(1.0,0.0,1.0)-ofxVec3f(0.4,0.1,0), 0.1, 2.0, ofxIndustrialRobotDefines::Up)){
+ //cout<<(getPos(0).normalized()*ofxVec3f(1.0,0.0,1.0)).x<<" "<<(getPos(0).normalized()*ofxVec3f(1.0,0.0,1.0)).y<<" "<<(getPos(0).normalized()*ofxVec3f(1.0,0.0,1.0)).z<<endl;
+ //cout<<"Could not add drawing mode pre target"<<endl;
+ }
+ } else {
+ if(!robot->industrialRobot->setGravityTarget(getPos(0), getDir(0), 0.1, 1.0, ofxIndustrialRobotDefines::Up)){
+ cout<<"Could not add drawing mode target"<<endl;
+ } else {
+ if(robot->industrialRobot->isRobotReady(0.0001)){
+ timer ++;
+ if(timer > 30){
+ cout<<"drawing mode ready for taking photo"<<endl;
+ if(!gotPicture && grabTheDrawing->doGrab(false))
+ {
+ cout<<"Found picture"<<endl;
+ buttonMatrixMode->pictureReady(grabTheDrawing->convertToBool());
+ if(lastCaptureTime + 60000 < ofGetElapsedTimeMillis() || ofGetElapsedTimeMillis()+100 < lastCaptureTime){
+ ofImage img;
+ img.setImageType(GL_RGB);
+ img.setFromPixels(grabTheDrawing->interpretatedImg.getPixels(), grabTheDrawing->interpretatedImg.width, grabTheDrawing->interpretatedImg.height, false);
+ img.saveImage("/Brandts/picture small "+ofToString(ofGetDay(),0)+"."+ofToString(ofGetMonth(),0)+"."+ofToString(ofGetYear(),0)+" - "+ofToString(ofGetMinutes(),0)+"-"+ofToString(ofGetMinutes(),0)+"-"+ofToString(ofGetSeconds(),0)+".jpg");
+
+ ofImage img2;
+ img2.setImageType(GL_RGB);
+ img2.setFromPixels(grabTheDrawing->tmpGrayImg2.getPixels(), grabTheDrawing->tmpGrayImg2.width, grabTheDrawing->tmpGrayImg2.height, false);
+ img2.saveImage("/Brandts/picture "+ofToString(ofGetDay(),0)+"."+ofToString(ofGetMonth(),0)+"."+ofToString(ofGetYear(),0)+" - "+ofToString(ofGetMinutes(),0)+"-"+ofToString(ofGetMinutes(),0)+"-"+ofToString(ofGetSeconds(),0)+".jpg");
+
+
+
+ lastCaptureTime = ofGetElapsedTimeMillis();
+ }
+ gotPicture = true;
+ } else {
+ cout<<"No picture found"<<endl;
+ gotPicture = false;
+ }
+ rate = 0;
+ timer = 0;
+ }
+
+ }
+ }
+ }
+
+
+ }
+ }
+ else
+ {
+ if(motionDetector->isAreaActive(0, 5, 4,5, 0.35))
+ {
+ if(rate< 50 && rate > 30)
+ {
+ rate = 50;
+ }
+ rate +=0.08;
+
+ }
+ gotPicture = false;
+ }
+ if (rate > 70)
+ {
+ rate = 40;
+ }
+
+}
+
+ofxVec3f DrawingMode::getPos(int n){
+ return ofxVec3f(*positionInformation[n*6], *positionInformation[n*6+1], *positionInformation[n*6+2] );
+}
+ofxVec3f DrawingMode::getDir(int n){
+ // cout<<*positionInformation[n*6]+3<<endl;
+ //return ofxVec3f(-0,-0.3,1);
+ return ofxVec3f(*positionInformation[n*6+3], *positionInformation[n*6+4], *positionInformation[n*6+5] );
+}
+
View
35 brandts/DrawingMode.h
@@ -0,0 +1,35 @@
+#pragma once
+#include "Mode.h"
+#include "GrabTheDrawing.h"
+#include "ButtonMatrixMode.h"
+
+#include "VideoGrabber.h"
+#include "MotionDetector.h"
+
+class DrawingMode : public Mode{
+public:
+ DrawingMode(Robot * robot, myData * data);
+
+ void init();
+ void activate();
+ bool deactivate();
+ void step();
+ ButtonMatrixMode * buttonMatrixMode;
+ float pressedTimer;
+
+ bool foundMasterSafePos;
+ MotionDetector * motionDetector;
+ QPushButton * storePosition[3];
+
+ bool gotPicture;
+ float* positionInformation[3*3*2];
+
+ GrabTheDrawing * grabTheDrawing;
+ ofxVec3f getPos(int n);
+ ofxVec3f getDir(int n);
+
+ int timer;
+ int lastCaptureTime;
+
+ VideoGrabber * vidGrabber;
+};
View
239 brandts/FaceTrackerMode.cpp
@@ -0,0 +1,239 @@
+#include "FaceTrackerMode.h"
+
+FaceTrackerMode::FaceTrackerMode(Robot * _robot, myData * _data){
+ name = "FaceTracker";
+ robot = _robot;
+ robotData = _data;
+ rate = 0;
+ idlePosition = ofxVec3f(1560, 1460, 0);
+
+ maxX = 2100;
+ minX = 1390;
+ maxY = 1660;
+ minY = 1170;
+ maxZ = 750;
+
+ init();
+ noFaceCount = 0;
+ lastCaptureTime = 0;
+ randomCount = 0;
+}
+
+void FaceTrackerMode::init(){
+ controllerItem = robot->addRobotController("FaceTracker", CONTROL_MODE_GRAVITY);
+}
+void FaceTrackerMode::activate(){
+ robot->setRobotController(controllerItem);
+
+ rate = rate + 10;
+}
+bool FaceTrackerMode::deactivate(){
+ if(controllerItem->locked){
+ return false;
+ }
+ return true;
+}
+void FaceTrackerMode::step(){
+ rate += 0.01;
+
+ if(rate > 50){
+ rate = 30;
+ }
+
+ if(isActive()){
+
+ /* if( !robot->industrialRobot->setGravityTarget(idlePosition, idleDirection, 0.1, 1, ofxIndustrialRobotDefines::Up)){
+ cout<<"Could not add facetracker"<<endl;
+ }
+ */
+ updateFacetracking();
+
+ }
+ else
+ {
+ if(motionDetector->isAreaActive(5, 0, 5, 3, 0.2))
+ {
+ if(rate < 30 && rate > 10)
+ {
+ rate = 30;
+ }
+ rate +=0.04;
+
+ }
+ }
+}
+
+void FaceTrackerMode::updateFacetracking()
+{
+ // if(robot->industrialRobot->timelineCuesLeft() < 2){
+ /*
+
+ if(!(vec->x == 0 && vec->y==0 && vec->z==0) && !robot->industrialRobot->addPositionCue(80.0, ofxVec3f(1169.0+ vec->x,700.824+ vec->y,-400.0), ofxVec3f(0.0,-1.0,0),false)){
+ cout<<"Could not add facetracker"<<endl;
+ }
+ }*/
+
+ ofxCvBlob * blob = faceTracker->getBiggestFace();
+ noFaceCount ++;
+
+
+ if(blob != NULL){
+ noFaceCount -= 5;
+ if(noFaceCount<0)
+ noFaceCount = 0;
+ float w = FACEWIDTH;
+ float h = FACEHEIGHT;
+ float factor = CAPWIDTH/FACEWIDTH;
+ // cout<< blob->boundingRect.width<<endl;
+ //float x = 2200;
+
+ /*
+ float x = robot->industrialRobot->getCurrentTarget().x - (blob->boundingRect.width-50)*5.0;
+
+ ofxVec3f target = ofxVec3f(x, robot->industrialRobot->getCurrentTarget().y - (blob->centroid.y-h/2.0)*1.5, robot->industrialRobot->getCurrentTarget().z + (blob->centroid.x-w/2.0)*1.0);
+ if( !robot->industrialRobot->setGravityTarget(target, ofxVec3f(1.0,0.2,-0))){
+ // cout<<"Could not add facetracker"<<endl;
+ }
+ */
+
+ ofxVec3f curDir = robot->industrialRobot->getCurrentDir();
+ ofxVec3f curPos = robot->industrialRobot->getCurrentTarget();
+ float z = curDir.z + (blob->centroid.x-w/2.0)*0.002*factor;
+ //cout<<z<<" "<<(blob->centroid.x-w/2.0)<<endl;
+ float y = curDir.y - (blob->centroid.y-h/2.0)*0.002*factor;
+ // y = curDir.y
+ ofxVec3f targetDir = ofxVec3f(0.9, y, z).normalized();
+
+ ofxVec3f armDir = curPos.normalized();
+
+ if(targetDir.y > 0.7)
+ targetDir.y = 0.7;
+ if(targetDir.y < -0.7)
+ targetDir.y = -0.7;
+
+ if(targetDir.z > 0.4+armDir.z)
+ targetDir.z = 0.4+armDir.z;
+ if(targetDir.z < -0.4+armDir.z)
+ targetDir.z = -0.4+armDir.z;
+
+
+
+ float tx = robot->industrialRobot->getCurrentTarget().x - (blob->boundingRect.width-40)*2.0;
+ // tx = (blob->boundingRect.width-40)*40 + 1800;
+ tx = (maxX-300- robot->industrialRobot->getCurrentTarget().x)*0.1 + robot->industrialRobot->getCurrentTarget().x;
+
+ ofxVec3f targetPosition = curPos;
+
+ ofxVec3f target = targetPosition; // + targetDir.normalized()*robot->industrialRobot->getHandLength();
+ target.x = tx;
+ if(target.x > maxX){
+ target.x = maxX;
+ }
+ if(target.x < minX){
+ target.x = minX;
+ }
+
+ if(noFaceCount < 40){
+ if(robot->industrialRobot->thread.lock()){
+ if(robot->industrialRobot->thread.coreData.reverseHeadPercent < 0.2 || robot->industrialRobot->thread.coreData.reverseHeadPercent > 0.8){
+ if( !robot->industrialRobot->setGravityTarget(target, targetDir, 0.1, 2, ofxIndustrialRobotDefines::Up,false)){
+ cout<<"Could not add facetracker scale "<<target.x<<", "<<target.y<<", "<<target.z<<" - "<<targetDir.x<<", "<<targetDir.y<<", "<<targetDir.z<<endl;
+ }
+ }
+ robot->industrialRobot->thread.unlock();
+ }
+ }
+ //cout<<"face"<<endl;
+
+ }
+ else {
+
+ }
+
+ if(noFaceCount > 40){
+ if(rate > 60){
+ rate = 30;
+ }
+ rate -=0.1;
+
+ robot->industrialRobot->lockVariant(false);
+
+ if(noFaceCount > 100){
+ noFaceCount = 100;
+ }
+ //cout<<"No face"<<endl;
+
+ /*
+ It is a nice try but quickly becoms jaggy - smoothness needed - mads
+ if(randomCount > 50)
+ {
+ idlePositionRandomized = idlePosition;
+ idlePositionRandomized.x = idlePositionRandomized.x + ofRandom(-30,0)*2;
+ randomCount =0;
+ }
+ randomCount++;*/
+
+
+ // idleDirection = ofxVec3f(2.0,-0.2,sin(ofGetElapsedTimeMillis()/5000.0)).normalized();
+ if(robot->industrialRobot->isRobotDirReady(0.1)){
+ idleDirection = ofxVec3f(2.0,ofRandom(-0.4, -0.05), ofRandom(-1.0, 1.0)).normalized();
+ ofxVec3f offsetPos = ofxVec3f(ofRandom(-200,200), ofRandom(-200,400), ofRandom(-200,200));
+ if( !robot->industrialRobot->setGravityTarget(idlePosition+offsetPos, idleDirection, 0.05, 0.4, ofxIndustrialRobotDefines::Up)){
+ cout<<"Could not add facetracker"<<endl;
+ }
+ }
+
+ } else {
+ if(lastCaptureTime + 60000 < ofGetElapsedTimeMillis() || ofGetElapsedTimeMillis()+100 < lastCaptureTime){
+ ofImage img;
+ img.setImageType(GL_RGB);
+ img.setFromPixels(faceTracker->imgBiggestFace.getPixels(), faceTracker->imgBiggestFace.width, faceTracker->imgBiggestFace.height, false);
+ img.saveImage("/Brandts/facepositive"+ofToString(ofGetDay(),0)+"."+ofToString(ofGetMonth(),0)+"."+ofToString(ofGetYear(),0)+" - "+ofToString(ofGetMinutes(),0)+"-"+ofToString(ofGetMinutes(),0)+"-"+ofToString(ofGetSeconds(),0)+".jpg");
+
+ lastCaptureTime = ofGetElapsedTimeMillis();
+ }
+
+ rate += 0.1;
+ //cout << "motion tracker counting";
+
+
+ if(rate > 70){
+ rate = 40;
+ }
+
+ robot->industrialRobot->lockVariant(true);
+
+ // cout<<"face1"<<endl;
+ // if(robot->industrialRobot->thread.lock()){
+ ofxVec3f curTarget = robot->industrialRobot->getCurrentTarget();
+ ofxVec3f curDir = robot->industrialRobot->getCurrentDir();
+
+ float tz = curTarget.z - ( curTarget.normalized().z-curDir.z)*90.0;;
+
+ if(tz > maxZ){
+ tz = maxZ;
+ }
+ if(tz < -maxZ){
+ tz = -maxZ;
+ }
+
+ float ty = curTarget.y - ( -0.15-curDir.y)*200.0;;
+
+ if(ty > maxY){
+ ty = maxY;
+ }
+ if(ty < minY){
+ ty = minY;
+ }
+
+ ofxVec3f target = ofxVec3f(robot->industrialRobot->getCurrentGravityTarget().x,ty,tz);
+ if( !robot->industrialRobot->setGravityTarget(target, robot->industrialRobot->getCurrentGravityDir(), 0.1, 1, ofxIndustrialRobotDefines::Up)){
+ cout<<"Could not add facetracker pos "<<robot->industrialRobot->getCurrentGravityTarget().x<<" "<<ty<<" "<<tz<<endl;
+ }
+ // robot->industrialRobot->thread.unlock();
+ }
+
+ //}
+
+
+}
View
37 brandts/FaceTrackerMode.h
@@ -0,0 +1,37 @@
+#pragma once
+#include "Mode.h"
+#include "FaceTracker.h"
+#include "VideoGrabber.h"
+#include "MotionDetector.h"
+
+class FaceTrackerMode : public Mode {
+public:
+ FaceTrackerMode(Robot * robot, myData * data);
+
+ void init();
+ void activate();
+ bool deactivate();
+ void step();
+
+ ofxVec3f idlePosition;
+ ofxVec3f idleDirection;
+
+
+ void updateFacetracking();
+
+ FaceTracker * faceTracker;
+ int noFaceCount;
+ MotionDetector * motionDetector;
+ ofxVec3f idlePositionRandomized ;
+ int randomCount;
+
+
+ float maxX;
+ float minX;
+ float maxY;
+ float minY;
+ float maxZ;
+
+ VideoGrabber * vidGrabber;
+ int lastCaptureTime;
+};
View
61 brandts/IdleMode.cpp
@@ -0,0 +1,61 @@
+/*
+ * IdleMode.cpp
+ * openframeworksQT
+ *
+ * Created by Jonas Jongejan on 27/07/09.
+ * Copyright 2009 HalfdanJ. All rights reserved.
+ *
+ */
+
+#include "IdleMode.h"
+
+IdleMode::IdleMode(Robot * _robot, myData * _data){
+ name = "Idle";
+ robot = _robot;
+ robotData = _data;
+ rate = 20;
+ idlePosition = ofxVec3f(1648, 877, 46);
+
+ init();
+}
+
+void IdleMode::init(){
+ controllerItem = robot->addRobotController("IdleMode", CONTROL_MODE_GRAVITY);
+}
+void IdleMode::activate(){
+ robot->setRobotController(controllerItem);
+}
+bool IdleMode::deactivate(){
+ if(controllerItem->locked){
+ return false;
+ }
+ return true;
+}
+void IdleMode::step(){
+ if( rate > 95)
+ rate = 95;
+
+ if(rate < 0)
+ {
+ rate = 0;
+ }
+
+ if(!motionDetector->isAreaActive(0, 5, 4,5, 0.4) && !motionDetector->isAreaActive(5, 0, 5, 3, 0.4) )
+ {
+ rate +=0.05;
+
+ // cout << "motion to drawingmode";
+ }
+ else
+ {
+ rate -= 10;
+ }
+ if(isActive()){
+
+ idleDirection = ofxVec3f(0.7,-1,sin(ofGetElapsedTimeMillis()/2000.0)).normalized();
+ if( !robot->industrialRobot->setGravityTarget(idlePosition, idleDirection, 0.1, 1, ofxIndustrialRobotDefines::Up)){
+ cout<<"Could not add facetracker"<<endl;
+ }
+
+ }
+}
View
17 brandts/IdleMode.h
@@ -0,0 +1,17 @@
+#pragma once
+#include "Mode.h"
+#include "MotionDetector.h"
+
+class IdleMode : public Mode {
+public:
+ IdleMode(Robot * robot, myData * data);
+
+ void init();
+ void activate();
+ bool deactivate();
+ void step();
+ MotionDetector * motionDetector;
+
+ ofxVec3f idlePosition;
+ ofxVec3f idleDirection;
+};
View
20 brandts/Info.plist
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleGetInfoString</key>
+ <string>Created by Qt/QMake</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleExecutable</key>
+ <string>openframeworksQT</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.yourcompany.openframeworksQT</string>
+ <key>NOTE</key>
+ <string>This file was generated by Qt/QMake.</string>
+</dict>
+</plist>
View
127 brandts/KeyboardMode.cpp
@@ -0,0 +1,127 @@
+/*
+ * LightButtonMode.cpp
+ * openframeworksQT
+ *
+ * Created by Jonas Jongejan on 27/07/09.
+ * Copyright 2009 HalfdanJ. All rights reserved.
+ *
+ */
+
+#include "KeyboardMode.h"
+
+
+KeyboardMode::KeyboardMode(Robot * _robot, myData * _data){
+ name = "Keyboard";
+ robot = _robot;
+ robotData = _data;
+ rate = 0;
+
+ pressedTimer = 0;
+ buttonQ = ofxVec3f(1487.6, 666.2, 1038.6);
+ buttonP = ofxVec3f(1376.6,597.2,1143.0);
+ buttonA = ofxVec3f(1482.6, 646.2, 1032.6);
+ buttonZ = ofxVec3f(1479.6, 628.2, 1022.6);
+ buttonDir = ofxVec3f(0.77, -0.44, 0.62);
+ curButton = 0;
+ foundMasterSafePos = false;
+ curRow = 0;
+ init();
+}
+
+
+void KeyboardMode::init(){
+ controllerItem = robot->addRobotController("Keyboard", CONTROL_MODE_GRAVITY);
+}
+
+void KeyboardMode::activate(){
+ robot->setRobotController(controllerItem);
+}
+bool KeyboardMode::deactivate(){
+ if(controllerItem->locked){
+ return false;
+ }
+ return true;
+}
+
+void KeyboardMode::step(){
+// rate += ofRandom(0,0.09);
+
+ char keys[] = "qwertyuiopåasdfghjklæøzxcvbnm,. ";
+ string s = "im a robot. ";
+ if(isActive()){
+ if(!foundMasterSafePos){
+ ofxVec3f safeDist = buttonQ + ofxVec3f(-30,0,-30);
+ robot->industrialRobot->setGravityTarget(safeDist, buttonDir, 0.1, 1.0, ofxIndustrialRobotDefines::Down);
+
+ if(robot->industrialRobot->isRobotReady(5.0)){
+ foundMasterSafePos = true;
+ }
+
+ } else {
+ int button = strcspn(keys,((string)""+s[curButton]).c_str());
+ int row = 0;
+ if(button == 34){
+ row = 3;
+ button = 5;
+ }else if(button > 24){
+ row = 2;
+ button -= 25;
+ }
+ else if(button > 11){
+ row = 1;
+ button -= 12;
+ }
+ ofxVec3f dir = buttonP - buttonQ;
+ dir /= 9.0;
+ ofxVec3f buttonPosition = buttonQ + dir*button;
+ if(row == 1){
+ buttonPosition += buttonA - buttonQ;
+ }
+ if(row == 2){
+ buttonPosition += buttonZ - buttonQ;
+ }
+ if(row == 3){
+ buttonPosition += buttonA - buttonQ;
+ buttonPosition += buttonZ - buttonQ;
+
+
+ }
+
+ ofxVec3f safeDist = buttonPosition + ofxVec3f(-14,0,-5);
+ if(pressedTimer == 0){
+ if(!foundToSafePos){
+ controllerItem->locked = false;
+ robot->industrialRobot->setGravityTarget(safeDist, buttonDir, 0.1, 1.0, ofxIndustrialRobotDefines::Down);
+ if(robot->industrialRobot->isRobotReady(20)){
+ foundToSafePos = true;
+ }
+ } else {
+ controllerItem->locked = true;
+ robot->industrialRobot->setGravityTarget(buttonPosition, buttonDir,0.1, 1.0, ofxIndustrialRobotDefines::Down);
+ if(robot->industrialRobot->isRobotReady(2.0)){
+ pressedTimer = 1;
+ }
+ }
+ } else {
+ foundToSafePos = false;
+ controllerItem->locked = false;
+ if((robot->industrialRobot->getCurrentTarget() - buttonPosition).length() < 3.0){
+ controllerItem->locked = true;
+ robot->industrialRobot->setGravityTarget(safeDist, buttonDir, 0.1, 1.0, ofxIndustrialRobotDefines::Down);
+ } else {
+ pressedTimer = 0;
+ curButton ++;
+ if(curButton > s.length()-1){
+ curButton = 0;
+ rate = 0;
+ }
+ // curButton = int( ofRandom(0, 10));
+ // curRow = int(ofRandom(0, 3));
+ }
+ }
+ }
+ } else {
+ }
+
+
+}
View
24 brandts/KeyboardMode.h
@@ -0,0 +1,24 @@
+#pragma once
+#include "Mode.h"
+
+class KeyboardMode : public Mode {
+public:
+ KeyboardMode(Robot * robot, myData * data);
+
+ void init();
+ void activate();
+ bool deactivate();
+ void step();
+
+ float pressedTimer;
+
+ bool foundMasterSafePos;
+ bool foundToSafePos;
+ ofxVec3f buttonQ;
+ ofxVec3f buttonP;
+ ofxVec3f buttonA;
+ ofxVec3f buttonZ;
+ int curButton;
+ int curRow;
+ ofxVec3f buttonDir;
+};
View
75 brandts/LightButtonMode.cpp
@@ -0,0 +1,75 @@
+/*
+ * LightButtonMode.cpp
+ * openframeworksQT
+ *
+ * Created by Jonas Jongejan on 27/07/09.
+ * Copyright 2009 HalfdanJ. All rights reserved.
+ *
+ */
+
+#include "LightButtonMode.h"
+
+
+LightButtonMode::LightButtonMode(Robot * _robot, myData * _data){
+ name = "LightBulb";
+ robot = _robot;
+ robotData = _data;
+ rate = 0;
+
+ pressedTimer = 0;
+ buttonPosition = ofxVec3f(1560.0, 834.1, 1119.2);
+ buttonDir = ofxVec3f(0.73, -0.15, 0.67);
+
+
+ init();
+}
+
+
+void LightButtonMode::init(){
+ controllerItem = robot->addRobotController("LightBulb", CONTROL_MODE_GRAVITY);
+}
+
+void LightButtonMode::activate(){
+ robot->setRobotController(controllerItem);
+}
+bool LightButtonMode::deactivate(){
+ if(controllerItem->locked){
+ return false;
+ }
+ return true;
+}
+
+void LightButtonMode::step(){
+// rate += ofRandom(0,0.07);
+
+ if(isActive()){
+ ofxVec3f safeDist = buttonPosition + ofxVec3f(-10,0,-10);
+
+ if(pressedTimer < 100){
+ if(!foundToSafePos){
+ controllerItem->locked = false;
+ robot->industrialRobot->setGravityTarget(safeDist, buttonDir, 0.1, 1.0, ofxIndustrialRobotDefines::Down);
+ if(robot->industrialRobot->isRobotReady(10)){
+ foundToSafePos = true;
+ }
+ } else {
+ controllerItem->locked = true;
+ pressedTimer ++;
+ robot->industrialRobot->setGravityTarget(buttonPosition, buttonDir, 0.1, 1.0, ofxIndustrialRobotDefines::Down);
+ }
+ } else {
+ foundToSafePos = false;
+ controllerItem->locked = false;
+ if((robot->industrialRobot->getCurrentTarget() - buttonPosition).length() < 7.0){
+ controllerItem->locked = true;
+ robot->industrialRobot->setGravityTarget(safeDist, buttonDir, 0.1, 1.0, ofxIndustrialRobotDefines::Down);
+ } else {
+ pressedTimer = 0;
+ rate = 0;
+ }
+ }
+ } else {
+ }
+
+
+}
View
19 brandts/LightButtonMode.h
@@ -0,0 +1,19 @@
+#pragma once
+#include "Mode.h"
+
+class LightButtonMode : public Mode {
+public:
+ LightButtonMode(Robot * robot, myData * data);
+
+ void init();
+ void activate();
+ bool deactivate();
+ void step();
+
+ float pressedTimer;
+
+ bool foundToSafePos;
+ ofxVec3f buttonPosition;
+ ofxVec3f buttonDir;
+
+};
View
17 brandts/Mode.cpp
@@ -0,0 +1,17 @@
+
+/*
+ * Mode.cpp
+ * openframeworksQT
+ *
+ * Created by Jonas Jongejan on 27/07/09.
+ * Copyright 2009 HalfdanJ. All rights reserved.
+ *
+ */
+
+#include "Mode.h"
+
+Mode::Mode(){
+ widget = new QWidget();
+}
+
+
View
31 brandts/Mode.h
@@ -0,0 +1,31 @@
+#pragma once
+#include "ofConstants.h"
+#include "Robot.h"
+#include "Data.h"
+#include "RobotControllerItem.h"
+#include <QGroupBox>
+#include <QGridLayout>
+#include <QLabel>
+#include <QTGui>
+#include <QCheckBox>
+
+class Mode {
+public:
+ RobotControllerItem * controllerItem;
+ Mode();
+ string name;
+ myData * robotData;
+ Robot * robot;
+
+ QWidget * widget;
+
+ float rate;
+
+ virtual void init(){};
+ virtual void activate(){};
+ virtual void step(){};
+ virtual bool deactivate(){};
+ virtual bool isActive(){return controllerItem->isActive();};
+ virtual void securityCheck(){};
+
+};
View
440 brandts/PaperTracker.cpp
@@ -0,0 +1,440 @@
+/*
+ * FaceTracker.cpp
+ * openFrameworks
+ *
+ * Created by mads hobye on 26/05/09.
+ * Copyright 2009 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "PaperTracker.h"
+
+
+void PaperTracker::init(myData * _data, QVBoxLayout * boxLayout)
+{
+
+ data = _data;
+ nameid = "PaperTracker";
+
+
+
+ // GUI
+
+ addBaseGui(boxLayout);
+
+ QGroupBox * sliderArea = new QGroupBox("Motors");
+ QGridLayout *sliderAreaLayout = new QGridLayout;
+ boxLayout->addWidget(sliderArea,0,0);
+
+ sliderHughParam1 = AddQSlider("Param 1", 10, 0, 100, sliderAreaLayout, 1, true);
+ sliderHughParam2 = AddQSlider("Param 2", 10, 0, 100, sliderAreaLayout, 2, true);
+ sliderHoughthreshold = AddQSlider("Threshold", 10,1,100,sliderAreaLayout,3,true);
+ sliderHoughTheta = AddQSlider("HoughTheta", 10,1,300,sliderAreaLayout,4,true);
+ sliderHoughRho = AddQSlider("HoughRo",10,1,300,sliderAreaLayout,5,true);
+ sliderLowerCanny = AddQSlider("Lower Canny",10,1,300,sliderAreaLayout,6,true);
+ sliderHigherCanny = AddQSlider("Higher Canny",10,1,300,sliderAreaLayout,7,true);
+
+ sliderAreaLayout->setAlignment(Qt::AlignTop);
+ sliderArea->setLayout(sliderAreaLayout);
+ sliderArea->setMinimumWidth(460);
+
+
+
+
+
+ // **********************
+
+
+
+ grayImage.allocate(CAPWIDTH,CAPHEIGHT);
+ grayImageScaled.allocate(CAPWIDTH,CAPHEIGHT);
+
+ // EDGE DETECTER
+
+ doCanny = true;
+ lowerCanny = 10;
+ higherCanny = 50;
+
+ doHough = true;
+ linesBeingUpdate = false;
+ houghMethod = CV_HOUGH_PROBABILISTIC;
+ houghRho= 1;
+ houghTheta = 180;
+
+ drawMonitor = false;
+
+ doRectTracking = true;
+ parAMargin = 1;
+
+ rectAMargin = 1;
+
+ anyLines = false;
+
+
+ captureCounter = 0;
+ capturedRect = new oRect();
+ avgRect = new oRect();
+
+}
+
+
+
+
+void PaperTracker::update()
+{
+ grayImage = data->srcImgGray;
+ grayImageScaled.scaleIntoMe(grayImage);
+
+
+
+ canny(&grayImageScaled,sliderLowerCanny->value(),sliderHigherCanny->value());
+
+ linesBeingUpdate = false;
+
+ if(doHough){
+ linesBeingUpdate = true;
+ lines = HoughLines(&grayImageScaled,houghMethod, sliderHoughRho->value(), CV_PI/sliderHoughTheta->value(), sliderHoughthreshold->value(), sliderHughParam1->value(), sliderHughParam2->value());
+ anyLines = true;
+ if(doRectTracking){
+ rectPoints.clear();
+
+ pLines = findParalLines();
+
+ if(pLines.size() > 1){
+
+ //There are at least two parrallel groups (that have different angels)
+ rectPoints =findRect(pLines);
+ // cout<<rectPoints.size()<<end
+ if(rectPoints.size() == 4){
+ //Yes, we found a rectangle!
+
+
+ if(captureCounter == 0){
+
+
+ int minN = -1;
+ float minY = -1;
+ for(int i=0;i<4;i++){
+ if(minY == -1 || minY > rectPoints[i].y){
+ minN = i;
+ minY = rectPoints[i].y;
+ }
+ }
+ if(rectPoints[minN].x < rectPoints[(minN+1)%4].x)
+ avgRect = new oRect(rectPoints[minN],rectPoints[(minN+1)%4],rectPoints[(minN+2)%4],rectPoints[(minN+3)%4]);
+ else
+ avgRect = new oRect(rectPoints[minN],rectPoints[(minN+3)%4],rectPoints[(minN+2)%4],rectPoints[(minN+1)%4]);
+
+ } else {
+ oRect r;
+ for(int i=0;i<4;i++){
+ float s = 0;
+ int best = -1;
+ for(int u=0;u<4;u++){
+ // cout<<"p "<<u<<" "<<rectPoints[u].x<<endl;
+ if(best == -1 || avgRect->p[i].squareDistance(rectPoints[u]) < s){
+ s = avgRect->p[i].squareDistance(rectPoints[u]);
+ best = u;
+ }
+ }
+ r.p[i] = rectPoints[best];
+
+ }
+ // avgRect->add(r);
+ if(fabs(avgRect->w() - r.w()) > 10 || fabs(avgRect->h() - r.h()) > 10 ){
+ captureCounter =- 10*speed;
+ cout<<"Abort"<<endl;
+
+ }
+ }
+ captureCounter += 5.9*speed;
+
+
+
+
+
+ } else {
+
+ }
+ }
+ }
+ else {
+ // cout<<"v"<<ofGetElapsedTimeMillis() - millis<<endl;
+ }
+ }
+}
+
+float PaperTracker::getA(CvPoint* line){
+ return (float)(line[1].y - line[0].y)/(line[1].x - line[0].x);
+}
+float PaperTracker::getB(CvPoint* line){
+ float a = getA(line);
+ return line[0].y- a*line[0].x;
+}
+
+float PaperTracker::dist(int x1, int y1, int x2, int y2){
+ return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
+}
+
+vector<vector<CvPoint*> > PaperTracker::findParalLines(){
+ vector<vector<CvPoint*> > ret;
+ bool * lineAdded = new bool[lines->total];
+ for(int i=0;i<lines->total;i++){
+ lineAdded[i] = false;
+ }
+
+ for(int i=0;i<lines->total;i++){
+ if(lineAdded[i] == false){
+ bool lineFound = false;
+ CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
+ float a1 = getA(line);
+ ofxPoint2f p1a = ofxPoint2f(line[0].x, line[0].y);
+ ofxPoint2f p1b = ofxPoint2f(line[1].x, line[1].y);
+ ofxVec2f v1 = ofxVec2f((p1b-p1a).x, (p1b-p1a).y);
+ ofxPoint2f p1bRot = p1b.rotated(atan(a1)/PI*180, p1a);
+
+
+ for(int u=i+1;u<lines->total;u++){
+ CvPoint* line2 = (CvPoint*)cvGetSeqElem(lines,u);
+ ofxPoint2f p2a = ofxPoint2f(line2[0].x, line2[0].y);
+ ofxPoint2f p2b = ofxPoint2f(line2[1].x, line2[1].y);
+ ofxVec2f v2 = ofxVec2f((p2b-p2a).x, (p2b-p2a).y);
+
+ float a2 = getA(line2);
+ float angle1 = fabs(v1.angle(v2));
+ float angle2 = fabs(v1.angle(-v2));
+ float angle;
+ if(angle1 < angle2)
+ angle = angle1;
+ else
+ angle = angle2;
+
+ //cout<<angle<<endl;
+ if(fabs(angle) < parAMargin ){
+
+ // cout<<"a1: "<<a1<<" "<<atan(a1)/PI*180<<endl;
+ ofxPoint2f p2bRot = p2b.rotated(atan(a1)/PI*180, p1a);
+ // cout<<"y: "<<fabs(p2bRot.y-p1bRot.y)<<endl;
+
+ //if(fabs(p2bRot.y-p1bRot.y) > parMinDist && fabs(p2bRot.y-p1bRot.y) < parMaxDist ){
+ if(!lineFound){
+ lineFound = true;
+ vector<CvPoint*> n;
+ n.push_back(line);
+ ret.push_back(n);
+ lineAdded[i] = true;
+ }
+ ret[ret.size()-1].push_back(line2);
+ lineAdded[u] = true;
+ // }
+ }
+ }
+ }
+ }
+ return ret;
+}
+
+vector<ofxPoint2f> PaperTracker::findRect(vector<vector<CvPoint*> > l){
+ vector<ofxPoint2f> r;
+ r.clear();
+ vector<vector<CvPoint*> > tmp;
+
+ float bestAngle = -1;
+ int bestN1;
+ int bestN2;
+ for(int i=0;i<l.size();i++){
+ float a1;
+ for(int u=0;u<l[i].size();u++){
+ a1 += atan(getA(l[i][u]))/PI*180;
+ }
+ a1 /= l[i].size();
+
+
+ for(int u=i+1;u<l.size();u++){
+ float a2;
+ for(int p=0;p<l[u].size();p++){
+ a2 += atan(getA(l[u][p]))/PI*180;
+ }
+ a2 /= l[u].size();
+ //cout<<fabs(fabs(a2-a1)-90) <<endl;
+ if(fabs(fabs(a2-a1)-90) < rectAMargin){
+ if(fabs(fabs(a2-a1)-90) < bestAngle || bestAngle == -1){
+ bestAngle = fabs(fabs(a2-a1)-90);
+ tmp.clear();
+ bestN1 = i;
+ bestN2 = u;
+ tmp.push_back(l[i]);
+ tmp.push_back(l[u]);
+ }
+ }
+ }
+
+ }
+ // cout<<bestN1<<" - "<<bestN2<<endl;
+ // cout<<"Number of candidate p groups: "<<tmp.size()<<endl;
+ if(tmp.size() >= 2){
+
+ double * la1 = new double[tmp[0].size()];
+ double *lb1 = new double[tmp[0].size()];
+ double *la2 = new double[tmp[1].size()];
+ double *lb2 = new double[tmp[1].size()];
+ for(int i=0; i<tmp[0].size(); i++){
+ la1[i] = getA(tmp[0][i]);
+ lb1[i] = getB(tmp[0][i]);
+ }
+ for(int i=0; i<tmp[1].size(); i++){
+ la2[i] = getA(tmp[1][i]);
+ lb2[i] = getB(tmp[1][i]);
+ }
+ vector<vector<ofxPoint2f> > tmp2; //All intersection points
+
+ for(int i=0; i<tmp[0].size(); i++){
+ vector<ofxPoint2f> tmp22 ;
+ tmp2.push_back(tmp22);
+ int n = tmp2.size()-1;
+ for(int u=0; u<tmp[1].size(); u++){
+ float x = (-(lb1[i]-lb2[u]))/(la1[i]-la2[u]);
+ float y = la2[u]*x+lb2[u];
+ tmp2[n].push_back(ofxPoint2f(x,y));
+ }
+ }
+ vector<oRect> rects;
+
+ for(int i=0;i<tmp2.size()-1;i++){
+ //All rows except last row - i
+ for(int u=0;u<tmp2[i].size()-1;u++){
+ //All cols except last - u
+ //Go through all the next rows a cols
+ for(int i2=i+1;i2< tmp2.size();i2++){
+ for(int u2=u+1;u2< tmp2[i].size();u2++){
+ rects.push_back(oRect(tmp2[i][u], tmp2[i][u2], tmp2[i2][u2], tmp2[i2][u]));
+ }
+ }
+
+ }
+ }
+
+ // cout<<"-------"<<endl;
+ int bestRect = -1;
+ float marginW = 8;
+ float smallestW = 0;
+ float minSize = 60;
+ for(int i=0;i<rects.size();i++){
+ // cout<<rects[i].w()<<" x "<<rects[i].h()<<endl;
+ if(fabs(rects[i].w()-rects[i].h()) < marginW){
+ if(rects[i].w() > minSize){
+ if(rects[i].w()<smallestW || bestRect == -1){
+ bestRect = i;
+ smallestW = rects[i].w();
+ }
+ }
+ }
+ }
+ // cout<<"-------"<<endl;
+
+ if(bestRect != -1){
+ for(int i=0;i<4;i++){
+ r.push_back(ofxPoint2f(rects[bestRect].p[i].x,rects[bestRect].p[i].y));
+ }
+ }
+
+ }
+
+ return r;
+}
+
+
+void PaperTracker::threadedFunction(){
+
+}
+
+void PaperTracker::draw()
+{
+ //data->srcImgGray.draw(0,0);
+ grayImageScaled.draw(0,0);
+ glPushMatrix();
+
+ ofEnableAlphaBlending();
+ ofNoFill();
+ ofSetColor(255, 255, 255);
+
+ if(doHough && linesBeingUpdate){
+ ofSetColor(255, 255, 255);
+ for(int i=0;i<lines->total;i++){
+ CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
+ ofLine(line[0].x, line[0].y, line[1].x, line[1].y);
+ ofEllipse(line[0].x, line[0].y, 5,5);
+ }
+ ofSetColor(0, 255, 0);
+ for(int i=0;i<pLines.size();i++){
+ if(i ==0)
+ glColor3d(0, 255, 0);
+ else if(i == 1)
+ glColor3d(0, 0, 255);
+ else if(i == 2)
+ glColor3d(255, 0, 255);
+ else
+ glColor3d(255, 255, 0);
+ for(int u=0;u<pLines[i].size();u++){
+ ofLine(pLines[i][u][0].x, pLines[i][u][0].y, pLines[i][u][1].x, pLines[i][u][1].y);
+ }
+ }
+ }
+ ofDisableAlphaBlending();
+ if(rectPoints.size() > 0){
+ for(int i=0;i<rectPoints.size();i++){
+ ofSetColor(255, 0, 255);
+ ofFill();
+ ofEllipse(rectPoints[i].x, rectPoints[i].y, 20, 20);
+ }
+ }
+ ofEnableAlphaBlending();
+ glColor4d(0, 255, 255, 0.2);
+ glBegin(GL_POLYGON);
+ for(int u=0;u<4;u++){
+ glVertex2f(avgRect->p[u].x, avgRect->p[u].y);
+ }
+ glEnd();
+
+ glColor4d(255, 255, 255, 0.2);
+ glBegin(GL_POLYGON);
+ for(int u=0;u<4;u++){
+ glVertex2f(capturedRect->p[u].x, capturedRect->p[u].y);
+ }
+ glEnd();
+
+
+ glTranslated(400, 0, 0);
+ ofSetColor(255, 255, 255);
+
+
+
+
+ glPopMatrix();
+
+
+
+}
+
+
+
+
+void PaperTracker::canny(ofxCvGrayscaleImage * img, int lower, int higher){
+ cvCanny(img->getCvImage(), img->getCvImage(), lower, higher);
+
+
+}
+
+
+CvSeq* PaperTracker::HoughLines(ofxCvGrayscaleImage * img,int method, double rho, double theta, int threshold, int param1, int param2){
+ CvMemStorage* storage = cvCreateMemStorage(0);
+ CvSeq* lines = 0;
+
+
+// lines = cvHoughLines2(img->getCvImage(), storage, CV_HOUGH_PROBABILISTIC, 1, 3*CV_PI/180, 35, 40, 10 );
+
+ lines = cvHoughLines2(img->getCvImage(), storage, method, rho, theta, threshold, param1, param2);
+ return lines;
+
+};
+
View
140 brandts/PaperTracker.h
@@ -0,0 +1,140 @@
+/*
+ * FaceTracker.h
+ * openFrameworks
+ *
+ * Created by mads hobye on 26/05/09.
+ * Copyright 2009 __MyCompanyName__. All rights reserved.
+ *
+ */
+#pragma once
+#include "BasePlugin.h"
+#include "Data.h"
+#include "cv.h"
+#include "ofxVectorMath.h"
+
+
+class oRect {
+public:
+ ofxPoint2f *p;
+ int avgCounter;
+ oRect(){
+ p = new ofxPoint2f[4];
+ p[0] = ofxPoint2f();
+ p[1] = ofxPoint2f();
+ p[2] = ofxPoint2f();
+ p[3] = ofxPoint2f();
+ avgCounter = 1;
+
+ }
+ oRect(ofxPoint2f p1, ofxPoint2f p2, ofxPoint2f p3, ofxPoint2f p4){
+ p = new ofxPoint2f[4];
+ p[0] = p1;
+ p[1] = p2;
+ p[2] = p3;
+ p[3] = p4;
+
+ avgCounter = 1;
+ }
+
+ float w(){
+ ofxVec2f v = ofxVec2f((p[1]-p[0]).x, (p[1]-p[0]).y);
+ ofxVec2f v2 = ofxVec2f((p[3]-p[2]).x, (p[3]-p[2]).y);
+ if(v.length()< v2.length())
+ return v.length();
+ else
+ return v2.length();
+ }
+ float h(){
+ ofxVec2f v = ofxVec2f((p[2]-p[1]).x, (p[2]-p[1]).y);
+ ofxVec2f v2 = ofxVec2f((p[0]-p[3]).x, (p[0]-p[3]).y);
+ if(v.length()< v2.length())
+ return v.length();
+ else
+ return v2.length();
+ }
+
+ float a(){
+ ofxVec2f v = ofxVec2f((p[1]-p[0]).x, (p[1]-p[0]).y);
+
+ return v.angle(ofxVec2f(1.0,0.0));
+ }
+
+ void add(oRect r){
+ avgCounter++;
+ for(int i=0;i<4;i++){
+ // if(r.p[i].x != 0 && r.p[i].y != 0){
+
+ p[i] = ofxPoint2f(p[i]*(1.0-1.0/(double)avgCounter) + r.p[i]*(1.0/(double)avgCounter));
+ // }
+ }
+ }
+};
+
+
+class PaperTracker : public BasePlugin {
+public:
+
+ virtual void init(myData * _data, QVBoxLayout * boxLayout);
+ virtual void update();
+ virtual void draw();
+ virtual void threadedFunction();
+
+
+ void canny(ofxCvGrayscaleImage * img,int lower, int higher);
+ CvSeq* HoughLines(ofxCvGrayscaleImage * img,int method, double rho, double theta, int threshold, int param1, int param2);
+ myData * data;
+
+protected:
+
+ CvSeq* lines;
+ bool anyLines;
+ vector<vector<CvPoint*> > pLines;
+ vector<ofxPoint2f> rectPoints;
+
+ bool drawMonitor;
+
+ bool doCanny;
+ int lowerCanny;
+ int higherCanny;
+
+ float speed;
+
+ bool doHough;
+ bool linesBeingUpdate;
+ int houghMethod;
+ double houghRho;
+ double houghTheta;
+ int houghthreshold;
+ double houghParam1;
+ double houghParam2;
+
+ bool doRectTracking;
+ float parAMargin;
+ float parMinDist;
+ float parMaxDist;
+
+ float rectAMargin;
+ oRect * avgRect;
+ oRect * capturedRect;
+ float captureCounter;
+ vector<vector<CvPoint*> > findParalLines();
+ vector<ofxPoint2f> findRect(vector<vector<CvPoint*> >);
+
+ float getA(CvPoint* line);
+ float getB(CvPoint* line);
+
+ float dist(int x1, int y1, int x2, int y2);
+ ofxCvGrayscaleImage grayImage;
+ ofxCvGrayscaleImage grayImageScaled;
+ ofxCvGrayscaleImage grayImageScaled2;
+ QSlider * sliderHughParam1;
+ QSlider * sliderHughParam2;
+ QSlider * sliderHoughthreshold;
+ QSlider * sliderHoughRho;
+ QSlider * sliderHoughTheta;
+ QSlider * sliderLowerCanny;
+ QSlider * sliderHigherCanny;
+
+
+
+};
View
112 brandts/SoundInput.cpp
@@ -0,0 +1,112 @@
+/*
+ * SoundInput.cpp
+ * openframeworksQT
+ *
+ * Created by mads hobye on 09/08/09.
+ * Copyright 2009 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "SoundInput.h"
+
+
+
+
+void SoundInput::init(myData * _data, QVBoxLayout * boxLayout)
+{
+
+ addBaseGui(boxLayout);
+ data = _data;
+ nameid = "SoundInput";
+
+
+
+
+ bufferCounter = 0;
+ drawCounter = 0;
+ smoothVolume = 0;
+ fastVolume = 0;
+ beat = false;
+ QGroupBox * sliderArea = new QGroupBox("