问题描述
我正在尝试从连接到Raspberry Pi的网络摄像头捕获node.js中的图像.捕获可以很好地工作,但是现在当我要传输图像时,帧率和滞后会出现一些严重的问题.
现在我的第一个想法是将RGB图像转换为8位灰度,这应该将性能提高3倍(我希望..).
我正在为此使用node.js和opencv-node.现在,您可以在此处看到一些代码片段:
var startT = new Date().getTime();
var capture = new cv.VideoCapture();
var frame = new cv.Mat;
var grey = new cv.Mat;
var imgPath = __dirname + "/ramdisk/";
var frame_number = 0;
capture.open(0);
if (!capture.isOpened())
{
console.log("aCapLive could not open capture!");
return;
}
function ImgCap()
{
var elapsed = (new Date().getTime() - startT) / 1000;
capture.read(frame);
cv.imwrite(imgPath+".bmp", frame);
id = setImmediate(ImgCap);
}
ImgCap();
我试图使用类似的东西
cv.cvtColor(frame, grey, "CV_BGR2GRAY");
在读取图像之后,但是我只得到一些TypeError,说参数2必须是整数...我目前不知道该怎么办.我提到了 http://docs.opencv.org/doc/tutorials/introduction/load_save_image/load_save_image.html#explanation ,用于将rgb转换为灰度图像.
此外,我仍然不确定这是否会给MIT提供24位灰度图像而不是8位.
感谢您的任何帮助! :)
使用CV_BGR2GRAY代替"CV_BGR2GRAY".
前者是整数常数,后者是char *
并且,不用担心,这将是8位灰度.
I'm trying to capture images within node.js from a webcam connected to a Raspberry Pi. Capturing works fine, but now when I want to transmit the images I have some serious problems with framerate and lags.
Now my first idea was to convert the RGB images to 8bit grayscale, that should increase the performance by factor 3 (i hope..).
I'm using node.js and opencv-node for this. Here you can see some code snippet for the moment:
var startT = new Date().getTime();
var capture = new cv.VideoCapture();
var frame = new cv.Mat;
var grey = new cv.Mat;
var imgPath = __dirname + "/ramdisk/";
var frame_number = 0;
capture.open(0);
if (!capture.isOpened())
{
console.log("aCapLive could not open capture!");
return;
}
function ImgCap()
{
var elapsed = (new Date().getTime() - startT) / 1000;
capture.read(frame);
cv.imwrite(imgPath+".bmp", frame);
id = setImmediate(ImgCap);
}
ImgCap();
I tried to use something like
cv.cvtColor(frame, grey, "CV_BGR2GRAY");
after reading the image but i only get some TypeError saying that argument 2 has to be an integer... I dont know what to do at the moment. I referred to http://docs.opencv.org/doc/tutorials/introduction/load_save_image/load_save_image.html#explanation for converting a rgb to a grayscale image.
Beside I'm still not sure if this just gives mit a 24bit grayscale image instead of 8bit..?!
Thanks for any help in advance! :)
use CV_BGR2GRAY instead of "CV_BGR2GRAY".
the former is an integral constant, the latter a char*
and, no fear, that will be 8bit grayscale.
这篇关于使用node.js中的opencv-node将24位RGB图像转换为8位灰度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!