nakkaya / vision

OpenCV wrapper for Clojure
http://nakkaya.com/vision.html
132 stars 17 forks source link

(view) crashes java #3

Closed stathissideris closed 13 years ago

stathissideris commented 13 years ago

This is on Lion MacOSX with openCV 2.2.0 (installed using brew install opencv) and [vision "1.0.0-SNAPSHOT"] in my leiningen project.clj.

When I try (view :raw frame), Java crashes with

    OpenCV Error: Assertion failed (code) in imencode, file /tmp/homebrew-opencv-2.2-IdC1/OpenCV-2.2.0/modules/highgui/src/loadsave.cpp, line 424

From the code, it seems that this is because the (delay) in (ipl-image) is being force to evaluate and the (encode-image) fails, I looked at the opencv code with this and it seems that the imencode function fails to write the encoded image to the buffer. See below:

http://www.oschina.net/code/explore/OpenCV-2.2.0/modules/highgui/src/loadsave.cpp

The actual code:


(ns film-tempo.vision
  (:use vision.core))

;;"/Users/sideris/Movies/some.like.it.hot.avi"
;;"/Users/sideris/Downloads/StayingInLane_MPEG4.avi"

(let [filename "/Users/sideris/Downloads/StayingInLane_MPEG4.avi"
      capture (capture-from-file filename)
      frame-count (get-capture-property capture :frame-count)
      width (get-capture-property capture :frame-width)
      height (get-capture-property capture :frame-height)
      fps (get-capture-property capture :fps)]

  (print "frame count: " frame-count "\n"
         "w: " width "\n"
         "h: " height "\n"
         "fps: " fps "\n")

  (dotimes [_ 1]
    (let [frame (query-frame capture)]
      ;;(print (.getHeight (force (:buffered-image frame))))
      (view :raw frame)
      (Thread/sleep 10)))
  (release capture)
  (print "Done"))
nakkaya commented 13 years ago

I don't have lion installed on any of my machines, I have rerun the code from that post on snow both using 32 bit opencv 2.2 (homebrew) and 64 bit opencv 2.2 (ports), no crashes works fine . Can you pinpoint the problem and send me a patch?

Nurullah Akkaya http://nakkaya.com

On Sun, Aug 21, 2011 at 4:52 PM, stathissideris reply@reply.github.com wrote:

This is on Lion MacOSX with openCV 2.2.0 (installed using brew install opencv) and [vision "1.0.0-SNAPSHOT"] in my leiningen project.clj.

When I try (view :raw frame), Java crashes with

   OpenCV Error: Assertion failed (code) in imencode, file /tmp/homebrew-opencv-2.2-IdC1/OpenCV-2.2.0/modules/highgui/src/loadsave.cpp, line 424

From the code, it seems that this is because the (delay) in (ipl-image) is being force to evaluate and the (encode-image) fails, I looked at the opencv code with this and it seems that the imencode function fails to write the encoded image to the buffer. See below:

http://www.oschina.net/code/explore/OpenCV-2.2.0/modules/highgui/src/loadsave.cpp

The actual code:


(ns film-tempo.vision
 (:use vision.core))

;;"/Users/sideris/Movies/some.like.it.hot.avi"
;;"/Users/sideris/Downloads/StayingInLane_MPEG4.avi"

(let [filename "/Users/sideris/Downloads/StayingInLane_MPEG4.avi"
     capture (capture-from-file filename)
     frame-count (get-capture-property capture :frame-count)
     width (get-capture-property capture :frame-width)
     height (get-capture-property capture :frame-height)
     fps (get-capture-property capture :fps)]

 (print "frame count: " frame-count "\n"
        "w: " width "\n"
        "h: " height "\n"
        "fps: " fps "\n")

 (dotimes [_ 1]
   (let [frame (query-frame capture)]
     ;;(print (.getHeight (force (:buffered-image frame))))
     (view :raw frame)
     (Thread/sleep 10)))
 (release capture)
 (print "Done"))

Reply to this email directly or view it on GitHub: https://github.com/nakkaya/vision/issues/3

stathissideris commented 13 years ago

Sure, I can give it a try. Any ideas about where to look first? Do you think it might be something in the way it's called via JNA?

nakkaya commented 13 years ago

Can you try putting together a quick c program that does the same as the clojure code by calling the functions in the vision lib, that way we know that the problem is on the native side if that too crashes or on the jvm side if it works.

Nurullah Akkaya http://nakkaya.com

On Mon, Aug 22, 2011 at 5:32 PM, stathissideris reply@reply.github.com wrote:

Sure, I can give a try. Any ideas about where to look first? Do you think it might be something in the way it's called via JNA?

Reply to this email directly or view it on GitHub: https://github.com/nakkaya/vision/issues/3#issuecomment-1870615

stathissideris commented 13 years ago

ok, I've written a small C program that does exactly that:


#include <stdio.h>
#include "vision.c"

char* filename = "/Users/sideris/Downloads/StayingInLane_MPEG4.avi";

int main(int argc, char* argv[]) {
  void* ptr = capture_from_file(filename);

  double frame_count = get_capture_property(ptr, 8);
  printf("Frame count: %f\n", frame_count);

  void* img = query_frame(ptr);
  encode_image(img, 2, 80);

  return 0;
}

The result is the same, implying that the problem is not clojure-related:

Frame count: 0.000000
OpenCV Error: Assertion failed (code) in imencode, file /tmp/homebrew-opencv-2.2-IdC1/OpenCV-2.2.0/modules/highgui/src/loadsave.cpp, line 424
terminate called throwing an exceptionAbort trap: 6

It could be that the brew install of openCV is broken on Lion, but it's weird that it's failing like that. Any ideas about what to try next?

stathissideris commented 13 years ago

A small update: I tried calling cvNamedWindow() and then using cvShowImage() to show the result of query_frame() and it still doesn't work. The result of the query_frame() call is in fact a null pointer, which probably shows that the problem is with openCV on Lion. I know it's most likely not related to vision, but any advice about how to proceed would be greatly appreciated!

stathissideris commented 13 years ago

OK, I've managed to solve this with the combination of the following: I installed ffmpeg before OpenCV (I was under the impression that it was an explicit dependency, but no). The brew recipe of ffmpeg on Lion is currently broken, so I had to do:

sudo brew install --use-clang --HEAD ffmpeg

I then downloaded the current stable OpenCV from the website (2.3.1) and built it with:

bunzip2 OpenCV-2.3.1.tar.bz2
tar xvf OpenCV-2.3.1.tar
cd OpenCV-2.3.1
sudo cmake -G "Unix Makefiles" .
sudo make -j8
sudo make install

Video at last!! :-)