Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+37 votes

Me and my partner are trying to get the video to display after it's been selected but we are getting bunch of errors or we get nothing on the screen. Could someone help what actually makes the video to be displayed on the screen?

asked in CSC285_Fall2018 by (1 point)

You may need to be more specific about the error messages that you are getting?


We have actually deleted what was causing the error, we realized it was wrong. Is there anything on the tutorial or an example that I can look at that you know of, that has to do with getting the video to display aka getting the first frame(we are on the second part of the lab)?

3 Answers

+18 votes
Best answer

In some ways, there is no such thing as displaying the "video" -- you're really trying to just display one frame of the video.

This involves several steps:

  1. Opening the video vidCap.open("/file/path/etc.mp4");
  2. reading in one frame (still image) from it:
    Mat frame = new Mat()
  3. Converting that frame from an OpenCV Mat object into a JavaFX Image object. (There are at least two ways of doing that:
    a) a simpler method given in the tutorial, involving MatOfByte, encoding into a png format, and feeding an inputstream that reads an array of those bytes into the new Image(...) constructor.
    b) a more complex method that was given in the Utils class in the GitHub code that the tutorial author provided at the bottom of the page.
  4. Updating the JavaFX ImageView widget to show the newly created image. myImageView.setImage(imageToDisplay).

For Part 1 of the lab, this 4-step process is being done repeatedly (ever 33 ms) by a separate Thread of execution.

For Part 2 of the lab, you should first try to just display the very first frame of the video (when they click browse), and then after that is working, you want to do these same steps to display the appropriate frame whenever they change the slider.

answered by (508 points)
selected by

For the second part, does the video has to be playing(changing frames) like in the first part or should it only be changing when the slider is moved?


For lab part 2, it only needs to change when the slider is moved. (For your team project, you may want the flexibility to do both things though...)

+16 votes

I would fork the example that the tutorial has at the bottom of "Your First JavaFX Application with OpenCV". This will allow you to see how to get the display to work for using a webcam, so you will have to change it from the webcam to the recording of the chicks. I would look at the documentation for OpenCV so you can understand what the methods are doing and how to manipulate them to work for the recording.

answered by (1 point)

I tried looking into that but the language is confusing and the gitHub code is different from the actual tutorial so that didn't help I'm still not able to get the video to display.

+15 votes

Once you have forked the code for part 1 start looking through it to understand it. There should be a fairly distinct part of the code that just uploads one frame of the video, and another part of the code to continuously upload the frames to give the impression of a video is playing

answered by (1 point)