macos 以编程方式访问 iSight?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:52:19  来源:igfitidea点击:

Accessing iSight programmatically?

objective-cmacoswebcamisight

提问by Paul Wicks

Is it possible to access the iSight camera on a macbook programmatically? By this I mean I would like to be able to just grab still frames from the iSight camera on command and then do something with them. If so, is it only accessible using objective c, or could other languages be used as well?

是否可以通过编程方式访问 macbook 上的 iSight 摄像头?我的意思是我希望能够根据命令从 iSight 摄像头抓取静止帧,然后对它们进行处理。如果是这样,它只能使用目标 c 访问,还是也可以使用其他语言?

回答by Nick Brosnahan

You should check out the QTKit Capture documentation.

您应该查看QTKit Capture 文档

On Leopard, you can get at all of it over the RubyCocoa bridge:

在 Leopard 上,您可以通过 RubyCocoa 桥获得所有这些信息:

require 'osx/cocoa'
OSX.require_framework("/System/Library/Frameworks/QTKit.framework")

OSX::QTCaptureDevice.inputDevices.each do |device|
    puts device.localizedDisplayName
end

回答by Michael Stum

I don't have a Mac here, but there is some Documentation up here:

我这里没有 Mac,但这里有一些文档:

http://developer.apple.com/documentation/Hardware/Conceptual/iSightProgGuide/01introduction/chapter_1_section_1.html

http://developer.apple.com/documentation/Hardware/Conceptual/iSightProgGuide/01introduction/chapter_1_section_1.html

It looks like you have to go through the QuickTime API. There is supposed to be a Sample Project called "MungGrab" which could be worth a look according to this thread.

看起来您必须通过 QuickTime API。应该有一个名为“MungGrab”的示例项目,根据此线程可能值得一看。

回答by Facebook Staff are Complicit

If you poke around Apple's mailing lists you can find some code to do it in Java as well. Here's a simple example suitable for capturing individual frames, and here's a more complicated one that's fast enough to display live video.

如果您浏览 Apple 的邮件列表,您也可以找到一些用 Java 编写的代码。这是一个适用于捕获单个帧的简单示例这是一个更复杂的示例,其速度足以显示实时视频

回答by Kristof Van Landschoot

One thing that hasn't been mentioned so far is the IKPictureTaker, which is part of Image Kit. This will come up with the standard OS provided panel to take pictures though, with all the possible filter functionality etc. included. I'm not sure if that's what you want.

到目前为止还没有提到的一件事是IKPictureTaker,它是 Image Kit 的一部分。这将提供标准操作系统提供的面板来拍照,包括所有可能的过滤器功能等。我不确定这是否是你想要的。

I suppose you can use it from other languages as well, considering there are things like cocoa bridgesbut I have no experience with them.

我想你也可以从其他语言中使用它,考虑到像可可桥这样的东西,但我没有使用它们的经验。

Googling also came up with another question on stackoverflowthat seems to address this issue.

谷歌搜索还提出了关于 stackoverflow 的另一个问题,似乎解决了这个问题。

回答by Theo

There's a command line utility called isightcapturethat does more or less what you want to do. You could probably get the code from the developer (his e-mail address is in the readme you get when you download the utility).

有一个命令行实用程序isightcapture可以或多或少地完成您想做的事情。您可能会从开发人员那里获得代码(他的电子邮件地址在您下载该实用程序时获得的自述文件中)。

回答by dbr

Aside from ObjC, you can use the PyObjC or RubyCocoa bindings to access it also. If you're not picky about which language, I'd say use Ruby, as PyObjC is horribly badly documented (even the official Apple page on it refers to the old version, not the one that came with OS X Leopard)

除了 ObjC,您还可以使用 PyObjC 或 RubyCocoa 绑定来访问它。如果您对哪种语言不挑剔,我会说使用 Ruby,因为 PyObjC 的记录非常糟糕(即使是 Apple 官方页面也指的是旧版本,而不是 OS X Leopard 附带的那个)

Quartz Composer is probably the easiest way to access it, and .quartz files can be embed in applications pretty easily (and the data piped out to ObjC or such)

Quartz Composer 可能是访问它的最简单方法,并且 .quartz 文件可以很容易地嵌入到应用程序中(并且数据通过管道传输到 ObjC 或类似的地方)

Also, I suppose there should be an example or two of this in the /Developer/Examples/

另外,我想 /Developer/Examples/ 中应该有一两个这样的例子

回答by meduz

From a related question which specifically asked the solution to be pythonic, you should give a try to motmot's camifacelibrary from Andrew Straw. It also works with firewire cameras, but it works also with the isight, which is what you are looking for.

从一个专门要求解决方案为pythonic的相关问题中,您应该尝试一下来自 Andrew Straw 的motmot 的 camiface库。它也适用于火线相机,但它也适用于您正在寻找的 isight。

From the tutorial:

从教程:

import motmot.cam_iface.cam_iface_ctypes as cam_iface
import numpy as np

mode_num = 0
device_num = 0
num_buffers = 32

cam = cam_iface.Camera(device_num,num_buffers,mode_num)
cam.start_camera()
frame = np.asarray(cam.grab_next_frame_blocking())
print 'grabbed frame with shape %s'%(frame.shape,)