我想使用C ++,OpenCV 2.4.11,Windows 8.1和Qt Creator 3.4.2列出所有连接的网络摄像头(USB网络摄像头和内部网络摄像头)。对我而言,通过以下方式获取可访问的网络摄像头数量就足够了:
VideoCapture videoCapture(0); // Will access my internal laptop webcam.
VideoCapture videoCapture(1); // Will access the first connected usb webcam.
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
// Following procedure detects, how many webcams are accessible from 0 on upwards.
numberOfDevices = 0;
bool noError = true;
while (noError)
{
try
{
// Check if camera is available.
VideoCapture videoCapture(numberOfDevices); // Will crash if not available, hence try/catch.
// ...
}
catch (...)
{
noError = false;
}
// If above …Run Code Online (Sandbox Code Playgroud) 我正在使用 R 中预安装的 RScript 包。
我想从命令提示符调用以下名为“test.R”的 R 脚本:
a <- c("a", "b", "c")
a
args <- commandArgs(TRUE)
b <- as.vector(args[1])
b
Run Code Online (Sandbox Code Playgroud)
我使用以下命令:
RScript test.R c("d","e","f")
Run Code Online (Sandbox Code Playgroud)
这将创建以下输出:
[1] "a" "b" "c"
[1] "c(d,e,f)"
Run Code Online (Sandbox Code Playgroud)
如您所见,第一个(也是唯一的)参数被解释为字符串,然后转换为一维向量。如何将参数解释为向量?
旁注:当然,向量的项可以分为多个参数,但在我的最终项目中,将有多个向量参数。实现这样的事情是我最后的手段:
RScript test.R "d" "e" "f" END_OF_VECTOR_1 "g" "h" "i" END_OF_VECTOR_2 "j" "k" "l"
Run Code Online (Sandbox Code Playgroud)