數位天堂

Nokia:科技始終來自於人性; 拜耳:如果文明不能使我們更相愛,那科技便失去意義!
歡迎您的加入,讓我們一起討論科技與環保的整合應用...

您尚未登入。

#1 2011-11-16 21:54:17

ardayang
精靈
註冊日期: 2008-05-25
文章數: 104
目前積分 :   

Logitech QuickCam Orbit/Sphere AF(MP) PTZ (Remote) Control

實現近端及遠端控制羅技瞭望台Logitech QuickCam Orbit/Sphere AF 或 MP 機械上下左右及數位放大縮小.
作業平台:WINDOWS XP
驅動程式:Logitech QuickCam 11
編譯程式:Microsoft Visual C++ 2005 Express 版(另需Microsoft Windows SDK v6.0以上)
程式及原始碼: http://webhd.xuite.net/_oops/arda.yang/aiu

LGPTZ

//專案>屬性>連結器>輸入>其他相依性>strmiids.lib oleaut32.lib ole32.lib #include #include // Required by KsMedia.h #include // For KSPROPERTY_CAMERACONTROL_FLAGS_* long pan=0,tilt=0,zoom=0; int reset=0; HRESULT set_mechanical_pan_relative(IAMCameraControl *pCameraControl, long value) { HRESULT hr = 0; long flags = KSPROPERTY_CAMERACONTROL_FLAGS_RELATIVE | KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL; hr = pCameraControl->Set(CameraControl_Pan, value, flags); if(hr != S_OK) //fprintf(stderr, "ERROR: Unable to set CameraControl_Pan property value to %d. (Error 0x%08X)\n", value, hr); Sleep(100); return hr; } HRESULT set_mechanical_tilt_relative(IAMCameraControl *pCameraControl, long value) { HRESULT hr = 0; long flags = KSPROPERTY_CAMERACONTROL_FLAGS_RELATIVE | KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL; hr = pCameraControl->Set(CameraControl_Tilt, value, flags); if(hr != S_OK) //fprintf(stderr, "ERROR: Unable to set CameraControl_Tilt property value to %d. (Error 0x%08X)\n", value, hr); Sleep(100); return hr; } void reset_machanical_pan_tilt(IAMCameraControl *pCameraControl) { set_mechanical_tilt_relative(pCameraControl, 180); Sleep(600); set_mechanical_pan_relative(pCameraControl, 180); Sleep(800); set_mechanical_tilt_relative(pCameraControl, -24); Sleep(600); set_mechanical_pan_relative(pCameraControl, -64); //Sleep(600); } HRESULT set_digital_zoom_absolute(IAMCameraControl *pCameraControl, long value) { HRESULT hr = 0; long flags = KSPROPERTY_CAMERACONTROL_FLAGS_ABSOLUTE | KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL; hr = pCameraControl->Set(CameraControl_Zoom, value, flags); if(hr != S_OK) //fprintf(stderr, "ERROR: Unable to set CameraControl_Zoom property value to %d. (Error 0x%08X)\n", value, hr); return hr; } void reset_digital_zoom(IAMCameraControl *pCameraControl) { set_digital_zoom_absolute(pCameraControl, 50); } HRESULT test_pan_tilt(IBaseFilter *pBaseFilter) { HRESULT hr = 0; IAMCameraControl *pCameraControl = NULL; long value = 0, flags = 0; // Get a pointer to the IAMCameraControl interface used to control the camera hr = pBaseFilter->QueryInterface(IID_IAMCameraControl, (void **)&pCameraControl); if(hr != S_OK) { fprintf(stderr, "ERROR: Unable to access IAMCameraControl interface.\n"); return hr; } if (reset == 1) { printf(" Resetting pan/tilt/zoom ...\n"); //reset_digital_pan_tilt(pCameraControl); reset_digital_zoom(pCameraControl); reset_machanical_pan_tilt(pCameraControl); Sleep(600); } else { set_digital_zoom_absolute(pCameraControl, zoom); set_mechanical_tilt_relative(pCameraControl, tilt); if (tilt != 0 ){Sleep(600);} set_mechanical_pan_relative(pCameraControl, pan); if (pan != 0 ){Sleep(600);} } return S_OK; } void process_filter(IBaseFilter *pBaseFilter) { test_pan_tilt(pBaseFilter); } int enum_devices() { HRESULT hr; // Create the System Device Enumerator. ICreateDevEnum *pSysDevEnum = NULL; hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum); if(FAILED(hr)) { fprintf(stderr, "ERROR: Unable to create system device enumerator.\n"); return hr; } // Obtain a class enumerator for the video input device category. IEnumMoniker *pEnumCat = NULL; hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0); if(hr == S_OK) { // Enumerate the monikers. IMoniker *pMoniker = NULL; ULONG cFetched; while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) { IPropertyBag *pPropBag; hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag); if(SUCCEEDED(hr)) { // To retrieve the filter's friendly name, do the following: VARIANT varName; VariantInit(&varName); hr = pPropBag->Read(L"FriendlyName", &varName, 0); if (SUCCEEDED(hr)) { // Display the name in your UI somehow. wprintf(L" Found device: %s\n", varName.bstrVal); } VariantClear(&varName); // To create an instance of the filter, do the following: IBaseFilter *pFilter; hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, (void**)&pFilter); process_filter(pFilter); //Remember to release pFilter later. pPropBag->Release(); } pMoniker->Release(); } pEnumCat->Release(); } pSysDevEnum->Release(); return 0; } int main(int argc, char* argv[]) { reset = argc; if (argc-1 >= 3 ) { pan = atol(argv[1]); tilt = atol(argv[2]); zoom = atol(argv[3]); } else { printf("\n"); printf("Logitech QuickCam Orbit/Sphere AF PTZ Control. \n"); printf("LGPTZ [Pan Tilt Zoom(50,100,150,200)] \n"); printf("LGPTZ 0 0 200 \n"); printf("LGPTZ 10 -10 50 \n"); printf("LGPTZ -15 15 100 \n"); printf("LGPTZ -20 -20 150 \n"); printf("\n"); } CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); enum_devices(); CoUninitialize(); return 0; }


