int MUCamSource::OnDevice( MM::PropertyBase* pProp, MM::ActionType eAct ) { #ifdef _LOG_OUT_ OutputDebugString("OnDevice"); #endif if (eAct == MM::AfterSet) { string strName; pProp->Get(strName); vector<string>::const_iterator begin = DevicesVec_.begin(); vector<string>::const_iterator end = DevicesVec_.end(); vector<string>::const_iterator it = find(begin, end, strName); vector<string>::difference_type idx = distance(begin, it); if (it != end && idx != currentCam_) { StopSequenceAcquisition(); if (!OpenCamera(hCameras_[idx])) return DEVICE_ERR; currentCam_ = idx;// MIDP_GetCurCameraIndex(); InitDevice(); } } else if (eAct == MM::BeforeGet) { if(currentCam_ >= 0 && currentCam_ < cameraCnt_) { string strName = DevicesVec_[currentCam_]; pProp->Set(strName.c_str()); } } return DEVICE_OK; }
/** * Intializes the hardware. * Typically we access and initialize hardware at this point. * Device properties are typically created here as well. * Required by the MM::Device API. */ int MUCamSource::Initialize() { if (!LoadFunctions()) return DEVICE_ERR; if (initialized_) return DEVICE_OK; // set property list // ----------------- FindMoticCameras(); if(cameraCnt_ == 0) { return ERR_NO_CAMERAS_FOUND; } currentCam_ = 0;//MIDP_GetCurCameraIndex(); int ret; CPropertyAction* pAct; if (!OpenCamera(hCameras_[currentCam_])) return DEVICE_ERR; char sName[Camera_Name_Len]; GetMotiCamNAME(hCameras_[currentCam_], sName); //memcpy(sName, GetMotiCamNAME(hCameras_[currentCam_]), Camera_Name_Len); pAct = new CPropertyAction(this, &MUCamSource::OnDevice); ret = CreateProperty(g_Keyword_Cameras, sName, MM::String, true, pAct); ret = SetAllowedValues(g_Keyword_Cameras, DevicesVec_); assert(ret == DEVICE_OK); ret = InitDevice(); if(ret == DEVICE_OK) { initialized_ = true; } return ret; }
void openCamera(CAMediaDelegate* target) { delegate = target; // if (allowEdit) { // OpenCamera(0); // } // else { OpenCamera(1); } }
int main() { int ret = 0; void * mV4l2_ctx = NULL; int mCaptureFormat; int width = 1280; int height = 720; int number = 0; struct v4l2_buffer buf; memset(&buf, 0, sizeof(buf)); mV4l2_ctx = CreateV4l2Context(); setV4L2DeviceName(mV4l2_ctx, "/dev/video1"); // open v4l2 camera device ret = OpenCamera(mV4l2_ctx); if (ret != 0) { LOGE("openCameraDevice failed\n"); return ret; } StartCamera(mV4l2_ctx, &width, &height); while(number < 300) { CameraGetOneframe(mV4l2_ctx,&buf); CameraReturnOneframe(mV4l2_ctx,buf.index); LOGD("test, number: %d",number); number ++; } StopCamera(mV4l2_ctx); CloseCamera(mV4l2_ctx); DestroyV4l2Context(mV4l2_ctx); mV4l2_ctx = NULL; return 0; }
void CDlgPresetSetting::OnNMDblclkTreeLinkageList(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: 在此添加控件通知处理程序代码 *pResult = 0; HTREEITEM hItem = m_treeLinkageList.GetSelectedItem(); if (hItem == NULL) { return ; } NodeInfo* pNodeInfo = (NodeInfo*)m_treeLinkageList.GetItemData(hItem); if (pNodeInfo == NULL) { return ; } GetDlgItem(IDC_EDIT_CURRENT_DEVICE)->SetWindowText(""); if (pNodeInfo->node_type == RVU_DEVICE_NODE) { GetDlgItem(IDC_EDIT_CURRENT_DEVICE)->SetWindowText(pNodeInfo->node_name); SetPresetEditText(); ////加载这个设备绑定的摄像头 if (GetCameraInfoByDevId(hItem, pNodeInfo->node_id)) return; } if (pNodeInfo->node_type == PRESET_NODE) { sprintf_s(m_szCameraCode,64,pNodeInfo->node_code); //打开摄像头 if (OpenCamera(m_szCameraCode,pNodeInfo->parent_id)==-1) { MessageBox("打开摄像头失败!","辅助系统"); return; } m_nCameraPresetId = pNodeInfo->node_id; ToPreset(m_nCameraPresetId); } }
void PD_flow_mrpt::initializePDFlow() { //Initialize Visualization initializeScene(); //Initialize CUDA mrpt::system::sleep(500); initializeCUDA(); //Start video streaming OpenCamera(); //Fill empty matrices CaptureFrame(); createImagePyramidGPU(); CaptureFrame(); createImagePyramidGPU(); solveSceneFlowGPU(); }
void GCamera::LatterInitialization() { m_IsOpened = OpenCamera(); if(!m_IsOpened) return; if(ImageProcessor()) { disconnect(ImageProcessor(), SIGNAL(OutputImageDouble(GImageDouble)), this, SLOT(NotifyImageSent())); disconnect(ImageProcessor(), SIGNAL(ProcessorFailed()), this, SLOT(NotifyImageFailed())); connect(ImageProcessor(), SIGNAL(OutputImageDouble(GImageDouble)), this, SLOT(NotifyImageSent()), Qt::QueuedConnection); connect(ImageProcessor(), SIGNAL(ProcessorFailed()), this, SLOT(NotifyImageFailed()), Qt::QueuedConnection); } ChangeExposureTime(m_Expo_ms); ChangeGainFactor(m_Gain); emit CapabilitiesMayHaveChanged(); GDevice::LatterInitialization(); }
static int startcamera(AWCameraDevice *p) { AWCameraDevice* camera_dev = (AWCameraDevice *)(p); AWCameraContext* CameraCtx = NULL; int err = 0; if(!camera_dev) return -1; CameraCtx = (AWCameraContext*)(camera_dev->context); if(CameraCtx->callback.cookie == NULL) { LOGE("should set callback before start Camera"); return -1; } camera_dev->isYUYV = 0; setV4L2DeviceName(CameraCtx->v4l2ctx, camera_dev->deviceName ); OpenCamera(CameraCtx->v4l2ctx); StartCamera(CameraCtx->v4l2ctx, &CameraCtx->width, &CameraCtx->height); camera_dev->isYUYV = V4L2_PIX_FMT_YUYV == v4l2GetCaptureFmt(CameraCtx->v4l2ctx); err = getFrameRate(CameraCtx->v4l2ctx); LOGD("Camera FPS=%d", err ); set_state(CameraCtx, 1); // Create the camera thread err = pthread_create(&CameraCtx->thread_id, NULL, CameraThread, camera_dev); if (err || !CameraCtx->thread_id) { LOGE("Create thread error"); return -1; } return 0; }
////////////////////////////////////////////////////////////////////////////////// // init -------------------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////////// bool ofxUeye::init(int id){ bool success = false; // close any open camera close(); // try to create windows bullshit if(CreateDisplayWindow()) { // try to open the camera if(OpenCamera(id)) { // store sensor size _sensorWidth = m_nSizeX; _sensorHeight = m_nSizeY; success = true; } else ofLog(OF_LOG_WARNING, "ofxUeye - init - Couldn't open camera."); } else ofLog(OF_LOG_WARNING, "ofxUeye - init - Couldn't create Windows handlers."); return success; }
/* * Method: OnToolClick() * Purpose: called when the user click on of the tools on the * toll bar * Comments: none */ void CMainWindow::OnToolClick(wxCommandEvent& aEvent) { wxTreeItemId lItem = iTree->GetSelection(); if(lItem.IsOk() && lItem != iRoot || aEvent.GetId() == ID_SEEK) { CTreeItemData* lData = (CTreeItemData *)iTree->GetItemData(lItem); switch(aEvent.GetId()) { case ID_INFO: { if(!lData->iInfo) { // create the info window CInfoWindow* lWindow = new CInfoWindow(*this,lData->iData); if(lWindow) { // keep a pointer to it lData->iInfo = lWindow; // and show the window lWindow->Show(true); } } else lData->iInfo->Raise(); break; } case ID_CTRL: { if(!lData->iCtrl) { if(!lData->iHandle) lData->iHandle = OpenCamera(lData->iData.UniqueId,lData->iOwner); if(lData->iHandle) { // create the info window CCtrlWindow* lWindow = new CCtrlWindow(*this,lData->iData,lData->iHandle,lData->iOwner); if(lWindow) { // keep a pointer to it lData->iCtrl = lWindow; // and show the window lWindow->Show(true); if(lData->iFinder) lData->iCtrl->Notify(kEvnLiveOpened,lData->iFinder,true); } } else { wxMessageBox(L"Sorry, the camera couldn't be open.", L"Ooops ...", wxOK | wxICON_ERROR,this); } } else lData->iCtrl->Raise(); break; } case ID_LIVE: { if(!lData->iFinder) { if(!lData->iHandle) lData->iHandle = OpenCamera(lData->iData.UniqueId,lData->iOwner); if(lData->iHandle) { // create the info window CFinderWindow* lWindow = new CFinderWindow(*this,lData->iData,lData->iHandle); if(lWindow) { // keep a pointer to it lData->iFinder = lWindow; // and show the window lWindow->Show(true); if(lData->iCtrl) lData->iCtrl->Notify(kEvnLiveOpened,lWindow,true); } } else { wxMessageBox(L"Sorry, the camera couldn't be open.", L"Ooops ...", wxOK | wxICON_ERROR,this); } } else lData->iFinder->Raise(); break; } case ID_SEEK: { wxTextEntryDialog lDialog(this,L"Please enter the IP address of the camera",L"Seek a camera ...",L"0.0.0.0"); if(lDialog.ShowModal() == wxID_OK) { unsigned long lAddr = inet_addr(lDialog.GetValue().mb_str(wxConvUTF8)); if(lAddr) { iSeeking = new CSeeker(dSEEKER,GetEventHandler(),lAddr); if(iSeeking) if(!iSeeking->Start()) { delete iSeeking; iSeeking = NULL; } } else wxMessageBox(L"You need to enter a valid IP address", L"Ooops ...", wxOK | wxICON_ERROR,this); } break; } case ID_EXPO: { bool lClose = false; if(!lData->iHandle) { lData->iHandle = OpenCamera(lData->iData.UniqueId,lData->iOwner); lClose = true; } if(lData->iHandle) { wxFileDialog lDialog(NULL,wxT("Select an output file"),wxT(""), wxString(lData->iData.SerialNumber,wxConvUTF8), wxT("Text files (*.txt)|*.txt"),wxSAVE | wxOVERWRITE_PROMPT); if(lDialog.ShowModal() == wxID_OK) { wxString lExt = wxT(".txt"); wxString lPath = lDialog.GetPath(); if(!lPath.Contains(lExt)) lPath = lPath + lExt; if(!ExportCamera(lData->iHandle,lPath)) wxMessageBox(wxT("Camera's setup export failed."),wxT("Ooops ..."),wxOK | wxICON_ERROR,this); } if(lClose) { CloseCamera(lData->iHandle); lData->iHandle = NULL; } } break; } case ID_EVNT: { if(!lData->iEvnt) { if(!lData->iHandle) lData->iHandle = OpenCamera(lData->iData.UniqueId,lData->iOwner); if(lData->iOwner) { if(lData->iHandle) { // create the info window CEvntWindow* lWindow = new CEvntWindow(*this,lData->iData,lData->iHandle); if(lWindow) { // keep a pointer to it lData->iEvnt = lWindow; // and show the window lWindow->Show(true); } } else { wxMessageBox(L"Sorry, the camera couldn't be open.", L"Ooops ...", wxOK | wxICON_ERROR,this); } } else { wxMessageBox(L"Sorry, the camera is already open", L"Ooops ...", wxOK | wxICON_ERROR,this); } } else lData->iEvnt->Raise(); break; } case ID_SRIO: { if(!lData->iSrio) { if(!lData->iHandle) lData->iHandle = OpenCamera(lData->iData.UniqueId,lData->iOwner); if(lData->iOwner) { if(lData->iHandle) { // create the info window CSerialWindow* lWindow = new CSerialWindow(*this,lData->iData,lData->iHandle); if(lWindow) { // keep a pointer to it lData->iSrio = lWindow; // and show the window lWindow->Show(true); } } else { wxMessageBox(L"Sorry, the camera couldn't be open.", L"Ooops ...", wxOK | wxICON_ERROR,this); } } else { wxMessageBox(L"Sorry, the camera is already open", L"Ooops ...", wxOK | wxICON_ERROR,this); } } else lData->iSrio->Raise(); break; } } // refresh the list of window RefreshWindowsList(); // and force the window to be updated Update(); } else { wxMessageBox(L"You must select a camera first.", L"Ooops ...", wxOK | wxICON_ERROR,this); } }
void USBCamera::UpdateSettings() { std::lock_guard<priority_recursive_mutex> lock(m_mutex); bool wasActive = m_active; if (wasActive) StopCapture(); if (m_open) CloseCamera(); OpenCamera(); uInt32 count = 0; uInt32 currentMode = 0; SAFE_IMAQ_CALL(IMAQdxEnumerateVideoModes, m_id, nullptr, &count, ¤tMode); auto modes = std::make_unique<IMAQdxVideoMode[]>(count); SAFE_IMAQ_CALL(IMAQdxEnumerateVideoModes, m_id, modes.get(), &count, ¤tMode); // Groups are: // 0 - width // 1 - height // 2 - format // 3 - fps std::regex reMode("([0-9]+)\\s*x\\s*([0-9]+)\\s+(.*?)\\s+([0-9.]+)\\s*fps"); IMAQdxVideoMode* foundMode = nullptr; IMAQdxVideoMode* currentModePtr = &modes[currentMode]; double foundFps = 1000.0; // Loop through the modes, and find the match with the lowest fps for (unsigned int i = 0; i < count; i++) { std::cmatch m; if (!std::regex_match(modes[i].Name, m, reMode)) continue; unsigned int width = (unsigned int)std::stoul(m[1].str()); unsigned int height = (unsigned int)std::stoul(m[2].str()); if (width != m_width) continue; if (height != m_height) continue; double fps = atof(m[4].str().c_str()); if (fps < m_fps) continue; if (fps > foundFps) continue; bool isJpeg = m[3].str().compare("jpeg") == 0 || m[3].str().compare("JPEG") == 0; if ((m_useJpeg && !isJpeg) || (!m_useJpeg && isJpeg)) continue; foundMode = &modes[i]; foundFps = fps; } if (foundMode != nullptr) { if (foundMode->Value != currentModePtr->Value) { SAFE_IMAQ_CALL(IMAQdxSetAttribute, m_id, IMAQdxAttributeVideoMode, IMAQdxValueTypeU32, foundMode->Value); } } if (m_whiteBalance.compare(AUTO) == 0) { SAFE_IMAQ_CALL(IMAQdxSetAttribute, m_id, ATTR_WB_MODE, IMAQdxValueTypeString, AUTO); } else { SAFE_IMAQ_CALL(IMAQdxSetAttribute, m_id, ATTR_WB_MODE, IMAQdxValueTypeString, MANUAL); if (m_whiteBalanceValuePresent) SAFE_IMAQ_CALL(IMAQdxSetAttribute, m_id, ATTR_WB_VALUE, IMAQdxValueTypeU32, m_whiteBalanceValue); } if (m_exposure.compare(AUTO) == 0) { SAFE_IMAQ_CALL(IMAQdxSetAttribute, m_id, ATTR_EX_MODE, IMAQdxValueTypeString, std::string("AutoAperaturePriority").c_str()); } else { SAFE_IMAQ_CALL(IMAQdxSetAttribute, m_id, ATTR_EX_MODE, IMAQdxValueTypeString, MANUAL); if (m_exposureValuePresent) { double minv = 0.0; double maxv = 0.0; SAFE_IMAQ_CALL(IMAQdxGetAttributeMinimum, m_id, ATTR_EX_VALUE, IMAQdxValueTypeF64, &minv); SAFE_IMAQ_CALL(IMAQdxGetAttributeMaximum, m_id, ATTR_EX_VALUE, IMAQdxValueTypeF64, &maxv); double val = minv + ((maxv - minv) * ((double)m_exposureValue / 100.0)); SAFE_IMAQ_CALL(IMAQdxSetAttribute, m_id, ATTR_EX_VALUE, IMAQdxValueTypeF64, val); } } SAFE_IMAQ_CALL(IMAQdxSetAttribute, m_id, ATTR_BR_MODE, IMAQdxValueTypeString, MANUAL); double minv = 0.0; double maxv = 0.0; SAFE_IMAQ_CALL(IMAQdxGetAttributeMinimum, m_id, ATTR_BR_VALUE, IMAQdxValueTypeF64, &minv); SAFE_IMAQ_CALL(IMAQdxGetAttributeMaximum, m_id, ATTR_BR_VALUE, IMAQdxValueTypeF64, &maxv); double val = minv + ((maxv - minv) * ((double)m_brightness / 100.0)); SAFE_IMAQ_CALL(IMAQdxSetAttribute, m_id, ATTR_BR_VALUE, IMAQdxValueTypeF64, val); if (wasActive) StartCapture(); }
void CameraDriver::ReconfigureCallback(UVCCameraConfig &new_config, uint32_t level) { boost::recursive_mutex::scoped_lock(mutex_); if ((level & kReconfigureClose) == kReconfigureClose) { if (state_ == kRunning) CloseCamera(); } if (state_ == kStopped) { OpenCamera(new_config); } if (new_config.camera_info_url != config_.camera_info_url) cinfo_manager_.loadCameraInfo(new_config.camera_info_url); if (state_ == kRunning) { #define PARAM_INT(name, fn, value) if (new_config.name != config_.name) { \ int val = (value); \ if (uvc_set_##fn(devh_, val)) { \ ROS_WARN("Unable to set " #name " to %d", val); \ new_config.name = config_.name; \ } \ } PARAM_INT(scanning_mode, scanning_mode, new_config.scanning_mode); PARAM_INT(auto_exposure, ae_mode, 1 << new_config.auto_exposure); PARAM_INT(auto_exposure_priority, ae_priority, new_config.auto_exposure_priority); PARAM_INT(exposure_absolute, exposure_abs, new_config.exposure_absolute * 10000); PARAM_INT(auto_focus, focus_auto, new_config.auto_focus ? 1 : 0); PARAM_INT(focus_absolute, focus_abs, new_config.focus_absolute); #if libuvc_VERSION > 00005 /* version > 0.0.5 */ PARAM_INT(gain, gain, new_config.gain); PARAM_INT(iris_absolute, iris_abs, new_config.iris_absolute); PARAM_INT(brightness, brightness, new_config.brightness); #endif if (new_config.pan_absolute != config_.pan_absolute || new_config.tilt_absolute != config_.tilt_absolute) { if (uvc_set_pantilt_abs(devh_, new_config.pan_absolute, new_config.tilt_absolute)) { ROS_WARN("Unable to set pantilt to %d, %d", new_config.pan_absolute, new_config.tilt_absolute); new_config.pan_absolute = config_.pan_absolute; new_config.tilt_absolute = config_.tilt_absolute; } } // TODO: roll_absolute // TODO: privacy // TODO: backlight_compensation // TODO: contrast // TODO: power_line_frequency // TODO: auto_hue // TODO: saturation // TODO: sharpness // TODO: gamma // TODO: auto_white_balance // TODO: white_balance_temperature // TODO: white_balance_BU // TODO: white_balance_RV } config_ = new_config; }
void CAMediaManager::addCameraView() { OpenCamera(); }
//双击预置位列表树 void CDlgPresetSetting::OnNMDblclkTreePresettingList(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: 在此添加控件通知处理程序代码 *pResult = 0; HTREEITEM hItem = m_treePresetList.GetSelectedItem(); if (hItem == NULL) { return; } NodeInfo* pNodeInfo = (NodeInfo*)m_treePresetList.GetItemData(hItem); if (pNodeInfo == NULL) { return; } GetDlgItem(IDC_EDIT_CURRENT_CAMERA)->SetWindowText(""); if (pNodeInfo->node_type == CAMERA_NODE) { CloseCamera(m_nCurrentID); //设置各个成员变量 sprintf_s(m_szCameraCode,64,pNodeInfo->node_code); //打开摄像头 if (OpenCamera(m_szCameraCode,pNodeInfo->parent_id)==-1) { MessageBox("转到预置位失败!","辅助系统"); return; } GetDlgItem(IDC_EDIT_CURRENT_CAMERA)->SetWindowText(pNodeInfo->node_name); m_combo_presetnum.SetCurSel(0); //设置预置位名称 SetPresetEditText(); //加载该摄像头下已经设置的预置位 if (GetPresetInfoByCameraCode(hItem,m_pStationNode->station_id,m_szCameraCode,pNodeInfo->parent_id)) return; } if (pNodeInfo->node_type == PRESET_NODE) { //关闭摄像头 CloseCamera(m_nCurrentID); sprintf_s(m_szCameraCode,64,pNodeInfo->node_code); //打开摄像头 if (OpenCamera(m_szCameraCode,pNodeInfo->parent_id)==-1) { MessageBox("转到预置位失败!","辅助系统"); return; } m_nCameraPresetId = pNodeInfo->node_id; ToPreset(m_nCameraPresetId); } }