我正在使用Python 2.7和OpenCV 2.4.9.
我需要捕获正在向用户显示的当前帧并将其作为Python中的cv :: Mat对象加载.
你们知道一种快速的递归方法吗?
我需要像下面的示例中所做的那样,以递归方式从网络摄像头捕获Mat帧:
import cv2
cap = cv2.VideoCapture(0)
while(cap.isOpened()):
ret, frame = cap.read()
cv2.imshow('WindowName', frame)
if cv2.waitKey(25) & 0xFF == ord('q'):
cap.release()
cv2.destroyAllWindows()
break
Run Code Online (Sandbox Code Playgroud)
在该示例中,它使用VideoCapture类来处理来自网络摄像头的捕获图像.
使用VideoCapture.read(),新帧始终被呈现并存储到Mat对象中.
我可以将"printscreens流"加载到VideoCapture对象中吗?我是否可以使用Python中的OpenCV创建计算机屏幕的流媒体,而无需每秒保存和删除大量.bmp文件?
我需要这些帧是Mat对象或NumPy数组,所以我可以实时执行一些计算机视觉例程.
我在R中有以下两个函数:
exs.time.start<-function(){
exs.time<<-proc.time()[3]
return(invisible(NULL))
}
exs.time.stop<-function(restartTimer=TRUE){
if(exists('exs.time')==FALSE){
stop("ERROR: exs.time was not found! Start timer with ex.time.start")
}
returnValue=proc.time()[3]-exs.time
if(restartTimer==TRUE){
exs.time<<-proc.time()[3]
}
message(paste0("INFO: Elapsed time ",returnValue, " seconds!"))
return(invisible(returnValue))
}
Run Code Online (Sandbox Code Playgroud)
该函数使用我调用函数时的CPU时间exs.time.start创建一个全局变量(exs.time).
函数exs.time.stop访问全局变量并返回执行exs.time.start和之间的时间exs.time.stop.
我的目标是用这两个函数创建一个包IR.如何将全局变量(exs.time)定义为对用户不可见的变量,因此他无法在R全局环境中看到此变量?
我可以将此变量定义为R包环境/命名空间内的"隐藏"全局变量吗?
这是我第一次使用包,所以我不确切知道如何在定义包时很好地使用命名空间文件.我正在使用R Studio和Roxygen2创建我的包.
任何帮助或建议都会很棒!