IP camera with OpenCv in Java -



IP camera with OpenCv in Java -

i trying , display video stream ip camera. found sample code here:http://answers.opencv.org/question/24012/reading-video-stream-from-ip-camera-in-opencv-java/

but not working me. code works when utilize internal webcam, when switch photographic camera ip, not work. have no thought why. can please help me? here code:

import java.awt.borderlayout; import java.awt.image; import java.awt.image.bufferedimage; import java.awt.image.databufferbyte; import java.io.file; import java.io.ioexception; import javax.imageio.imageio; import javax.swing.imageicon; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; import org.opencv.core.core; import org.opencv.core.cvtype; import org.opencv.core.mat; import org.opencv.highgui.videocapture; import org.opencv.imgproc.imgproc; public class opencvtest { public opencvtest() { // todo auto-generated constructor stub } /** * @param args * @throws ioexception */ public static void main(string[] args) throws ioexception { system.loadlibrary(core.native_library_name); //videocapture photographic camera = new videocapture("http://192.168.0.7/image.jpg"); videocapture photographic camera = new videocapture(0); if (camera.isopened()) { system.out.println("video captured"); } else { system.out.println(""); } videocamera cam = new videocamera(camera); jframe frame = new jframe(); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.add(cam); frame.setsize(800,800); frame.setvisible(true); while(camera.isopened()) { cam.repaint(); } } } import java.awt.graphics; import java.awt.point; import java.awt.image.bufferedimage; import java.awt.image.databufferbyte; import java.util.arraylist; import javax.swing.jframe; import javax.swing.jpanel; import org.opencv.core.core; import org.opencv.core.mat; import org.opencv.core.matofrect; import org.opencv.core.rect; import org.opencv.core.scalar; import org.opencv.highgui.videocapture; import org.opencv.imgproc.imgproc; import org.opencv.objdetect.cascadeclassifier; import org.opencv.core.*; @suppresswarnings("serial") public class videocamera extends jpanel { videocapture camera; public videocamera(videocapture cam) { photographic camera = cam; } /** * @param args */ public static void main(string[] args) { // todo auto-generated method stub } public bufferedimage mat2bufferedimage(mat m) { int type = bufferedimage.type_byte_gray; if (m.channels() > 1) { type = bufferedimage.type_3byte_bgr; } int buffersize = m.channels() * m.cols() * m.rows(); byte[] b = new byte[buffersize]; m.get(0, 0, b); // pixels bufferedimage img = new bufferedimage(m.cols(), m.rows(), type); final byte[] targetpixels = ((databufferbyte) img.getraster().getdatabuffer()).getdata(); system.arraycopy(b, 0, targetpixels, 0, b.length); homecoming img; } public void paintcomponent(graphics g) { super.paintcomponent(g); mat mat = new mat(); if( camera.read(mat)) { system.out.print("image"); } bufferedimage image = mat2bufferedimage(mat); //mat grayness = turngray(mat); //matofrect objects = new matofrect(); //cascadeclassifier cas = new cascadeclassifier(); //cas.detectmultiscale(gray,objects); //mat thresh = threash( gray); //bufferedimage image = mat2bufferedimage(thresh); g.drawimage(image,10,10,image.getwidth(),image.getheight(), null); } public mat turngray( mat img) { mat mat1 = new mat(); imgproc.cvtcolor(img, mat1, imgproc.color_rgb2gray); homecoming mat1; } public mat threash(mat img) { mat threshed = new mat(); int sensitivity_value = 100; imgproc.threshold(img, threshed, sensitivity_value,255,imgproc.thresh_binary); homecoming threshed; } }

thank help. able utilize said find proper ip address (http://192.168.0.6/video.cgi) (yes, know 7 became 6, different camera) video in browser. still next error.

exception in thread "awt-eventqueue-0" java.lang.illegalargumentexception: width (0) , height (0) must > 0 @ java.awt.image.samplemodel.<init>(unknown source) @ java.awt.image.componentsamplemodel.<init>(unknown source) @ java.awt.image.pixelinterleavedsamplemodel.<init>(unknown source) @ java.awt.image.raster.createinterleavedraster(unknown source) @ java.awt.image.raster.createinterleavedraster(unknown source) @ java.awt.image.raster.createinterleavedraster(unknown source) @ java.awt.image.componentcolormodel.createcompatiblewritableraster(unknown source) @ java.awt.image.bufferedimage.<init>(unknown source) @ videocamera.mat2bufferedimage(videocamera.java:54) @ videocamera.paintcomponent(videocamera.java:74) @ javax.swing.jcomponent.paint(unknown source) @ javax.swing.jcomponent.paintchildren(unknown source) @ javax.swing.jcomponent.paint(unknown source) @ javax.swing.jcomponent.paintchildren(unknown source) @ javax.swing.jcomponent.paint(unknown source) @ javax.swing.jlayeredpane.paint(unknown source) @ javax.swing.jcomponent.paintchildren(unknown source) @ javax.swing.jcomponent.painttooffscreen(unknown source) @ javax.swing.bufferstrategypaintmanager.paint(unknown source) @ javax.swing.repaintmanager.paint(unknown source) @ javax.swing.jcomponent.paint(unknown source) @ java.awt.graphicscallback$paintcallback.run(unknown source) @ sun.awt.sungraphicscallback.runonecomponent(unknown source) @ sun.awt.sungraphicscallback.runcomponents(unknown source) @ java.awt.container.paint(unknown source) @ java.awt.window.paint(unknown source) @ javax.swing.repaintmanager$3.run(unknown source) @ javax.swing.repaintmanager$3.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ javax.swing.repaintmanager.paintdirtyregions(unknown source) @ javax.swing.repaintmanager.paintdirtyregions(unknown source) @ javax.swing.repaintmanager.prepaintdirtyregions(unknown source) @ javax.swing.repaintmanager.access$1100(unknown source) @ javax.swing.repaintmanager$processingrunnable.run(unknown source) @ java.awt.event.invocationevent.dispatch(unknown source) @ java.awt.eventqueue.dispatcheventimpl(unknown source) @ java.awt.eventqueue.access$200(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$1.dointersectionprivilege(unknown source) @ java.awt.eventqueue.dispatchevent(unknown source) @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source) @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.run(unknown source)

i think because videocapture not grabbing frame correctly.

this photographic camera trying utilize http://www.trendnet.com/products/proddetail.asp?prod=150_tv-ip100w-n

.jpg refers single image file, while .mjpg gives access video stream. it's of import define ip , port used connect.

depending on device have , settings defined in web interface of camera, url going different:

videocapture photographic camera = new videocapture("http://192.168.0.7:8080/?dummy=param.mjpg"); videocapture photographic camera = new videocapture("http://192.168.0.7:8080/mjpeg.cgi"); videocapture photographic camera = new videocapture("http://192.168.0.7:8080/mjpg/mjpeg.cgi"); videocapture photographic camera = new videocapture("http://192.168.0.7:8080/video.mjpeg"); videocapture photographic camera = new videocapture("http://192.168.0.7:8080/video.cgi?.mjpg");

when access valid url via browser should display video stream. 1 time find address works, pass videocapture constructor. in examples showed how access stream via http, rtsp protocol supported.

java opencv camera ip jpanel

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -