int cwebcamcamera::startwebcam(hwnd hparent, int nwidth, int nheight)
;tchar szver[max_path] = ;
bool bret = capgetdriverdescription(0, szname, max_path, szver, max_path);
if (!bret)
m_hwnd = capcreatecapturewindow(szname, ws_visible | ws_child, 0, 0, nwidth, nheight, hparent, 0);
bitmapinfo bitmapinfo;
bitmapinfo.bmiheader.bisize = sizeof(bitmapinfo.bmiheader);
bitmapinfo.bmiheader.biwidth = nwidth;
bitmapinfo.bmiheader.biheight = nheight;
bitmapinfo.bmiheader.biplanes = 1;
bitmapinfo.bmiheader.bibitcount = 24;
capsetvideoformat(m_hwnd, &bitmapinfo, sizeof(bitmapinfo));
capsetcallbackonframe(m_hwnd, framecallbackproc);
setwindowpos(m_hwnd, null, 0, 0, nwidth,
nheight, swp_nozorder | swp_nomove);
}return 0;
}lresult winapi cwebcamcamera::framecallbackproc(hwnd hwnd, lpvideohdr lpvhdr)
2.也可以通過capgrabframe和capeditcopy把幀資料儲存到剪貼簿裡,然後通過剪貼簿獲取影象。
然後把點陣圖資料儲存為位**件。
hbitmap hbitmap = null;
capgrabframe(m_hwnd);
capeditcopy(m_hwnd);
openclipboard(null);
hbitmap = (hbitmap)getclipboarddata(cf_bitmap);
closeclipboard();
就是這麼簡單。封裝成乙個class,**如下:
//webcamcamera.h
#pragma once
#include
class cwebcamcamera
;//webcamcamera.cpp
#include "stdafx.h"
#include "webcamcamera.h"
cwebcamcamera::cwebcamcamera(void)
cwebcamcamera::~cwebcamcamera(void)
int cwebcamcamera::startwebcam(hwnd hparent, int nwidth, int nheight)
;tchar szver[max_path] = ;
bool bret = capgetdriverdescription(0, szname, max_path, szver, max_path);
if (!bret)
m_hwnd = capcreatecapturewindow(szname, ws_visible | ws_child, 0, 0, nwidth, nheight, hparent, 0);
bitmapinfo bitmapinfo;
bitmapinfo.bmiheader.bisize = sizeof(bitmapinfo.bmiheader);
bitmapinfo.bmiheader.biwidth = nwidth;
bitmapinfo.bmiheader.biheight = nheight;
bitmapinfo.bmiheader.biplanes = 1;
bitmapinfo.bmiheader.bibitcount = 24;
capsetvideoformat(m_hwnd, &bitmapinfo, sizeof(bitmapinfo));
capsetcallbackonframe(m_hwnd, framecallbackproc);
setwindowpos(m_hwnd, null, 0, 0, nwidth,
nheight, swp_nozorder | swp_nomove);
}return 0;
}int cwebcamcamera::closewebcam(void)
return 0;
}lresult winapi cwebcamcamera::framecallbackproc(hwnd hwnd, lpvideohdr lpvhdr)
int cwebcamcamera::takesnapshot(istream* pipicture)
hbitmap hbitmap = null;
if (m_hwnd)
else
if (hbitmap)
bfh.bftype = 'mb'; // little-endian for "mb".
bfh.bfsize = (dword) (sizeof(bitmapfileheader) +
pbih->bisize + pbih->biclrused
* sizeof(rgbquad) + pbih->bisizeimage);
bfh.bfoffbits = (dword) sizeof(bitmapfileheader) +
pbih->bisize + pbih->biclrused
* sizeof (rgbquad);
pipicture->seek(lizero, stream_seek_set, null);
pipicture->write(&bfh, sizeof(bfh), null);
pipicture->write((lpvoid)pbih, sizeof(bitmapinfoheader)
+ pbih->biclrused * sizeof (rgbquad), null);
pipicture->write(lpbits, pbih->bisizeimage, null);
globalfree((hglobal)lpbits);
}return 0;
}int cwebcamcamera::takesnapshot(tchar* szpicture)
hbitmap hbitmap = null;
if ( m_hwnd )
else
if ( hbitmap )
bfh.bftype = 'mb'; // little-endian for "mb".
bfh.bfsize = (dword) (sizeof(bitmapfileheader) +
pbih->bisize + pbih->biclrused
* sizeof(rgbquad) + pbih->bisizeimage);
bfh.bfoffbits = (dword) sizeof(bitmapfileheader) +
pbih->bisize + pbih->biclrused
* sizeof (rgbquad);
writefile(hfile, &bfh, sizeof(bfh), &dwwritten, null);
writefile(hfile, (lpvoid)pbih, sizeof(bitmapinfoheader)+ pbih->biclrused * sizeof (rgbquad), &dwwritten, null);
writefile(hfile, lpbits, pbih->bisizeimage, &dwwritten, null);
globalfree((hglobal)lpbits);
if ( hfile )
}else
return 0;
}pbitmapinfo cwebcamcamera::createbitmapinfostruct(hbitmap hbmp)
USB攝像頭 介紹
從攝像頭的工作原理就可以列出攝像頭的主要結構和元件 1 鏡頭 lens 透鏡結構,由幾片透鏡組成,有塑膠透鏡 plastic 或玻璃透鏡 glass 2 影象感測器 sensor 可以分為兩類 ccd charge couple device 電荷耦合器件 cmos complementary me...
樹莓派使用usb攝像頭
sudo apt get install fswebcam 安裝拍照工具 fswebcam s10 test2.jpg 拍照基礎路徑預設在home d設定拍照的源解決黑屏問題 no banner 關標籤 r 設定解析度 後路徑設定 在樹莓派裡開攝像頭 sudo apt getinstall moti...
usb攝像頭鏈結vmware
1,usb攝像頭插到電腦上,主機可以響應,vm不能!vm removable devices 下面沒有識別usb camera 2,設定開啟vm usb 計算機 管理 服務和應用程式 vmware usb arbitration service 開啟 重啟 重啟vm,不是重啟虛擬機器,是重啟vm v...