I am trying to take images from an IP cam (sony snc p1) for motion detection using opencv java. The stream is in mjpeg format and I am using opencv's VideoCapture to try to retrieve an image. I can grab an image from a video file using videocapture but when I try to open the camera doesn't work. I can view the stream on vlc but that ip address doesn't work on opencv. This is the code that I use:
while (true){
VideoCapture camera1=newVideoCapture("http://192.168.0.101/mjpeg");
if (!camera1.isOpened())
System.out.println("Cannot open file");
}
What version are you using? In openCV 2.4 this is a known bug. (fixed in later versions)
You can olso try adding a dummy param, at the end, something like camera1.open("http://192.168.0.101/?dummy=video.mjpg");
because opencv VideoCapture expects an extension at the end of the file name.
Related
I'm trying to access a RTSP video stream from an IP camera using OpenCV and Java. I can access the stream using VLC player with the following format: rtsp://192.168.1.10:554/rtsp_live0 but when I try to use OpenCV the video stream seems to always be closed.
The code I'm using... (simplified)
VideoCapture capture = new VideoCapture();
capture.open("rtsp://192.168.1.10:554/rtsp_live0");
while(!capture.isOpened())
System.out.print("Not opened :( \r");
I have a Mustcam H806P and found the stream URI from this website: http://www.ispyconnect.com/man.aspx?n=ipcamera
What am I doing wrong?
I'm reporting Alexander Smorkalov answer on answers.opencv.org
OpenCV uses ffmpeg library for video I/O. Try to get video stream with console ffmpeg tool. The address must be the same.
See also here OpenCV - how to capture rtsp video stream
How do you capture an image through the user's webcam and save it to file in the default image folder as well as into a database? I'm using JSP and Java in my web app.
It is very easy with OpenCV & JavaCV libraries , and here is the code snippet to capture image from webcam & save to disc.
IplImage img; // Image format provided with JavaCV APIs
OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0); // Camera Device ID (0 for built in , 1 for external etc)
grabber.start();
img = grabber.grab();
String imageName="images_name.jpg";
cvSaveImage(imageName, img);
Take a look at this website :
http://osama-oransa.blogspot.com.br/2012/06/accessing-webcam-within-jsp.html
Essentially:
Use a Jquery Webcam Plugin: http://www.xarg.org/project/jquery-webcam-plugin/%20
Use AJAX to send the data to Java.
Get the byte[] and save it.
I am trying to grab images from a IP cam for image processing using opencv java. The stream is in mjpg format and I am using opencv's VideoCapture to try to retrieve a image. I can grab a image from my webcam using videocapture but when I try to open a IP cam it will never open. I can also view test stream here. I tried searching around for an answer but none pf them seem to work. I am on windows 7 with opencv 2.4.9. This is the code I am trying to get to work.
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
VideoCapture vc = new VideoCapture();
vc.open("http://construction.sfhs.com/mjpg/video.mjpg");
Thread.sleep(100);
while(true) {
System.out.println(vc.isOpened());
Thread.sleep(100);
}
It just outputs false
I had the same problem.
Try adding "opencv_ffmpeg249.dll" to the folder of your program.
Hi I am working on image processing where I need to convert all types
of videos into series of frames.
I already tried with JCodec which worked only with .mp4 type videos.
Below code shows what I did before to grab frames from video,
try {
int frameNumber = 0;
BufferedImage frame = null;
for(int i=0;i<100;i++)
{
frameNumber = i;
//video from which frames can be retrieved, declare frame number,
//returns numbered frame from video
frame = FrameGrab.getFrame(new File("D:\\Traffic.mp4\\"), frameNumber);
//write frame as image declare image format and file path where image
//is to be write
ImageIO.write(frame, "png", new File("D:\\Frames2\\frame_"+frameNumber+".png\\"));
}
System.out.println("Finished");
} catch (Exception e) {
e.printStackTrace();
}
Here in above code I am trying to read Traffic.mp4 video and getting
first 100 frames. This code is working fine for all types of .mp4
videos, but as I tried with .flv, .avi type of video it is giving
me NullPointer exception.
So is there any other Java API I can try which accepts all type of
videos.
You can try using xuggler, a wrapper of FFMpeg for java. FFMpeg has support for processing individual frames so I guess Xuggler won't be far from it, the demo DecodeAndCaptureFrames.java seems to be doing what you want.
Take a look at Marvin Framework. It uses JavaCV as an interface to cameras and media files. Check this Example showing how to get each video frame from a WMV file for image processing purpose.
In the JavaCV group there is a Discussion about supported file formats.
I want to take a snapshot with my webcam using java and save it to a jpg file. What are the steps needed to do so? A tutorial would be greatly appreciated.
Greetings,
Burkhard
the JMF (Java Media Framework) is a good starting point. However, I did not succeed with it.
I finally found the solution here.
The important part being:
Buffer buf = frameGrabber.grabFrame();
// Convert frame to an buffered image so it can be processed and saved
Image img = (new BufferToImage((VideoFormat) buf.getFormat()).createImage(buf));
buffImg = new BufferedImage(img.getWidth(this), img.getHeight(this), BufferedImage.TYPE_INT_RGB);
//TODO saving the buffImg
what you are looking for might be the Java Media Framework (JMF).
See the Sun Tutorial. I hope that helps.
I prefer using JMyron instead of JMF. JMyron is easy to use for accessing webcam. To save the captured image you just need to save the BufferedImage using ImageIO.write(); this blog post How To Use Webcam Using Javais usefull to start using JMyron.
Try webcam-capture project.
This code will take a snapshot from webcam (embedded, connected to USB or IP camera) and save it into JPG file:
Webcam webcam = Webcam.getDefault();
webcam.open()
BufferedImage image = webcam.getImage();
ImageIO.write(image, "JPG", new File("test.jpg"));