View Single Post
  #1   Spotlight this post!  
Unread 03-02-2016, 21:24
rpappa rpappa is offline
Registered User
FRC #0340
 
Join Date: Feb 2016
Location: Rochester
Posts: 9
rpappa is an unknown quantity at this point
Get image from USBCamera into an OpenCV Mat

I've successfully put opencv on the Roborio and have tested to make sure it works (will do a write up on that soon™). However, I have run into the roadblock of the fact that the USBCamera class has no apparent way to get a straight up Java Image or BufferedImage or something easy to pass to Mat.put().

Here's my code which crashes:
Code:
        USBCamera cam = new USBCamera("cam0");
        cam.openCamera();
    	cam.startCapture();
    	ByteBuffer buf = ByteBuffer.allocate(76800);
    	cam.getImageData(buf);
    	matOriginal = new Mat();
    	matOriginal.put(0, 0, buf.array());
    	Imgcodecs.imwrite("output.png", matOriginal);
The line that crashes it is probably
Code:
ByteBuffer buf = ByteBuffer.allocate(76800);
But I'm not sure if that matters as I don't believe I am approaching this problem the right way. Any suggestions?
Reply With Quote