0
我預先寫好的代碼應該可以訪問我的USB網絡攝像頭。據我瞭解,它使用URL方案(我是編程新手,很抱歉,如果我說的是廢話)。 所以我現在有下面的代碼,我想知道如何使用opencv_capture而不是例如DummyCapture來訪問攝像頭。如何確認條件「if scheme =='opencv'」?如何正確使用「urlparse」
如果有人知道如何解決這個問題,這將是一個很大的幫助!
from traits.trait_base import ETSConfig
#ETSConfig.toolkit = "wx"
# fix window color on unity TODO: gets overriden by splitter
if ETSConfig.toolkit == "wx":
from traitsui.wx import constants
constants.WindowColor = constants.wx.NullColor
import optparse, logging, urlparse
from capture import BaseCapture, DummyCapture
from bullseye import Bullseye
from process import Process
def main():
p = optparse.OptionParser(usage="%prog [options]")
p.add_option("-c", "--camera", default="any:",
help="camera uri (none:, any:, dc1394://guid/b09d01009981f9, "
"fc2://index/1, replay://glob/beam*.npz) [%default]")
p.add_option("-s", "--save", default=None,
help="save images accordint to strftime() "
"format string (e.g. 'beam_%Y%m%d%H%M%S.npz'), "
"compressed npz format [%default]")
p.add_option("-l", "--log",
help="log output file [stderr]")
p.add_option("-d", "--debug", default="info",
help="log level (debug, info, warn, error, "
"critical, fatal) [%default]")
opts, args = p.parse_args()
logging.basicConfig(filename=opts.log,
level=getattr(logging, opts.debug.upper()),
format='%(asctime)s %(levelname)s %(message)s')
scheme, loc, path, query, frag = urlparse.urlsplit(opts.camera)
if scheme == "opencv":
from .opencv_capture import OpenCVCapture
if loc == "index":
cam = OpenCVCapture(int(path[1:]))
elif scheme == "none":
from capture import DummyCapture
cam = DummyCapture()
elif scheme == "any":
try:
from .opencv_capture import OpenCVCapture
cam = OpenCVCapture()
except Exception, e:
logging.debug("opencv error: %s", e)
from capture import DummyCapture
cam = DummyCapture()
logging.debug("running with capture device: %s", cam)
if opts.save:
cam.save_format = opts.save
proc = Process(capture=cam)
bull = Bullseye(process=proc)
bull.configure_traits()
bull.close()
if __name__ == "__main__":
main()
是的你是對的,這是一個Beamprofiler代碼的一部分。問題是,我並不是真的想要從我的相機獲取實時視頻,但我希望上面的代碼訪問相機,以便真正的Beamprofiler代碼可以評估從相機獲取的信息。 – Jennan
你有鏈接到源代碼? –
當然,你可以在這裏找到代碼:https://github.com/jordens/bullseye 我一直無法讓我的相機使用它。我使用的是隻有CCD芯片的Playstation相機,所以沒有鏡頭等。我可以用simplecv或opencv輕鬆訪問相機,但我無法弄清楚如何將它與bullseye代碼結合起來。 – Jennan