Guest User

Untitled

a guest
Sep 21st, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. //ofMain.cpp
  2.  
  3. #include "ofMain.h"
  4. #include "testApp.h"
  5. #include "ofAppGlutWindow.h"
  6.  
  7. //========================================================================
  8. int main( ){
  9.  
  10. ofAppGlutWindow window;
  11. ofSetupOpenGL(&window, 1680 ,680, OF_WINDOW); // <-------- setup the GL context
  12.  
  13. // this kicks off the running of my app
  14. // can be OF_WINDOW or OF_FULLSCREEN
  15. // pass in width and height too:
  16. ofRunApp( new testApp());
  17.  
  18. }
  19.  
  20. //testApp.h
  21.  
  22. #pragma once
  23.  
  24. #include "ofMain.h"
  25.  
  26. #define VIDWIDTH 640 // Video width
  27. #define VIDHEIGHT 480 // Video Height
  28.  
  29.  
  30. class testApp : public ofBaseApp{
  31.  
  32. public:
  33. void setup();
  34. void update();
  35. void draw();
  36.  
  37. ofVideoGrabber vidGrabber; // Video Grabber Object
  38. ofVbo ptsVbo; // VBO that stores points
  39.  
  40. int numPixels; // Number of pixels in image
  41.  
  42. ofVec3f pts[307200]; // This sucks
  43. ofFloatColor col[307200]; // This sucks
  44.  
  45. };
  46.  
  47. //testApp.cpp
  48.  
  49. #include "testApp.h"
  50.  
  51. //--------------------------------------------------------------
  52. void testApp::setup(){
  53.  
  54. ofSetLogLevel(OF_LOG_NOTICE);
  55. //ofLogToFile("log.txt", true);
  56.  
  57. vidGrabber.listDevices();
  58. vidGrabber.initGrabber(VIDWIDTH, VIDHEIGHT); // Setup vidGrabber
  59. numPixels = VIDWIDTH * VIDHEIGHT;
  60. }
  61.  
  62. //--------------------------------------------------------------
  63. void testApp::update(){
  64.  
  65. ofBackground(0, 0, 0);
  66.  
  67. vidGrabber.grabFrame(); // Grab a frame
  68.  
  69. if (vidGrabber.isFrameNew()){ // Check if frame is actually new
  70.  
  71. unsigned char * pixels = vidGrabber.getPixels();
  72.  
  73. // Cycle through pixels
  74. for (int y = 0; y < VIDHEIGHT; y++) {
  75. for (int x = 0; x < VIDWIDTH; x++) {
  76.  
  77. int red = pixels[((y * VIDWIDTH) + x) * 3]; // Get the red data
  78. int green = pixels[((y * VIDWIDTH) + x) * 3 + 1]; // Get the green data
  79. int blue = pixels[((y * VIDWIDTH) + x) * 3 + 2]; // Get the blue data
  80. int brightness = (red+green+blue)/3; // Calculate brightness
  81.  
  82. int px = x;
  83. int py = y;
  84. int pz = brightness;
  85.  
  86. pts[x*y].set(px,py,pz); // Add values to pts array
  87. col[x*y].set(red,green,blue); // Add colour values to col array
  88.  
  89. }
  90. }
  91.  
  92. ptsVbo.setVertexData(pts, numPixels , GL_DYNAMIC_DRAW); // Add points to VBO
  93. ptsVbo.setColorData(col, numPixels, GL_DYNAMIC_DRAW); // Add colours to VBO
  94. }
  95. }
  96.  
  97. //--------------------------------------------------------------
  98. void testApp::draw(){
  99.  
  100. ofTranslate(200, 100); // Move a little bit
  101. ptsVbo.draw(GL_POINTS, 0, numPixels); // Draw VBO
  102. vidGrabber.draw(640+100, 0); // Draw the camera input
  103.  
  104. }
Add Comment
Please, Sign In to add comment