Ask Your Question
0

Threading failed using Tkinter and Python 2.7

asked 2018-02-03 10:34:38 -0600

Nasrul97 gravatar image

updated 2018-02-05 12:55:03 -0600

I cant solve this. I've been searching for few days but still cant fix it yet.

nasrul@nasrul-Lenovo:~/Documents/HBRMonitorV1.00$ python main.py
VIDEOIO ERROR: V4L: index 1 is not correct!
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/imgproc/src/color.cpp, line 11048
Traceback (most recent call last):
  File "main.py", line 35, in <module>
    guiThread.start(videoThread)
  File "/home/nasrul/Documents/HBRMonitorV1.00/gui.py", line 39, in start
    self.main_window = MainWindow(self, self.cameraThread, self.root)
  File "/home/nasrul/Documents/HBRMonitorV1.00/gui.py", line 87, in __init__
    self.signal_display = WindowSignal(self, root, gui_thread, video_thread, self.statusbar, self.video_display)
  File "/home/nasrul/Documents/HBRMonitorV1.00/gui_windowSignal.py", line 34, in __init__
    self.__create_gui()
  File "/home/nasrul/Documents/HBRMonitorV1.00/gui_windowSignal.py", line 64, in __create_gui
    self.video_display, self.dataQueue)
  File "/home/nasrul/Documents/HBRMonitorV1.00/gui_signalProcessor.py", line 47, in __init__
    self.signalProcessingInstance = SignalProcessor()
  File "/home/nasrul/Documents/HBRMonitorV1.00/signal_processing.py", line 34, in __init__
    self.serial_interface = serial_interface.SerialInterface('/dev/ttyUSB0')
  File "/home/nasrul/Documents/HBRMonitorV1.00/serial_interface.py", line 33, in __init__
    self.serial_connection = serial.Serial(self.vPort, 9600)
  File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 180, in __init__
    self.open()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 311, in open
    self._update_dtr_state()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 605, in _update_dtr_state
    fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str)
IOError: [Errno 22] Invalid argument
Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/nasrul/Documents/HBRMonitorV1.00/gui_toolbarROI.py", line 262, in __store_roi
    if len(self.textbox_x1.get("1.0", Tk.END + "-1c")) > 0 & (
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 3082, in get
    return self.tk.call(self._w, 'get', index1, index2)
RuntimeError: main thread is not in main loop
Exception in thread Thread-4:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/nasrul/Documents/HBRMonitorV1.00/gui_toolbarROI.py", line 247, in __store_color_channel
    chan = self.list_color_channelsStr.get()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 343, in get
    value = self._tk.globalgetvar(self._name)
RuntimeError: main thread is not in main loop


Exception in thread Thread-6:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/nasrul/Documents/HBRMonitorV1.00/gui_windowVideo.py", line 195, in __compute_fps
    self.video_frame.after(1000, lambda: self.__compute_fps())
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 597, in after
    name = self._register(callit)
  File "/usr ...
(more)
edit retag flag offensive close merge delete

Comments

i think u should check jpeg and png and V4L when building opencv

arh24 gravatar imagearh24 ( 2018-02-04 05:30:44 -0600 )edit

Thankyou. I've been wondering why it doesnt work. It's seems like my TKinter is the problem, cause the code was perfectly fine in another pc.

Nasrul97 gravatar imageNasrul97 ( 2018-02-04 07:20:44 -0600 )edit

@arh24. The answer is NO!. That is not the problem jpeg. The thread is not in mainloop ==> that is problem will be solved

supra56 gravatar imagesupra56 ( 2018-02-04 08:12:41 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-02-04 04:45:37 -0600

supra56 gravatar image

updated 2018-02-04 04:46:25 -0600

Move the thread and mainloop at the end of cv2.waitKey, but not before waitKey.

edit flag offensive delete link more

Comments

Btw, the V4L: index 1 is not correct is no the error problem

supra56 gravatar imagesupra56 ( 2018-02-04 05:14:36 -0600 )edit

Thank you so much. Yes, at first I thought that was the problem but it seems it isnt. And I think the main problem was my TKinter itself. Because it's the code is working fine in my second pc.

Nasrul97 gravatar imageNasrul97 ( 2018-02-04 07:18:17 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-02-03 10:34:38 -0600

Seen: 1,106 times

Last updated: Feb 05 '18