////////////////////////////////////////////////////////////////////////////////// // close ------------------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////////// void ofxUeye::close() { bReady = false; bLive = false; bIsFrameNew = false; bIsWaitingNewFrame = true; _binning = IS_BINNING_DISABLE; _subSampling = IS_BINNING_DISABLE; _scaler = 1.0; _AOI = ofRectangle(0,0,0,0); _AOINormalized = ofRectangle(0,0,0,0); _AOIMax = ofRectangle(0,0,0,0); _sensorWidth = 0; _sensorHeight = 0; _width = 0; _height = 0; if(_pixels != NULL) delete _pixels; _pixels = NULL; _channels = 0; _bitsPerPixel = 0; _bytesPerPixel = 0; _colorCorrection = 0; CloseCamera(); }
void CameraDriver::Stop() { boost::recursive_mutex::scoped_lock(mutex_); assert(state_ != kInitial); if (state_ == kRunning) CloseCamera(); assert(state_ == kStopped); uvc_exit(ctx_); ctx_ = NULL; state_ = kInitial; }
int CaptureSensorFace(char *Buffer, BOOL Sign,int* ImageSize) { int sizein = 0; int sizeout = 0; static unsigned char CapFailCnt=0; if( cameraflag <0) { CapFailCnt=0; cameraflag=CameraOpen(0); DelayMS(10); SetCameraLed(&videoIn,2,1); SetFaceExtactParams(); } if(cameraflag<0 || hFaceExtact <= 0)// || (FaceInit == 0 && FaceTest==0)) { printf(" Open Face Camera Failed or Init face DB failed \n"); return 0; } sizein = FACE_IMG_W * FACE_IMG_H; sizeout=read(videoIn.fd,(void *)Buffer,sizein); if((sizeout<=0) || (!((sizeout >0)&&chech_jpeg((void *)Buffer,sizeout,FACE_IMG_H,FACE_IMG_W)))) { CapFailCnt++; if(CapFailCnt>3) { CloseCamera(&videoIn); cameraflag=-1; } printf(" check jpg failed \n"); return 0; } #if 0 // save jpg file FILE * fj=NULL; fj=fopen("/mnt/ramdisk/fa.jpg","wb"); if(sizeout == fwrite(Buffer,1, sizeout,fj)) ; // printf("write fa.jpg ok \n"); fclose(fj); sync(); #endif *ImageSize=sizeout; return TRUE; }
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; }
static int stopcamera(AWCameraDevice *p) { AWCameraDevice* camera_dev = (AWCameraDevice *)(p); AWCameraContext* CameraCtx = NULL; int err = 0; if(!camera_dev) return -1; CameraCtx = (AWCameraContext *)(camera_dev->context); set_state(CameraCtx, 0); // Wait for thread to exit; pthread_join(CameraCtx->thread_id, (void*) &err); StopCamera(CameraCtx->v4l2ctx); CloseCamera(CameraCtx->v4l2ctx); return 0; }
/* * 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); } }
/* * Method: OnChildClosed() * Purpose: called when a child window is been closed * Comments: none */ void CMainWindow::OnChildClosed(PChildWindow* aChild) { wxTreeItemId lChild; wxTreeItemIdValue lCookie; CTreeItemData* lData; bool lFound = false; // get the first child lChild = iTree->GetFirstChild(iRoot,lCookie); // then loop over the child in search of the window that // was closed while(lChild.IsOk() && !lFound) { lData = (CTreeItemData *)iTree->GetItemData(lChild); if(lData->iInfo == aChild) { lData->iInfo = NULL; lFound = true; } else if(lData->iFinder == aChild) { lData->iFinder = NULL; lFound = true; // if the control window is still open, we notify it // that the live window is a gonner if(lData->iCtrl) lData->iCtrl->Notify(kEvnLiveClosed,NULL,true); } else if(lData->iCtrl == aChild) { lData->iCtrl = NULL; lFound = true; } else if(lData->iEvnt == aChild) { lData->iEvnt = NULL; lFound = true; } else if(lData->iSrio == aChild) { lData->iSrio = NULL; lFound = true; } // if all the window are closed and that we had the camera // open, we close it if(!lData->iFinder && !lData->iCtrl && !lData->iEvnt && !lData->iSrio && lData->iHandle) { SetStatusText(L"Closing a camera"); CloseCamera(lData->iHandle); lData->iHandle = NULL; } lChild = iTree->GetNextChild(iRoot,lCookie); } RefreshWindowsList(); }
CCameraDS::~CCameraDS() { CloseCamera(); CoUninitialize(); }
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; }
LRESULT CDlgPresetSetting::OnCloseVideoHandle(WPARAM w, LPARAM l) { CloseCamera(m_nCurrentID); return 0; }
//双击预置位列表树 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); } }