Ask Your Question

gde1's profile - activity

2017-06-25 21:11:51 -0600 commented question Unexpected interaction between Swing and VideoCapture?

I cleaned it up and further clarified my question. It's really not that there's an issue with Swing and VideoCapture, it's that I think there's some weird interaction going on. I'll delete the older one.

2017-06-25 17:38:16 -0600 asked a question Unexpected interaction between Swing and VideoCapture?

I've come across what I believe is a weird interaction between Swing and the VideoCapture class in OpenCV, and I was wondering if anyone either had an explanation or at least could duplicate my issue.

I've included minimal version of my code below.

Essentially, this code opens a VideoCapture and sets up a JFrame. It sets the Jframe to show an image, then reads in the video using VideoCaptue, and attempts to read a number of frames more than there are actual frames in the video. It then changes the JFrame to show a different image. However, it doesn't work correctly. If the two lines involving the VideoCapture are not commented out, once the VideoCapture reads a blank frame from the video, the JFrame closes. This is despite the fact that the VideoCapture never interacts with any of the content in the JFrame. The final line in the code, where we attempt to show something else, doesn't work. The JFrame remains closed, and that image is not shown. When the lines involving the VideoCapture are commented out, this runs as expected, it shows the first image briefly, runs through the loop (doing essentially nothing), and then shows the second image.

Any thoughts on what exactly is happening would be appreciated. I'm on a Mac, coding in Scala in IntelliJ, using OpenCV 3.0 with the official java wrapper. If not thoughts, if anyone on a Mac could test this, that'd be appreciated too.

class scalaTest {
  System.loadLibrary(Core.NATIVE_LIBRARY_NAME)

  def runTest() : Unit = {
    //val reader = new VideoCapture("video.mp4")
    val frm : JFrame = new JFrame("TestWindow")
    val lbl : JLabel = new JLabel()
    frm.add(lbl)
    frm.pack()
    frm.setVisible(true)
    frm.setSize(600,600)

    val imgIcon = new ImageIcon("image1.jpg")
    lbl.setIcon(imgIcon)
    var img : Mat = new Mat()

    var count : Int = 0

    // Video is 84 frames, so this overshoots it
    while (count <=100) {
     // reader.read(img)
      println(count)
      count += 1
    }

    //Show something else
    lbl.setIcon(new ImageIcon("image2.jpg"))

    //Other code here
  }
}
2017-06-16 09:21:34 -0600 commented question Issue with OpenCV and Swing - Video Display

This is a really simplified version of my actual code. It just displays the image in the JFrame, and can run through the movie grabbing each frame in the while loop. Running this without the VideoCapture results in the JFrame not closing, as I never set that property. Running it with the VideoCapture results in the JFrame closing as soon as the VideoCapture reads a blank frame, as opposed to when the program ends. In my actual program, there's more code after the while loop that attempts to use the given JFrame. However, it disappears as soon as the VideoCapture reads a blank frame, and I can't make it display afterwards.

Hope that helps explain.

2017-06-15 21:52:56 -0600 asked a question Issue with OpenCV and Swing - Video Display

I've been messing around with OpenCV, and have an issue with displaying images through Swing.

I'm using Swing, and was running into an issue where my JFrame and JPanel would close after I'd finished reading my video. After a good amount of debugging, this issue appears to be an interaction between the OpenCV VideoCapture and the JFrame. Once VideoCapture reads an empty frame, the JFrame closes, regardless of whether it has any link to the VideoCapture. Here's the simplest code I could write which still shows the issue. When the three commented lines (excluding the while loop) below are commented, this runs fine, and the JFrame stays up until I close it. When the three commented lines below are uncommented, the JFrame closes as soon as the reader reads a blank frame.

Note that there's two while loop lines, that was on purpose to test. The video is 84 frames.

If anyone could run this and see if it happens for them too, I'd appreciate it (or just explain why this happens).

I'm using Scala in IntelliJ on a Mac.

class scalaTest {
  System.loadLibrary(Core.NATIVE_LIBRARY_NAME)

def runTest() : Unit = {
  //val reader = new VideoCapture("src/main/resources/myVideo.mp4")
  val frm : JFrame = new JFrame("TestWindow")
  val lbl : JLabel = new JLabel()
  frm.add(lbl)
  frm.pack()
  frm.setVisible(true)
  frm.setSize(600,600)

  val imgIcon = new ImageIcon("src/main/resources/testimage.jpg")
  lbl.setIcon(imgIcon)
  var img : Mat = new Mat()

  var count : Int = 0

  //reader.read(img)
  //while (!img.empty()) {
  while (count <=250) {
    //reader.read(img)
    println(count)
    count += 1
  }
}
2017-06-09 13:36:17 -0600 received badge  Enthusiast
2017-06-09 13:36:17 -0600 received badge  Enthusiast
2017-01-26 00:38:41 -0600 asked a question Using get and put to access data in a MAT

I've been messing around with openCV recently, and have been running into an issue that I can't figure out. I've been trying to manipulate data in MATs, and haven't been able to use the get and put functions.

I'm currently using JavaCV and Scala. I'm trying to implement a solution I saw elsewhere on the web, as seen below. However, I'm not able to use get and put. Here's my code:

import org.bytedeco.javacpp.opencv_core._
import org.bytedeco.javacpp.opencv_imgproc._
import org.bytedeco.javacpp.opencv_videoio.VideoCapture
import org.bytedeco.javacv._
import org.bytedeco.javacpp.opencv_highgui._

. . .

def setChannel(img : Mat, chan : Int, value : Int) = {
    val cols = img.cols()
    val step = img.channels()
    val rows = img.rows()

    var a : Int = 0
    var b : Int = 0

    for (a <- 1 until rows) {
      for (b <- 1 until cols) {
        //THIS DOESNT WORK           
        val data : Array[Double] = img.get(a,b)
        data(chan) = value
       //THIS DOESNT WORK
        img.put(a,b,data)

      }
    }
  }

It won't recognize either get() or put() here. Am I missing something fundamental here? I'm not sure if I'm either just not importing the right thing, or not getting something here. Any help would be appreciated.