Skip to content

Instantly share code, notes, and snippets.

@tomas789
Created July 6, 2017 10:25
Show Gist options
  • Save tomas789/0b64339a0f9a8657c945d40fb2b3de82 to your computer and use it in GitHub Desktop.
Save tomas789/0b64339a0f9a8657c945d40fb2b3de82 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include "PtGrayCamera.hpp"
int main(int argc, const char * argv[]) {
auto available_cameras = PtGrayCamera::list_cameras();
if (available_cameras.empty()) {
std::cerr << "No camera found." << std::endl;
return 1;
}
std::cout << "Found " << available_cameras.size() << " camera(s)." << std::endl;
PtGrayCamera camera = PtGrayCamera::create(available_cameras[0]);
auto supported_modes = camera.get_supported_video_modes();
std::cout << " ... with " << supported_modes.size() << " supported modes." << std::endl;
camera.capture_setup();
camera.set_transmission(true);
cv::namedWindow("PtGrey");
while (cv::waitKey(1) != 27) {
cv::Mat mat = camera.capture_one();
cv::imshow("PtGrey", mat);
}
camera.set_transmission(false);
camera.capture_stop();
return 0;
}
//
// PtGrayCamera.hpp
// PtGrey
//
#ifndef PtGrayCamera_hpp
#define PtGrayCamera_hpp
#include <dc1394/dc1394.h>
#include <stdexcept>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <vector>
/**
* Read feed from PtGrey camera.
*
* A lot of features are not supported by this implementation yet. If you want to add more of them,
* just get in touch with Tom.
*
* To run this, you need OpenCV and libdc1394 (brew install libdc1394).
* You may also want to try pydc1394.
*
* Possible features:
* - Capture only ROI
* - Change framerate
* - Change resolution
* - Produce gray images only
* - Get temperature of camera (useful for calibration)
* - Set/get/lock exposure
* - ... a lot more
*/
class PtGrayCamera {
public:
PtGrayCamera(PtGrayCamera&& other);
PtGrayCamera& operator=(const PtGrayCamera& other) = delete;
PtGrayCamera& operator=(PtGrayCamera&& other);
static std::vector<dc1394camera_id_t> list_cameras();
static PtGrayCamera create(dc1394camera_id_t camera_id);
void set_transmission(bool transmission);
void capture_setup();
void capture_stop();
cv::Mat capture_one(bool blocking = true);
std::vector<dc1394video_mode_t> get_supported_video_modes();
~PtGrayCamera();
private:
dc1394_t *d;
dc1394camera_t *camera;
uint32_t selected_mode;
PtGrayCamera(dc1394_t *d, dc1394camera_t *camera, uint32_t selected_mode);
cv::Mat process_raw(cv::Mat mat_raw, dc1394color_filter_t color_filter);
};
#endif /* PtGrayCamera_hpp */
//
// PtGrayCamera.hpp
// PtGrey
//
#ifndef PtGrayCamera_hpp
#define PtGrayCamera_hpp
#include <dc1394/dc1394.h>
#include <stdexcept>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <vector>
/**
* Read feed from PtGrey camera.
*
* A lot of features are not supported by this implementation yet. If you want to add more of them,
* just get in touch with tomas789@gmail.com.
*
* To run this, you need OpenCV and libdc1394 (brew install libdc1394).
* You may also want to try pydc1394.
*
* Possible features:
* - Capture only ROI
* - Change framerate
* - Change resolution
* - Produce gray images only
* - Get temperature of camera (useful for calibration)
* - Set/get/lock exposure
* - ... a lot more
*/
class PtGrayCamera {
public:
PtGrayCamera(PtGrayCamera&& other);
PtGrayCamera& operator=(const PtGrayCamera& other) = delete;
PtGrayCamera& operator=(PtGrayCamera&& other);
static std::vector<dc1394camera_id_t> list_cameras();
static PtGrayCamera create(dc1394camera_id_t camera_id);
void set_transmission(bool transmission);
void capture_setup();
void capture_stop();
cv::Mat capture_one(bool blocking = true);
std::vector<dc1394video_mode_t> get_supported_video_modes();
~PtGrayCamera();
private:
dc1394_t *d;
dc1394camera_t *camera;
uint32_t selected_mode;
PtGrayCamera(dc1394_t *d, dc1394camera_t *camera, uint32_t selected_mode);
cv::Mat process_raw(cv::Mat mat_raw, dc1394color_filter_t color_filter);
};
#endif /* PtGrayCamera_hpp */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment