main.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "../../DFPSR/includeFramework.h"
  2. #include <raspicam/raspicam.h>
  3. using namespace dsr;
  4. // Global
  5. const String mediaPath = string_combine(U"media", file_separator());
  6. bool running = true;
  7. // The window handle
  8. Window window;
  9. int main(int argn, char **argv) {
  10. // Create a window
  11. int cameraWidth = 320 * 2;
  12. int cameraHeight = 240 * 2;
  13. window = window_create(U"Raspberry Pi camera application", cameraWidth, cameraHeight);
  14. // Load an interface to the window
  15. //window_loadInterfaceFromFile(window, mediaPath + U"?.lof");
  16. // Bind methods to events
  17. window_setCloseEvent(window, []() {
  18. running = false;
  19. });
  20. // Start the camera
  21. raspicam::RaspiCam piCamera;
  22. piCamera.setWidth(cameraWidth); piCamera.setHeight(cameraHeight);
  23. piCamera.setFormat(raspicam::RASPICAM_FORMAT_GRAY);
  24. if (!piCamera.open()) {
  25. throwErrorMessage("Couldn't find any Raspberry Pi camera!\n");
  26. return -1;
  27. }
  28. time_sleepSeconds(0.1);
  29. // Create an image for the camera input
  30. AlignedImageU8 cameraImage = image_create_U8(piCamera.getWidth(), piCamera.getHeight());
  31. // Execute
  32. while(running) {
  33. window_executeEvents(window);
  34. //window_drawComponents(window);
  35. // Set shutter time in microseconds
  36. piCamera.setShutterSpeed(10000); // 10000 fast, 20000 normal
  37. piCamera.setISO(800); // 100 darkest, 800 brightest
  38. // Get an image from the camera
  39. piCamera.grab();
  40. // Uncomment for a 10 ms cooldown time after each frame
  41. //time_sleepSeconds(0.1);
  42. piCamera.retrieve(image_dangerous_getData(cameraImage));
  43. // Display the image
  44. auto canvas = window_getCanvas(window);
  45. draw_copy(canvas, cameraImage);
  46. // Show the final state of the canvas without flickering
  47. window_showCanvas(window);
  48. }
  49. }