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:
- Opening the video
vidCap.open("/file/path/etc.mp4");
- reading in one frame (still image) from it:
Mat frame = new Mat()
vidCap.read(frame);
- 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.
- 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.