refactor cam::Camera::Description
This commit is contained in:
9
main.cpp
9
main.cpp
@ -40,7 +40,7 @@ void listDevices()
|
|||||||
std::vector<Camera::Description> cameras = Camera::getAvailableCameras();
|
std::vector<Camera::Description> cameras = Camera::getAvailableCameras();
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for(auto camera : cameras)
|
for(auto camera : cameras)
|
||||||
std::cout<<i++<<": "<<camera.id<<' '<<camera.model<<' '<<camera.vendor<<'\n';
|
std::cout<<i++<<": "<<camera.getId()<<' '<<camera.getModel()<<' '<<camera.getVendor()<<'\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void help()
|
void help()
|
||||||
@ -143,7 +143,12 @@ int main(int argc, char* argv[])
|
|||||||
std::cout<<"setting exposure time failed\n";
|
std::cout<<"setting exposure time failed\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cout<<"Exposure time: "<<camera.getExposureTime()/1000000.0<<'\n';
|
{
|
||||||
|
uint64_t min, max;
|
||||||
|
camera.getExposureTimeLimits(min, max);
|
||||||
|
std::cout<<"Exposure time: "<<camera.getExposureTime()/1000000.0<<'\n'
|
||||||
|
<<" Limits: "<<min/1000000.0<<" to "<<max/1000000.0<<'\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
59
uvoscam.cpp
59
uvoscam.cpp
@ -289,6 +289,7 @@ bool Camera::setupCamera()
|
|||||||
setFrameRate(10);
|
setFrameRate(10);
|
||||||
setExposureTime(100000);
|
setExposureTime(100000);
|
||||||
setGain(1);
|
setGain(1);
|
||||||
|
setMtu(1500);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -304,22 +305,16 @@ std::vector<Camera::Description> Camera::getAvailableCameras(bool update)
|
|||||||
std::vector<Description> cameras;
|
std::vector<Description> cameras;
|
||||||
for(size_t i = 0; i < arv_get_n_devices(); ++i)
|
for(size_t i = 0; i < arv_get_n_devices(); ++i)
|
||||||
{
|
{
|
||||||
Description camera;
|
|
||||||
const char* vendor = arv_get_device_vendor(i);
|
const char* vendor = arv_get_device_vendor(i);
|
||||||
const char* serial = arv_get_device_serial_nbr(i);
|
const char* serial = arv_get_device_serial_nbr(i);
|
||||||
const char* id = arv_get_device_id(i);
|
|
||||||
const char* model = arv_get_device_model(i);
|
const char* model = arv_get_device_model(i);
|
||||||
|
const char* id = arv_get_device_id(i);
|
||||||
|
|
||||||
if(vendor)
|
if(!vendor || !serial || !id || !model)
|
||||||
camera.vendor = vendor;
|
continue;
|
||||||
if(serial)
|
|
||||||
camera.serial = serial;
|
|
||||||
if(id)
|
|
||||||
camera.id = id;
|
|
||||||
if(model)
|
|
||||||
camera.model = model;
|
|
||||||
|
|
||||||
cameras.push_back(camera);
|
cameras.push_back(Description(vendor, model, serial, id));
|
||||||
}
|
}
|
||||||
return cameras;
|
return cameras;
|
||||||
}
|
}
|
||||||
@ -341,7 +336,8 @@ bool Camera::openCamera(const std::string& name)
|
|||||||
|
|
||||||
bool Camera::openCamera(const Camera::Description& camera)
|
bool Camera::openCamera(const Camera::Description& camera)
|
||||||
{
|
{
|
||||||
aCamera_ = arv_camera_new(camera.id.c_str(), nullptr);
|
description = new Description(camera);
|
||||||
|
aCamera_ = arv_camera_new(camera.getIdString().c_str(), nullptr);
|
||||||
if(ARV_IS_CAMERA(aCamera_))
|
if(ARV_IS_CAMERA(aCamera_))
|
||||||
setupCamera();
|
setupCamera();
|
||||||
else
|
else
|
||||||
@ -352,11 +348,12 @@ bool Camera::openCamera(const Camera::Description& camera)
|
|||||||
bool Camera::openCamera(const size_t index)
|
bool Camera::openCamera(const size_t index)
|
||||||
{
|
{
|
||||||
Description camera = getAvailableCameras().at(index);
|
Description camera = getAvailableCameras().at(index);
|
||||||
aCamera_ = arv_camera_new(camera.id.c_str(), nullptr);
|
description = new Description(camera);
|
||||||
|
aCamera_ = arv_camera_new(camera.getIdString().c_str(), nullptr);
|
||||||
if(ARV_IS_CAMERA(aCamera_))
|
if(ARV_IS_CAMERA(aCamera_))
|
||||||
setupCamera();
|
setupCamera();
|
||||||
else
|
else
|
||||||
Log(Log::ERROR)<<"Can not create camera from index "<<index<<" name "<<camera.model;
|
Log(Log::ERROR)<<"Can not create camera from index "<<index<<" name "<<camera.getModel();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,7 +456,7 @@ bool Camera::getExposureTimeLimits(uint64_t& min, uint64_t& max)
|
|||||||
{
|
{
|
||||||
double minD = 0;
|
double minD = 0;
|
||||||
double maxD = 0;
|
double maxD = 0;
|
||||||
GError* error;
|
GError* error = nullptr;
|
||||||
arv_camera_get_exposure_time_bounds(aCamera_, &minD, &maxD, &error);
|
arv_camera_get_exposure_time_bounds(aCamera_, &minD, &maxD, &error);
|
||||||
if(error)
|
if(error)
|
||||||
Log(Log::WARN)<<error->message;
|
Log(Log::WARN)<<error->message;
|
||||||
@ -553,29 +550,37 @@ void Camera::trigger()
|
|||||||
arv_camera_software_trigger(aCamera_, nullptr);
|
arv_camera_software_trigger(aCamera_, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Camera::setMtu(int mtu) {
|
||||||
|
GError* error = nullptr;
|
||||||
|
arv_device_set_integer_feature_value(arv_camera_get_device(aCamera_), "GevSCPSPacketSize", mtu, &error);
|
||||||
|
if(!error)
|
||||||
|
arv_device_set_integer_feature_value(arv_camera_get_device(aCamera_), "GevSCBWR", 10, &error);
|
||||||
|
if(error)
|
||||||
|
Log(Log::WARN)<<error->message;
|
||||||
|
return !error;
|
||||||
|
}
|
||||||
|
|
||||||
Camera::Description Camera::getDescription()
|
Camera::Description Camera::getDescription()
|
||||||
{
|
{
|
||||||
if(!description)
|
if(!description)
|
||||||
{
|
{
|
||||||
if(ARV_IS_CAMERA(aCamera_))
|
if(ARV_IS_CAMERA(aCamera_))
|
||||||
{
|
{
|
||||||
description = new Description;
|
std::string vendor;
|
||||||
|
std::string serial;
|
||||||
|
std::string model;
|
||||||
|
|
||||||
GError* error = nullptr;
|
GError* error = nullptr;
|
||||||
|
vendor = arv_camera_get_vendor_name(aCamera_, &error);
|
||||||
if(!error)
|
if(!error)
|
||||||
description->vendor = arv_camera_get_vendor_name(aCamera_, &error);
|
serial = arv_camera_get_device_serial_number(aCamera_, &error);
|
||||||
if(!error)
|
if(!error)
|
||||||
description->serial = arv_camera_get_device_serial_number(aCamera_, &error);
|
model = arv_camera_get_model_name(aCamera_, &error);
|
||||||
if(!error)
|
|
||||||
description->id = arv_camera_get_device_id(aCamera_, &error);
|
|
||||||
if(!error)
|
|
||||||
description->model = arv_camera_get_model_name(aCamera_, &error);
|
|
||||||
if(error)
|
if(error)
|
||||||
{
|
|
||||||
Log(Log::WARN)<<error->message;
|
Log(Log::WARN)<<error->message;
|
||||||
delete description;
|
else
|
||||||
description = nullptr;
|
description = new Description(vendor, model, serial);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return description ? *description : Description();
|
return description ? *description : Description("VOID", "VOID", "VOID");
|
||||||
}
|
}
|
||||||
|
43
uvoscam.h
43
uvoscam.h
@ -41,22 +41,46 @@ public:
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
size_t hash = 0;
|
size_t hash = 0;
|
||||||
|
std::string vendor_;
|
||||||
|
std::string serial_;
|
||||||
|
std::string model_;
|
||||||
|
std::string id_;
|
||||||
public:
|
public:
|
||||||
std::string vendor;
|
|
||||||
std::string serial;
|
|
||||||
std::string id;
|
|
||||||
std::string model;
|
|
||||||
|
|
||||||
size_t getHash() const
|
Description(std::string const vendor, const std::string model, const std::string serial, const std::string id = ""):
|
||||||
|
vendor_(vendor), serial_(serial), model_(model), id_(id)
|
||||||
{
|
{
|
||||||
//if(hash == 0)
|
hash = std::hash<std::string>{}(vendor_ + serial_ + model_);
|
||||||
return /*hash =*/ std::hash<std::string>{}(vendor + serial + id + model);
|
}
|
||||||
//return hash;
|
|
||||||
|
size_t getId() const
|
||||||
|
{
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getIdString() const
|
||||||
|
{
|
||||||
|
return id_;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getVendor() const
|
||||||
|
{
|
||||||
|
return vendor_;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getSerial() const
|
||||||
|
{
|
||||||
|
return serial_;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getModel() const
|
||||||
|
{
|
||||||
|
return model_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const Description& in) const
|
bool operator==(const Description& in) const
|
||||||
{
|
{
|
||||||
return in.getHash() == getHash();
|
return in.getId() == getId();
|
||||||
}
|
}
|
||||||
bool operator!=(const Description& in) const
|
bool operator!=(const Description& in) const
|
||||||
{
|
{
|
||||||
@ -147,6 +171,7 @@ public:
|
|||||||
bool hasExposureAuto();
|
bool hasExposureAuto();
|
||||||
bool startAcquisition();
|
bool startAcquisition();
|
||||||
bool stopAcquisition();
|
bool stopAcquisition();
|
||||||
|
bool setMtu(int mtu);
|
||||||
void getSize(unsigned int* x, unsigned int* y);
|
void getSize(unsigned int* x, unsigned int* y);
|
||||||
void setBayerMode(Camera::BayerMode mode);
|
void setBayerMode(Camera::BayerMode mode);
|
||||||
Camera::BayerMode getBayerMode();
|
Camera::BayerMode getBayerMode();
|
||||||
|
Reference in New Issue
Block a user