I tried to make access my webcam with opencv in java but it gives me this error
[ INFO:0@0.054] global videoio_registry.cpp:232 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(9, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[ INFO:0@0.055] global backend_plugin.cpp:383 cv::impl::getPluginCandidates Found 3 plugin(s) for FFMPEG
[ INFO:0@0.056] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\opencv\build\java\x64\opencv_videoio_ffmpeg470_64d.dll => FAILED
[ INFO:0@0.057] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_ffmpeg470_64d.dll => FAILED
[ INFO:0@0.059] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_ffmpeg470_64.dll => FAILED
[ INFO:0@0.059] global backend_plugin.cpp:383 cv::impl::getPluginCandidates Found 2 plugin(s) for GSTREAMER
[ INFO:0@0.060] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\opencv\build\java\x64\opencv_videoio_gstreamer470_64d.dll => FAILED
[ INFO:0@0.061] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_gstreamer470_64d.dll => FAILED
[ INFO:0@0.061] global backend_plugin.cpp:383 cv::impl::getPluginCandidates Found 2 plugin(s) for INTEL_MFX
[ INFO:0@0.062] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\opencv\build\java\x64\opencv_videoio_intel_mfx470_64d.dll => FAILED
[ INFO:0@0.063] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_intel_mfx470_64d.dll => FAILED
[ INFO:0@0.116] global cap_msmf.cpp:1027 CvCapture_MSMF::configureHW MSMF: Using D3D11 video acceleration on GPU device: Intel(R) UHD Graphics 620
OpenCV(4.7.0-dev) Error: Bad argument (CAP_IMAGES: can't find starting number (in the name of file): rtsp://172.30.75.213:8080/video) in cv::icvExtractPattern, file C:\GHA-OCV-2\_work\ci-gha-workflow\ci-gha-workflow\opencv\modules\videoio\src\cap_images.cpp, line 253
[ERROR:0@1.865] global cap.cpp:166 cv::VideoCapture::open VIDEOIO(CV_IMAGES): raised OpenCV exception:
OpenCV(4.7.0-dev) C:\GHA-OCV-2\_work\ci-gha-workflow\ci-gha-workflow\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): rtsp://172.30.75.213:8080/video in function 'cv::icvExtractPattern'
Here is the code that I worte:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.io.ByteArrayInputStream;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.videoio.VideoCapture;
import org.opencv.imgcodecs.Imgcodecs;
public class capture extends Application {
// Make the imageView accessible to all the threads
volatile ImageView imageView = new ImageView();
class CameraThread extends Thread {
VideoCapture capture = new VideoCapture();
@Override
public void run() {
capture.open("http://172.30.75.213:8080/video");
Mat frame = new Mat();
while (true) {
if (capture.read(frame)) {
// Convert the OpenCV frame to a JavaFX image
Image image = convertMatToImage(frame);
// Display the image in the ImageView
imageView.setImage(image);
}
}
}
private Image convertMatToImage(Mat mat) {
// Convert the Mat object to a byte array
MatOfByte buffer = new MatOfByte();
Imgcodecs.imencode(".png", mat, buffer);
byte[] imageData = buffer.toArray();
// Convert the byte array to a JavaFX image
ByteArrayInputStream inputStream = new ByteArrayInputStream(imageData);
return new Image(inputStream);
}
}
@Override
public void start(Stage stage) {
// Start the video capture thread
Thread videoCaptureThread = new CameraThread();
videoCaptureThread.setDaemon(true);
videoCaptureThread.start();
stage.setTitle("Video Capture");
// Create a JavaFX VBox to hold the ImageView
VBox vbox = new VBox();
vbox.getChildren().add(imageView);
// Create a JavaFX Scene with the VBox and set it on the Stage
Scene scene = new Scene(vbox, 640, 480);
stage.setScene(scene);
stage.show();
}
public static void main(String args[]) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
launch(args);
}
}
I tried running the same webcam on python using opencv and it seems to work fine but for some reason it does not work in java. Can you help me understand this because the error message makes no sense
I was expecting to access mobile camera through ipcamera in java using opencv but it did not work