LGPTZSV

//專案>屬性>連結器>輸入>其他相依性>WSock32.Lib strmiids.lib oleaut32.lib ole32.lib #include #include #include #include // Required by KsMedia.h #include // For KSPROPERTY_CAMERACONTROL_FLAGS_* char port[32]="8766"; long pan=0,tilt=0,zoom=0; int reset=0; HRESULT set_mechanical_pan_relative(IAMCameraControl *pCameraControl, long value) { HRESULT hr = 0; long flags = KSPROPERTY_CAMERACONTROL_FLAGS_RELATIVE | KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL; hr = pCameraControl->Set(CameraControl_Pan, value, flags); if(hr != S_OK) //fprintf(stderr, "ERROR: Unable to set CameraControl_Pan property value to %d. (Error 0x%08X)\n", value, hr); Sleep(100); return hr; } HRESULT set_mechanical_tilt_relative(IAMCameraControl *pCameraControl, long value) { HRESULT hr = 0; long flags = KSPROPERTY_CAMERACONTROL_FLAGS_RELATIVE | KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL; hr = pCameraControl->Set(CameraControl_Tilt, value, flags); if(hr != S_OK) //fprintf(stderr, "ERROR: Unable to set CameraControl_Tilt property value to %d. (Error 0x%08X)\n", value, hr); Sleep(100); return hr; } void reset_machanical_pan_tilt(IAMCameraControl *pCameraControl) { set_mechanical_tilt_relative(pCameraControl, 180); Sleep(600); set_mechanical_pan_relative(pCameraControl, 180); Sleep(800); set_mechanical_tilt_relative(pCameraControl, -24); Sleep(600); set_mechanical_pan_relative(pCameraControl, -64); //Sleep(600); } HRESULT set_digital_zoom_absolute(IAMCameraControl *pCameraControl, long value) { HRESULT hr = 0; long flags = KSPROPERTY_CAMERACONTROL_FLAGS_ABSOLUTE | KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL; hr = pCameraControl->Set(CameraControl_Zoom, value, flags); if(hr != S_OK) //fprintf(stderr, "ERROR: Unable to set CameraControl_Zoom property value to %d. (Error 0x%08X)\n", value, hr); return hr; } void reset_digital_zoom(IAMCameraControl *pCameraControl) { set_digital_zoom_absolute(pCameraControl, 50); } HRESULT test_pan_tilt(IBaseFilter *pBaseFilter) { HRESULT hr = 0; IAMCameraControl *pCameraControl = NULL; long value = 0, flags = 0; hr = pBaseFilter->QueryInterface(IID_IAMCameraControl, (void **)&pCameraControl); if(hr != S_OK) { fprintf(stderr, "ERROR: Unable to access IAMCameraControl interface.\n"); return hr; } if (reset == 1) { printf(" Resetting pan/tilt/zoom ...\n"); //reset_digital_pan_tilt(pCameraControl); reset_digital_zoom(pCameraControl); reset_machanical_pan_tilt(pCameraControl); Sleep(600); } else { set_digital_zoom_absolute(pCameraControl, zoom); set_mechanical_tilt_relative(pCameraControl, tilt); if (tilt != 0 ){Sleep(600);} set_mechanical_pan_relative(pCameraControl, pan); if (pan != 0 ){Sleep(600);} } return S_OK; } void process_filter(IBaseFilter *pBaseFilter) { test_pan_tilt(pBaseFilter); } int enum_devices() { HRESULT hr; // Create the System Device Enumerator. ICreateDevEnum *pSysDevEnum = NULL; hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum); if(FAILED(hr)) { fprintf(stderr, "ERROR: Unable to create system device enumerator.\n"); return hr; } // Obtain a class enumerator for the video input device category. IEnumMoniker *pEnumCat = NULL; hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0); if(hr == S_OK) { // Enumerate the monikers. IMoniker *pMoniker = NULL; ULONG cFetched; while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) { IPropertyBag *pPropBag; hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag); if(SUCCEEDED(hr)) { // To retrieve the filter's friendly name, do the following: VARIANT varName; VariantInit(&varName); hr = pPropBag->Read(L"FriendlyName", &varName, 0); if (SUCCEEDED(hr)) { // Display the name in your UI somehow. wprintf(L" Found device: %s\n", varName.bstrVal); } VariantClear(&varName); // To create an instance of the filter, do the following: IBaseFilter *pFilter; hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, (void**)&pFilter); process_filter(pFilter); //Remember to release pFilter later. pPropBag->Release(); } pMoniker->Release(); } pEnumCat->Release(); } pSysDevEnum->Release(); return 0; } int enum_devices_ok() { CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); enum_devices(); CoUninitialize(); return 0; } int main(int argc, char *argv[]) { printf("\n"); printf("Logitech QuickCam Orbit/Sphere AF PTZ Remote Control Server. \n"); printf("LGPTZSV [port] \n"); printf("LGPTZSV 8766 \n"); printf("\n"); if (argc -1 == 1) { strcpy(port,argv[1]); printf("PORT: %s\n",port); } SOCKET server_sockfd, client_sockfd; int server_len, client_len; struct sockaddr_in server_address; struct sockaddr_in client_address; // 註冊 Winsock DLL WSADATA wsadata; if(WSAStartup(0x101,(LPWSADATA)&wsadata) != 0) { printf("Winsock Error\n"); exit(1); } // 產生 server socket server_sockfd = socket(AF_INET, SOCK_STREAM, 0); // AF_INET(使用IPv4); SOCK_STREAM; 0(使用預設通訊協定,即TCP) if(server_sockfd == SOCKET_ERROR) { printf("Socket Error\n"); exit(1); } server_address.sin_family = AF_INET; // AF_INT(使用IPv4) server_address.sin_addr.s_addr = INADDR_ANY; // 設定IP位址 server_address.sin_port = htons(int(atoi(port))); //設定埠號 server_len = sizeof(server_address); if(bind(server_sockfd, (struct sockaddr *)&server_address, server_len) < 0) { printf("Bind Error\n"); exit(1); } if(listen(server_sockfd, 5) < 0) { printf("Listen Error\n"); exit(1); } while(1) { char ch; printf("Server waiting...\n"); client_len = sizeof(client_address); client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, &client_len); if(client_sockfd == SOCKET_ERROR) { printf("Accept Error\n"); exit(1); } recv(client_sockfd, &ch, 1, 0); // Linux socket programming 為 read //printf("%c \n",ch); if (ch == 114) { pan = 5; enum_devices_ok(); pan = 0; } if (ch == 108) { pan = -5; enum_devices_ok(); pan = 0; } if (ch == 117) { tilt = -5; enum_devices_ok(); tilt = 0; } if (ch == 100) { tilt = 5; enum_devices_ok(); tilt = 0; } if (ch == 122) { zoom = zoom - 50; if (zoom < 49){zoom = 50;} enum_devices_ok(); } if (ch == 90) { zoom = zoom + 50; if (zoom > 201){zoom = 200;} enum_devices_ok(); } if (ch == 111) { reset = 1; enum_devices_ok(); reset = 0; } closesocket(client_sockfd); // Linux socket programming 為 close } }


