【问题标题】:Why does the webcam image appear darker than when it's started from another application?为什么网络摄像头图像看起来比从其他应用程序启动时更暗?
【发布时间】:2012-02-15 17:03:06
【问题描述】:

我正在使用 Windows API 使用附加的网络摄像头拍照。

除了拍摄的照片很暗之外,一切正常。如果我在另一个应用程序中启动网络摄像头,然后用我的应用程序捕获,一切正常。我做错了什么?

这是我使用的代码:

procedure TWebCam.Execute; //different thread
var
  hand: THandle;
  fname: AnsiString;
const
  WM_CAP_START = $0400;
  WM_CAP_DRIVER_CONNECT = $0400 + 10;
  WM_CAP_DRIVER_DISCONNECT = $0400 + 11;
  WM_CAP_SAVEDIB = $0400 + 25;
  WM_CAP_GRAB_FRAME = $0400 + 60;
  WM_CAP_STOP = $0400 + 68;
  WM_CAP_SET_PREVIEW = WM_CAP_START + 50;
  WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52;
  WM_CAP_SET_SCALE = WM_CAP_START + 53;
begin
  FreeOnTerminate := True;
  fname := AnsiString(IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0))) +
    'capture.bmp');
  if FileExists(String(fname)) then DeleteFile(string(fname));
  hand := capCreateCaptureWindowA('CapWindow32', WS_CHILD and WS_VISIBLE, 0, 0,
    0, 0, frmMain.Handle, 0);
  if hand <> 0 then
  begin
    if SendMessage(hand, WM_CAP_DRIVER_CONNECT, 0, 0) <> 0 then
    begin
      SendMessage(hand,WM_CAP_SET_PREVIEWRATE,66,0); //tried some stuff that are not required but without any success
      SendMessage(hand, WM_CAP_SET_PREVIEW, 1, 0);
      Sleep(5000);
      SendMessage(hand, WM_CAP_GRAB_FRAME, 0, 0);
      SendMessage(hand, WM_CAP_SAVEDIB, 0, NativeInt(PAnsichar(fname)));
      SendMessage(hand, WM_CAP_DRIVER_DISCONNECT, 0, 0);
      SendMessage(hand, $0010, 0, 0);
      SendMessage(frmMain.Handle,WM_USER + 24,0,0); //notify main thread
    end
    else
    begin
      SendMessage(hand, $0010, 0, 0);
      Synchronize(NoWebcam);
    end;
  end
  else
    Synchronize(NoWebcam);
end;

【问题讨论】:

  • 我认为在“WM_CAP_DRIVER_CONNECT”之后您需要发送另一条消息,这将使网络摄像头的 LED 发光(:
  • @DorinDuminica 最终 sa dea drumu la bec :))
  • @AndreasRejbrand det var ett skämt ... du är alltid kränkande och sarkastiska ... har du vänner?
  • @AndreasRejbrand 以为您只是为了一个简单的玩笑而投了反对票……抱歉并不是粗鲁……只是我不喜欢每次我发布问题时都被否决了,我没有连原因都不知道……我很抱歉
  • 也许this 会有所帮助。

标签: delphi webcam


【解决方案1】:

我不想给自己的问题一个答案,但也许将来有人会发现它很有用。

问题是网络摄像头在启动时会逐渐调整其亮度,因此您必须先捕获一些虚拟帧才能获得正常图片...这是我现在使用的:

var
 i : Integer;
...
begin
...
   for i := 0 to 24 do
   begin
     SendMessage(hand, WM_CAP_GRAB_FRAME, 0, 0);
     Sleep(200)
   end;
...
end;

像一个魅力,有点hacky,我希望设备也存在WaitForInputIdle函数......

【讨论】:

    猜你喜欢
    • 2015-04-18
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    • 2012-09-16
    相关资源
    最近更新 更多