Is openCv compatible with multiple Cameras???
This code is workable. method 1 returns colored frame while method 2 returns binary frames.Although i initialized two cameras , I am still thinking that this program does not run with two cameras.It is using only one camera. Am i right ?? or wrong??
@FXML
public void mcamera(ActionEvent ee){
new Thread(() -> method1()).start();
new Thread(() -> method2()).start();
}
public void method1() {
VideoCapture camera1 = new VideoCapture("/home/chinthaka/Downloads/wow/giphy.mp4");
if (!camera1.isOpened()) {
System.out.println("Error! Camera can't be opened!");
return;
}
Mat frame = new Mat();
while (true) {
if (camera1.read(frame)) {
System.out.println("Frame Obtained");
System.out.println("Captured Frame Width " +
frame.width() + " Height " + frame.height());
Imgcodecs.imwrite("camera.jpg", frame);
System.out.println("OK");
while (camera1.read(frame)) {
System.out.println("Frame Obtained");
System.out.println("Captured Frame Width " +
frame.width() + " Height " + frame.height());
Imgcodecs.imwrite("camera.jpg", frame);
System.out.println("OK");
bufferedImage = matToBufferedImage(frame);
showWindow(bufferedImage);
}
camera1.release();
break;
}
}
}
public void method2() {
VideoCapture camera2 = new VideoCapture("/home/chinthaka/Downloads/wow/cinnamon.mp4");
if (!camera2.isOpened()) {
System.out.println("Error! Camera can't be opened!");
return;
}
Mat frame = new Mat();
while (true) {
if (camera2.read(frame)) {
System.out.println("Frame Obtained");
System.out.println("Captured Frame Width " +
frame.width() + " Height " + frame.height());
Imgcodecs.imwrite("camera.jpg", frame);
System.out.println("OK");
while (camera2.read(frame)) {
System.out.println("Frame Obtained");
System.out.println("Captured Frame Width " +
frame.width() + " Height " + frame.height());
Imgcodecs.imwrite("camera.jpg", frame);
System.out.println("OK");
//convert original color frame into gray scale frame.
Imgproc.cvtColor(frame, frame, Imgproc.COLOR_BGR2GRAY);
//convert gray scale frame to binary frame.
threshold(frame, frame, 100, 255, THRESH_BINARY);
bufferedImage = matToBufferedImage(frame);
showWindow(bufferedImage);
}
camera2.release();
break;
}
}
}
Thank you @berak for your comment. but this post---your comment-----you have done something like above.Isn't it??. post. Could you please tell me how to integrate multiple cameras???