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();
|
||||
size_t i = 0;
|
||||
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()
|
||||
@ -143,7 +143,12 @@ int main(int argc, char* argv[])
|
||||
std::cout<<"setting exposure time failed\n";
|
||||
}
|
||||
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
|
||||
{
|
||||
|
59
uvoscam.cpp
59
uvoscam.cpp
@ -289,6 +289,7 @@ bool Camera::setupCamera()
|
||||
setFrameRate(10);
|
||||
setExposureTime(100000);
|
||||
setGain(1);
|
||||
setMtu(1500);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -304,22 +305,16 @@ std::vector<Camera::Description> Camera::getAvailableCameras(bool update)
|
||||
std::vector<Description> cameras;
|
||||
for(size_t i = 0; i < arv_get_n_devices(); ++i)
|
||||
{
|
||||
Description camera;
|
||||
|
||||
const char* vendor = arv_get_device_vendor(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* id = arv_get_device_id(i);
|
||||
|
||||
if(vendor)
|
||||
camera.vendor = vendor;
|
||||
if(serial)
|
||||
camera.serial = serial;
|
||||
if(id)
|
||||
camera.id = id;
|
||||
if(model)
|
||||
camera.model = model;
|
||||
if(!vendor || !serial || !id || !model)
|
||||
continue;
|
||||
|
||||
cameras.push_back(camera);
|
||||
cameras.push_back(Description(vendor, model, serial, id));
|
||||
}
|
||||
return cameras;
|
||||
}
|
||||
@ -341,7 +336,8 @@ bool Camera::openCamera(const std::string& name)
|
||||
|
||||
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_))
|
||||
setupCamera();
|
||||
else
|
||||
@ -352,11 +348,12 @@ bool Camera::openCamera(const Camera::Description& camera)
|
||||
bool Camera::openCamera(const size_t 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_))
|
||||
setupCamera();
|
||||
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;
|
||||
}
|
||||
|
||||
@ -459,7 +456,7 @@ bool Camera::getExposureTimeLimits(uint64_t& min, uint64_t& max)
|
||||
{
|
||||
double minD = 0;
|
||||
double maxD = 0;
|
||||
GError* error;
|
||||
GError* error = nullptr;
|
||||
arv_camera_get_exposure_time_bounds(aCamera_, &minD, &maxD, &error);
|
||||
if(error)
|
||||
Log(Log::WARN)<<error->message;
|
||||
@ -553,29 +550,37 @@ void Camera::trigger()
|
||||
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()
|
||||
{
|
||||
if(!description)
|
||||
{
|
||||
if(ARV_IS_CAMERA(aCamera_))
|
||||
{
|
||||
description = new Description;
|
||||
std::string vendor;
|
||||
std::string serial;
|
||||
std::string model;
|
||||
|
||||
GError* error = nullptr;
|
||||
vendor = arv_camera_get_vendor_name(aCamera_, &error);
|
||||
if(!error)
|
||||
description->vendor = arv_camera_get_vendor_name(aCamera_, &error);
|
||||
serial = arv_camera_get_device_serial_number(aCamera_, &error);
|
||||
if(!error)
|
||||
description->serial = arv_camera_get_device_serial_number(aCamera_, &error);
|
||||
if(!error)
|
||||
description->id = arv_camera_get_device_id(aCamera_, &error);
|
||||
if(!error)
|
||||
description->model = arv_camera_get_model_name(aCamera_, &error);
|
||||
model = arv_camera_get_model_name(aCamera_, &error);
|
||||
if(error)
|
||||
{
|
||||
Log(Log::WARN)<<error->message;
|
||||
delete description;
|
||||
description = nullptr;
|
||||
}
|
||||
else
|
||||
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:
|
||||
size_t hash = 0;
|
||||
std::string vendor_;
|
||||
std::string serial_;
|
||||
std::string model_;
|
||||
std::string id_;
|
||||
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)
|
||||
return /*hash =*/ std::hash<std::string>{}(vendor + serial + id + model);
|
||||
//return hash;
|
||||
hash = std::hash<std::string>{}(vendor_ + serial_ + model_);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
return in.getHash() == getHash();
|
||||
return in.getId() == getId();
|
||||
}
|
||||
bool operator!=(const Description& in) const
|
||||
{
|
||||
@ -147,6 +171,7 @@ public:
|
||||
bool hasExposureAuto();
|
||||
bool startAcquisition();
|
||||
bool stopAcquisition();
|
||||
bool setMtu(int mtu);
|
||||
void getSize(unsigned int* x, unsigned int* y);
|
||||
void setBayerMode(Camera::BayerMode mode);
|
||||
Camera::BayerMode getBayerMode();
|
||||
|
Reference in New Issue
Block a user