Hello there,
I am trying to use the c# API to connect to multiple cameras but I am facing some issues.
The following line would always return false and ofcourse when removing the second parameter, the function does not know which camera to use so it always returns the image from the first camera.
RDK.Cam2DSnapshot(tempPath, cam_items[i].ItemId)
I was wondering if I am using this correctly or I overlooked something here?
I am trying to use the c# API to connect to multiple cameras but I am facing some issues.
The following line would always return false and ofcourse when removing the second parameter, the function does not know which camera to use so it always returns the image from the first camera.
RDK.Cam2DSnapshot(tempPath, cam_items[i].ItemId)
I was wondering if I am using this correctly or I overlooked something here?
Code:
using OpenCvSharp;
using RoboDk.API;
using RoboDk.API.Model;
using Mat = OpenCvSharp.Mat;
namespace RoboDKExample
{
class Program
{
static void Main()
{
var RDK = new RoboDK();
string[] CAM_NAMES = { "Camera 1", "Camera 2" };
string CAM_PARAMS = "SIZE=640x480";
string[] WINDOW_NAMES = { "My Camera Feed 1", "My Camera Feed 2" };
IItem[] cam_items = { null, null };
for (int i = 0; i < CAM_NAMES.Length; i++)
{
cam_items[i] = RDK.GetItemByName(CAM_NAMES[i], ItemType.Any);
cam_items[i].SetParam("Open", "1");
}
// Create a live feed
while (true)
{
bool isAnyCameraOpen = false;
for (int i = 0; i < cam_items.Length; i++)
{
if (cam_items[i].SetParam("isOpen") == "1")
{
isAnyCameraOpen = true;
// Method 2: Get the camera image, from disk
string tempPath = Path.GetTempPath() + $"/Camera{i}.png";
Mat img_png = null;
if (RDK.Cam2DSnapshot(tempPath, cam_items[i].ItemId))
{
img_png = Cv2.ImRead(tempPath);
}
// Show it to the world!
Cv2.ImShow(WINDOW_NAMES[i], img_png);
}
}
if (!isAnyCameraOpen)
{
break;
}
int key = Cv2.WaitKey(1);
if (key == 27)
{
break; // User pressed ESC, exit
}
}
// Close the preview and the camera. Ensure you call cam_item.setParam("Open", "1") before reusing a camera!
for (int i = 0; i < cam_items.Length; i++)
{
RDK.Cam2DClose();
}
Cv2.DestroyAllWindows();
}
}
}