void	CAviCap::_getDrvList()
{
	if(_totalDrv())
		{_drvNames.RemoveAll( );
		_drvVers.RemoveAll( );}
	_drvNames.SetSize(0,1);
	_drvVers.SetSize(0,1);

    int j;
    char szName[80];
    char szVer[80];

    for (j =0; j < MAXCAPDRIVERS; j++) 
        if (capGetDriverDescription (j,
                szName, sizeof (szName),
                szVer,  sizeof (szVer))) 
	{
           _drvNames.Add((LPCSTR)szName);
	   _drvVers.Add((LPCSTR)szVer);
        }
    	else
	{
	break; // !!!! terminate 
	}
}
示例#2
0
文件: capture.c 项目: ofilin/remcam2
void cap_getdevname(char *buff, size_t buflen, int device)
{
	if(!capGetDriverDescription(
		device, 
		buff,
		(DWORD)buflen,
		NULL,
		0))
	{
		strcpy(buff, "No device");
	}
}
示例#3
0
int GetCamIndex()
{
int wIndex;
char szDeviceName[80];
char szDeviceVersion[80];

for (wIndex = 0; wIndex < 9; wIndex++){
	if (capGetDriverDescription(wIndex, szDeviceName,sizeof (szDeviceName),szDeviceVersion, sizeof(szDeviceVersion)))
		return wIndex;
}
return -1;
}
示例#4
0
Array<MMCaptureDevice> MMCaptureDevice::getDevices() { // static
  Array<MMCaptureDevice> devices;
  for(int i = 0; i < 10; i++) {
    TCHAR deviceName[100];
    TCHAR deviceVersion[100];
    if(capGetDriverDescription(i, deviceName, ARRAYSIZE(deviceName), deviceVersion, ARRAYSIZE(deviceVersion))) {
      devices.add(MMCaptureDevice(deviceName,deviceVersion));
    } else {
      break;
    }
  }
  return devices;
}
示例#5
0
//Description: gets the name of an imaging device associated with a given ID number
//Input: digitizer ID number and a dummy string
//Output: returns success (non-negative) or failure, digitizer name in dummy string
EXPORT long GetDigitizer(long lID, CHAR *szName) {
	CHAR szVer[80];
	CHAR szTemp[80];

	//get the name of the capture device associated with the given ID
	if(!capGetDriverDescription (lID, szTemp, sizeof(szTemp), szVer, sizeof(szVer)))
		return -1;
	//copy the new device name over the dummy string provided by LabView
	else
		strcpy(szName, szTemp);

	return 0;
}
示例#6
0
// Initialize camera input
bool CvCaptureCAM_VFW::open( int wIndex )
{
    char szDeviceName[80];
    char szDeviceVersion[80];
    HWND hWndC = 0;

    close();

    if( (unsigned)wIndex >= 10 )
        wIndex = 0;

    for( ; wIndex < 10; wIndex++ )
    {
        if( capGetDriverDescription( wIndex, szDeviceName,
            sizeof (szDeviceName), szDeviceVersion,
            sizeof (szDeviceVersion)))
        {
            hWndC = capCreateCaptureWindow ( "My Own Capture Window",
                WS_POPUP | WS_CHILD, 0, 0, 320, 240, 0, 0);
            if( capDriverConnect (hWndC, wIndex))
                break;
            DestroyWindow( hWndC );
            hWndC = 0;
        }
    }

    if( hWndC )
    {
        capWnd = hWndC;
        hdr = 0;
        hic = 0;
        fourcc = (DWORD)-1;

        memset( &caps, 0, sizeof(caps));
        capDriverGetCaps( hWndC, &caps, sizeof(&caps));
        ::MoveWindow( hWndC, 0, 0, 320, 240, TRUE );
        capSetUserData( hWndC, (size_t)this );
        capSetCallbackOnFrame( hWndC, frameCallback );
        CAPTUREPARMS p;
        capCaptureGetSetup(hWndC,&p,sizeof(CAPTUREPARMS));
        p.dwRequestMicroSecPerFrame = 66667/2;
        capCaptureSetSetup(hWndC,&p,sizeof(CAPTUREPARMS));
        //capPreview( hWndC, 1 );
        capPreviewScale(hWndC,FALSE);
        capPreviewRate(hWndC,1);
    }
    return capWnd != 0;
}
示例#7
0
bool CVideoCap::IsWebCam()
{
    // 已经连接了
    if (m_bIsConnected)
        return false;

    bool	bRet = false;

    char	lpszName[100], lpszVer[50];
    for (int i = 0; i < 10 && !bRet; i++)
    {
        bRet = capGetDriverDescription(i, lpszName, sizeof(lpszName),
                                       lpszVer, sizeof(lpszVer));
    }
    return bRet;
}
示例#8
0
static VfwEngine * vfw_engine_new(int i){
	char dev[512];
	char ver[512];
	VfwEngine *obj=(VfwEngine*)ms_new0(VfwEngine,1);
	if (capGetDriverDescription(i, dev, sizeof (dev),
		ver, sizeof (ver))){
		obj->devidx=i;
		if (_vfw_engine_connect(obj)==-1){
			ms_free(obj);
			return NULL;
		}
		strcpy(obj->dev,dev);
		engines[i]=obj;
		return obj;
	}
	return NULL;
}
示例#9
0
// Initialize camera input
bool CvCaptureCAM_VFW::open( int wIndex )
{
    char szDeviceName[80];
    char szDeviceVersion[80];
    HWND hWndC = 0;

    close();

    if( (unsigned)wIndex >= 10 )
        wIndex = 0;

    for( ; wIndex < 10; wIndex++ )
    {
        if( capGetDriverDescription( wIndex, szDeviceName,
            sizeof (szDeviceName), szDeviceVersion,
            sizeof (szDeviceVersion)))
        {
            hWndC = capCreateCaptureWindow ( "My Own Capture Window",
                WS_POPUP | WS_CHILD, 0, 0, 320, 240, 0, 0);
            if( capDriverConnect (hWndC, wIndex))
                break;
            DestroyWindow( hWndC );
            hWndC = 0;
        }
    }

    if( hWndC )
    {
        capWnd = hWndC;
        hdr = 0;
        hic = 0;
        fourcc = (DWORD)-1;

        memset( &caps, 0, sizeof(caps));
        capDriverGetCaps( hWndC, &caps, sizeof(caps));
        CAPSTATUS status = {};
        capGetStatus(hWndC, &status, sizeof(status));
        ::SetWindowPos(hWndC, NULL, 0, 0, status.uiImageWidth, status.uiImageHeight, SWP_NOZORDER|SWP_NOMOVE);
        capSetUserData( hWndC, (size_t)this );
        capSetCallbackOnFrame( hWndC, frameCallback );
        CAPTUREPARMS p;
        capCaptureGetSetup(hWndC,&p,sizeof(CAPTUREPARMS));
        p.dwRequestMicroSecPerFrame = 66667/2; // 30 FPS
        capCaptureSetSetup(hWndC,&p,sizeof(CAPTUREPARMS));
        //capPreview( hWndC, 1 );
        capPreviewScale(hWndC,FALSE);
        capPreviewRate(hWndC,1);

        // Get frame initial parameters.
        const DWORD size = capGetVideoFormatSize(capWnd);
        if( size > 0 )
        {
            unsigned char *pbi = new unsigned char[size];
            if( pbi )
            {
                if( capGetVideoFormat(capWnd, pbi, size) == size )
                {
                    BITMAPINFOHEADER& vfmt = ((BITMAPINFO*)pbi)->bmiHeader;
                    widthSet = vfmt.biWidth;
                    heightSet = vfmt.biHeight;
                    fourcc = vfmt.biCompression;
                }
                delete []pbi;
            }
        }
        // And alternative way in case of failure.
        if( widthSet == 0 || heightSet == 0 )
        {
            widthSet = status.uiImageWidth;
            heightSet = status.uiImageHeight;
        }

    }
    return capWnd != 0;
}
示例#10
0
static int vfw_read_header(AVFormatContext *s)
{
    struct vfw_ctx *ctx = s->priv_data;
    AVCodecContext *codec;
    AVStream *st;
    int devnum;
    int bisize;
    BITMAPINFO *bi = NULL;
    CAPTUREPARMS cparms;
    DWORD biCompression;
    WORD biBitCount;
    int ret;
    AVRational framerate_q;

    if (!strcmp(s->filename, "list")) {
        for (devnum = 0; devnum <= 9; devnum++) {
            char driver_name[256];
            char driver_ver[256];
            ret = capGetDriverDescription(devnum,
                                          driver_name, sizeof(driver_name),
                                          driver_ver, sizeof(driver_ver));
            if (ret) {
                av_log(s, AV_LOG_INFO, "Driver %d\n", devnum);
                av_log(s, AV_LOG_INFO, " %s\n", driver_name);
                av_log(s, AV_LOG_INFO, " %s\n", driver_ver);
            }
        }
        return AVERROR(EIO);
    }

    ctx->hwnd = capCreateCaptureWindow(NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0);
    if(!ctx->hwnd) {
        av_log(s, AV_LOG_ERROR, "Could not create capture window.\n");
        return AVERROR(EIO);
    }

    /* If atoi fails, devnum==0 and the default device is used */
    devnum = atoi(s->filename);

    ret = SendMessage(ctx->hwnd, WM_CAP_DRIVER_CONNECT, devnum, 0);
    if(!ret) {
        av_log(s, AV_LOG_ERROR, "Could not connect to device.\n");
        DestroyWindow(ctx->hwnd);
        return AVERROR(ENODEV);
    }

    SendMessage(ctx->hwnd, WM_CAP_SET_OVERLAY, 0, 0);
    SendMessage(ctx->hwnd, WM_CAP_SET_PREVIEW, 0, 0);

    ret = SendMessage(ctx->hwnd, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0,
                      (LPARAM) videostream_cb);
    if(!ret) {
        av_log(s, AV_LOG_ERROR, "Could not set video stream callback.\n");
        goto fail;
    }

    SetWindowLongPtr(ctx->hwnd, GWLP_USERDATA, (LONG_PTR) s);

    st = avformat_new_stream(s, NULL);
    if(!st) {
        vfw_read_close(s);
        return AVERROR(ENOMEM);
    }

    /* Set video format */
    bisize = SendMessage(ctx->hwnd, WM_CAP_GET_VIDEOFORMAT, 0, 0);
    if(!bisize)
        goto fail;
    bi = av_malloc(bisize);
    if(!bi) {
        vfw_read_close(s);
        return AVERROR(ENOMEM);
    }
    ret = SendMessage(ctx->hwnd, WM_CAP_GET_VIDEOFORMAT, bisize, (LPARAM) bi);
    if(!ret)
        goto fail;

    dump_bih(s, &bi->bmiHeader);

    ret = av_parse_video_rate(&framerate_q, ctx->framerate);
    if (ret < 0) {
        av_log(s, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", ctx->framerate);
        goto fail;
    }

    if (ctx->video_size) {
        ret = av_parse_video_size(&bi->bmiHeader.biWidth, &bi->bmiHeader.biHeight, ctx->video_size);
        if (ret < 0) {
            av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n");
            goto fail;
        }
    }

    if (0) {
        /* For testing yet unsupported compressions
         * Copy these values from user-supplied verbose information */
        bi->bmiHeader.biWidth       = 320;
        bi->bmiHeader.biHeight      = 240;
        bi->bmiHeader.biPlanes      = 1;
        bi->bmiHeader.biBitCount    = 12;
        bi->bmiHeader.biCompression = MKTAG('I','4','2','0');
        bi->bmiHeader.biSizeImage   = 115200;
        dump_bih(s, &bi->bmiHeader);
    }

    ret = SendMessage(ctx->hwnd, WM_CAP_SET_VIDEOFORMAT, bisize, (LPARAM) bi);
    if(!ret) {
        av_log(s, AV_LOG_ERROR, "Could not set Video Format.\n");
        goto fail;
    }

    biCompression = bi->bmiHeader.biCompression;
    biBitCount = bi->bmiHeader.biBitCount;

    /* Set sequence setup */
    ret = SendMessage(ctx->hwnd, WM_CAP_GET_SEQUENCE_SETUP, sizeof(cparms),
                      (LPARAM) &cparms);
    if(!ret)
        goto fail;

    dump_captureparms(s, &cparms);

    cparms.fYield = 1; // Spawn a background thread
    cparms.dwRequestMicroSecPerFrame =
                               (framerate_q.den*1000000) / framerate_q.num;
    cparms.fAbortLeftMouse = 0;
    cparms.fAbortRightMouse = 0;
    cparms.fCaptureAudio = 0;
    cparms.vKeyAbort = 0;

    ret = SendMessage(ctx->hwnd, WM_CAP_SET_SEQUENCE_SETUP, sizeof(cparms),
                      (LPARAM) &cparms);
    if(!ret)
        goto fail;

    codec = st->codec;
    codec->time_base = av_inv_q(framerate_q);
    codec->codec_type = AVMEDIA_TYPE_VIDEO;
    codec->width  = bi->bmiHeader.biWidth;
    codec->height = bi->bmiHeader.biHeight;
    codec->pix_fmt = vfw_pixfmt(biCompression, biBitCount);
    if(codec->pix_fmt == AV_PIX_FMT_NONE) {
        codec->codec_id = vfw_codecid(biCompression);
        if(codec->codec_id == AV_CODEC_ID_NONE) {
            av_log(s, AV_LOG_ERROR, "Unknown compression type. "
                             "Please report verbose (-v 9) debug information.\n");
            vfw_read_close(s);
            return AVERROR_PATCHWELCOME;
        }
        codec->bits_per_coded_sample = biBitCount;
    } else {
        codec->codec_id = AV_CODEC_ID_RAWVIDEO;
        if(biCompression == BI_RGB) {
            codec->bits_per_coded_sample = biBitCount;
            codec->extradata = av_malloc(9 + AV_INPUT_BUFFER_PADDING_SIZE);
            if (codec->extradata) {
                codec->extradata_size = 9;
                memcpy(codec->extradata, "BottomUp", 9);
            }
        }
    }

    av_freep(&bi);

    avpriv_set_pts_info(st, 32, 1, 1000);

    ctx->mutex = CreateMutex(NULL, 0, NULL);
    if(!ctx->mutex) {
        av_log(s, AV_LOG_ERROR, "Could not create Mutex.\n" );
        goto fail;
    }
    ctx->event = CreateEvent(NULL, 1, 0, NULL);
    if(!ctx->event) {
        av_log(s, AV_LOG_ERROR, "Could not create Event.\n" );
        goto fail;
    }

    ret = SendMessage(ctx->hwnd, WM_CAP_SEQUENCE_NOFILE, 0, 0);
    if(!ret) {
        av_log(s, AV_LOG_ERROR, "Could not start capture sequence.\n" );
        goto fail;
    }

    return 0;

fail:
    av_freep(&bi);
    vfw_read_close(s);
    return AVERROR(EIO);
}
示例#11
0
void CDlgCapCam::Active(void)
{
	printf("capcam active\r\n");
	CString str;
	m_flg_process = 0;

	//init cfg para
	algo_cfg_path = config_path + _T("\\advanced_parameters_default.ini");
	strncpy_s(_vsv_dll_path, config_path.GetBuffer(), 256);

	memset(&m_algo_cfg, 0, sizeof(m_algo_cfg));
	memset(m_algo_cfg.scene, 0xFF, STE_IMAGE_HEIGH*STE_IMAGE_WIDTH);
	m_algo_cfg.val_sense = GetPrivateProfileInt(_T("SMOKETRACE"), _T("sensitivity"), 2, algo_cfg_path);
	m_algo_cfg.val_delay = GetPrivateProfileInt(_T("SMOKETRACE"), _T("delay"), 2, algo_cfg_path);
	m_algo_cfg.val_fov = GetPrivateProfileInt(_T("SMOKETRACE"), _T("fov"), 1, algo_cfg_path);
	m_algo_cfg.val_static_det = GetPrivateProfileInt(_T("SMOKETRACE"), _T("sdet"), 1, algo_cfg_path);
	m_algo_cfg.alarm_delay = GetPrivateProfileInt(_T("SMOKETRACE"), _T("alarmdelay"), 1, algo_cfg_path);

	video_file_info_frame = 0;
	video_file_info_fps = 25;
	video_file_info_fourcc = 0;
	video_file_info_width = 0;
	video_file_info_height = 0;

	//清空交换内存
	m_proc_result_buf.target_set.num = 0;
	m_proc_result_buf.event_set.num = 0;
	m_proc_result_buf.frame_index = 0;
	m_proc_result_buf.fps = 0;

	m_trigger_snatch_time = 0;
	m_trigger_index  = 0;

	//抓拍参数
	m_snatch_count =0 ;
	m_snatch_intertime = 0;
	m_snatch_pretime = 0;

	m_start_time = 0;

	//枚举所有有效地摄像机
	//m_combo_list_device.ResetContent();

	TCHAR szDeviceName[80];
	TCHAR szDeviceVersion[80];
	for (int wIndex = 0; wIndex < 10; wIndex++)
	{
		if (capGetDriverDescription (wIndex, szDeviceName,
			sizeof (szDeviceName), szDeviceVersion,
			sizeof (szDeviceVersion)))
		{
			m_combo_list_device.AddString(szDeviceName);
		}
	}
	if (m_combo_list_device.GetCount()>0)
	{
		m_combo_list_device.SetCurSel(0);
	}
	else
	{
		AfxMessageBox(_T("Error!You have no installed video capture device!"));
	}


	Invalidate();

}
示例#12
0
int _zbar_video_open (zbar_video_t *vdo,
                      const char *dev)
{
    video_state_t *state = vdo->state;
    if(!state)
        state = vdo->state = calloc(1, sizeof(video_state_t));

    int reqid = -1;
    if((!strncmp(dev, "/dev/video", 10) ||
        !strncmp(dev, "\\dev\\video", 10)) &&
       dev[10] >= '0' && dev[10] <= '9' && !dev[11])
        reqid = dev[10] - '0';
    else if(strlen(dev) == 1 &&
            dev[0] >= '0' && dev[0] <= '9')
        reqid = dev[0] - '0';

    zprintf(6, "searching for camera: %s (%d)\n", dev, reqid);
    char name[MAX_NAME], desc[MAX_NAME];
    int devid;
    for(devid = 0; devid < MAX_DRIVERS; devid++) {
        if(!capGetDriverDescription(devid, name, MAX_NAME, desc, MAX_NAME)) {
            /* FIXME TBD error */
            zprintf(6, "    [%d] not found...\n", devid);
            continue;
        }
        zprintf(6, "    [%d] %.100s - %.100s\n", devid, name, desc);
        if((reqid >= 0)
           ? devid == reqid
           : !strncmp(dev, name, MAX_NAME))
            break;
    }
    if(devid >= MAX_DRIVERS)
        return(err_capture_str(vdo, SEV_ERROR, ZBAR_ERR_INVALID, __func__,
                               "video device not found '%s'", dev));

    if(!state->captured)
        state->captured = CreateEvent(NULL, 0, 0, NULL);
    else
        ResetEvent(state->captured);

    if(_zbar_thread_start(&state->thread, vfw_capture_thread, vdo, NULL))
        return(-1);

    /* FIXME error */
    assert(state->hwnd);

    if(!capDriverConnect(state->hwnd, devid)) {
        _zbar_thread_stop(&state->thread, NULL);
        return(err_capture_str(vdo, SEV_ERROR, ZBAR_ERR_INVALID, __func__,
                               "failed to connect to camera '%s'", dev));
    }

    zprintf(1, "opened camera: %.60s (%d) (thr=%04lx)\n",
            name, devid, _zbar_thread_self());

    if(vfw_probe(vdo)) {
        _zbar_thread_stop(&state->thread, NULL);
        return(-1);
    }
    return(0);
}