LGPTZCL

//專案>屬性>連結器>輸入>其他相依性>WSock32.Lib #include<winsock2.h> #include<stdio.h> char ch[32] = "o"; char ip[32]="127.0.0.1"; char port[32]="8766"; int main(int argc, char *argv[]) { SOCKET sockfd; int len; struct sockaddr_in address; int result; if (argc -1 < 1) { printf("\n"); printf("Logitech QuickCam Orbit/Sphere AF PTZ Remote Control Client. \n"); printf("LGPTZCL [[PTZ COMMAND[r l u d z Z o O ]] [ip] [port]] \n"); printf("LGPTZCL o 127.0.0.1 \n"); printf("LGPTZCL o 127.0.0.1 8766\n"); printf("\n"); return 0; } if (argc -1 == 2) { strcpy(ip,argv[2]); } if (argc -1 == 3) { strcpy(ip,argv[2]); strcpy(port,argv[3]); } WSADATA wsadata; if(WSAStartup(0x101,(LPWSADATA)&wsadata) != 0) { printf("Winsock Error\n"); exit(1); } sockfd = socket(AF_INET, SOCK_STREAM, 0); address.sin_family = AF_INET; address.sin_addr.s_addr = inet_addr(ip); address.sin_port = htons(int(atoi(port))); len = sizeof(address); result = connect(sockfd, (struct sockaddr *)&address, len); if(result == -1) { printf("Connetc Error"); exit(1); } strcpy(ch,argv[1]); //printf("send = %s\n", ch); send(sockfd, ch, 1, 0); //recv(sockfd, ch, 1, 0); //printf("char from server = %s\n", ch); closesocket(sockfd); exit(0); }


PHP SEND


參考資料:
http://www.quickcamteam.net/documentati … ch-cameras
http://sites.google.com/site/ucanlab/Ho … with-dev-c



最後修改: ardayang (2011-11-18 18:27:53)


離線

 

相關討論主題

主題 回覆 點閱 最後發表
transmission-remote 作者 tankjaw
1 10789 2011-02-22 10:44:16 作者 tankjaw
1 20753 2008-12-10 23:53:53 作者 Aven

友情連結

論壇頁尾

Powered by PunBB
© Copyright 2018 Rickard Andersson
RSS Feed