No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

camera.cpp 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (C) 2018 dimercur
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "camera.h"
  18. #include "img.h"
  19. using namespace cv;
  20. void Camera::setSize(int size) {
  21. this->size = size;
  22. switch (size){
  23. case xs:
  24. this->width = 480;
  25. this->height = 360;
  26. break;
  27. case sm:
  28. this->width = 640;
  29. this->height = 480;
  30. break;
  31. case md:
  32. this->width = 1024;
  33. this->height = 768;
  34. break;
  35. case lg:
  36. this->width = 1280;
  37. this->height = 960;
  38. break;
  39. default:
  40. this->width = 480;
  41. this->height = 360;
  42. }
  43. }
  44. int Camera::open_camera() {
  45. this->cap.open(0);
  46. }
  47. Camera::Camera(int size) {
  48. this->setSize(size);
  49. this->cap.set(CV_CAP_PROP_FORMAT, CV_8UC3);
  50. this->cap.set(CV_CAP_PROP_FRAME_WIDTH,width);
  51. this->cap.set(CV_CAP_PROP_FRAME_HEIGHT,height);
  52. }
  53. int Camera::close_camera() {
  54. cap.release();
  55. return 0;
  56. }
  57. Img Camera::grab_image() {
  58. ImageMat frame;
  59. cap >> frame;
  60. Img capture = Img(frame);
  61. return capture;
  62. }
  63. bool Camera::isOpen() {
  64. return cap.isOpened();
  65. }
  66. int Camera::getWidth() const {
  67. return width;
  68. }
  69. int Camera::getHeight() const {
  70. return height;
  71. }