// %flair:license{ // This file is part of the Flair framework distributed under the // CECILL-C License, Version 1.0. // %flair:license} // created: 2014/07/17 // filename: V4LCamera.cpp // // author: Guillaume Sanahuja // Copyright Heudiasyc UMR UTC/CNRS 7253 // // version: $Id: $ // // purpose: base class for V4l camera // // /*********************************************************************/ #include "V4LCamera.h" #include "V4LCamera_impl.h" #include #include using std::string; using namespace flair::core; namespace flair { namespace sensor { V4LCamera::V4LCamera(string name,uint8_t camera_index, uint16_t width, uint16_t height, Image::Type::Format format, uint8_t priority) : Thread(getFrameworkManager(), name, priority), Camera(name, width, height, format) { pimpl_=new V4LCamera_impl(this,name,camera_index,width,height,format); } V4LCamera::~V4LCamera() { SafeStop(); Join(); delete pimpl_; } void V4LCamera::Run(void) { pimpl_->Run(); /* Time cam_time, new_time, fpsNow, fpsPrev; int fpsCounter = 0; cam_time = GetTime(); fpsPrev = cam_time; while (!ToBeStopped()) { // fps counter fpsCounter++; if (fpsCounter == 100) { fpsNow = GetTime(); fps->SetText("fps: %.1f", fpsCounter / ((float)(fpsNow - fpsPrev) / 1000000000.)); fpsCounter = 0; fpsPrev = fpsNow; } // cam properties if (gain->ValueChanged() == true && autogain->Value() == false) SetGain(gain->Value()); if (exposure->ValueChanged() == true && autoexposure->Value() == false) SetExposure(exposure->Value()); if (bright->ValueChanged() == true) SetBrightness(bright->Value()); if (sat->ValueChanged() == true) SetSaturation(sat->Value()); if (contrast->ValueChanged() == true) SetContrast(contrast->Value()); if (hue->ValueChanged() == true) SetHue(hue->Value()); //if (sharpness->ValueChanged() == true) // cvSetCaptureProperty(capture, CV_CAP_PROP_SHARPNESS, sharpness->Value()); if (autogain->ValueChanged() == true) { if (autogain->Value() == true) { gain->setEnabled(false); } else { gain->setEnabled(true); SetGain(gain->Value()); } SetAutoGain(autogain->Value()); } if (autoexposure->ValueChanged() == true) { if (autoexposure->Value() == true) { exposure->setEnabled(false); } else { exposure->setEnabled(true); SetExposure(exposure->Value()); } SetAutoExposure(autoexposure->Value()); } //if (awb->ValueChanged() == true) // cvSetCaptureProperty(capture, CV_CAP_PROP_AWB, awb->Value()); // cam pictures if (!GrabFrame()) { Printf("Could not grab a frame\n"); } //check for ps3eye deconnection in hds uav new_time = GetTime(); if(new_time-cam_time>100*1000*1000) { Thread::Warn("delta t trop grand\n"); hasProblems=true; } //select buffer if(useMemoryUsrPtr) {//buffers are already in CMEM imageData=(char*)buffers[dQueuedBuffer.index]; //dequeue it latter (buffer used by ProcessUpdate) } else {//copy to CMEM allocated buffer memcpy(imageData,(char *)buffers[dQueuedBuffer.index],output->GetDataType().GetSize()); QueueBuffer(&dQueuedBuffer);//we can do it right now } output->GetMutex(); output->buffer=imageData; output->ReleaseMutex(); output->SetDataTime(cam_time); ProcessUpdate(output); cam_time = new_time; if(useMemoryUsrPtr) { QueueBuffer(&dQueuedBuffer);//now it is possible to dequeue } } */ } bool V4LCamera::HasProblems(void) { return pimpl_->hasProblems; } void V4LCamera::SetAutoGain(bool value) { pimpl_->SetAutoGain(value); } void V4LCamera::SetAutoExposure(bool value) { Thread::Warn("not implemented\n"); } void V4LCamera::SetGain(float value) { pimpl_->SetGain(value); } void V4LCamera::SetExposure(float value) { pimpl_->SetExposure(value); } void V4LCamera::SetBrightness(float value) { pimpl_->SetBrightness(value); } void V4LCamera::SetSaturation(float value) { pimpl_->SetSaturation(value); } void V4LCamera::SetHue(float value) { pimpl_->SetHue(value); } void V4LCamera::SetContrast(float value) { pimpl_->SetContrast(value); } } // end namespace sensor } // end namespace flair