Skip to content

Commit

Permalink
change functions from cv2 to matplotlib
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sasatani committed Aug 15, 2023
1 parent 92601d7 commit b479829
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions miniscope_io/uart_daq.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from datetime import datetime
import numpy as np
import cv2
import matplotlib.pyplot as plt
import sys
import time

Expand Down Expand Up @@ -44,7 +45,7 @@ def _uart_recv(self, serial_buffer_queue, comport: str, baudrate: int):
while 1:
# read UART data until preamble and put into queue
log_uart_buffer = bytearray(serial_port.read_until(self.preamble))
serial_buffer_queue.put(log_uart_buffer)
serial_buffer_queue.put(log_uart_buffer)

time.sleep(1) #time for ending other process
serial_port.close()
Expand Down Expand Up @@ -214,16 +215,44 @@ def capture(self, comport:str = 'COM3', baudrate:int = 1200000, mode:str = 'DEBU
p_buffer_to_frame.start()
p_format_frame.start()

imagearray_plot = imagearray.get()
image = imagearray_plot.reshape(self.frame_width, self.frame_height)
#np.savetxt('imagearray.csv', imagearray, delimiter=',')
#np.savetxt('image.csv', image, delimiter=',')

fg = plt.figure()
ax = fg.gca()

myobj = ax.imshow(image, cmap='gray')

try:
plt.draw(), plt.pause(1e-3)
except Exception as e:
print(e)

keyInput = False

# event listener
def press(event):
global keyInput
if event.key == '1':
keyInput = True

while 1: # Seems like GUI functions should be on main thread in scripts but not sure what it means for this case
if imagearray.qsize() > 0:
imagearray_plot = imagearray.get()
image = imagearray_plot.reshape(self.frame_width, self.frame_height)
#np.savetxt('imagearray.csv', imagearray, delimiter=',')
#np.savetxt('image.csv', image, delimiter=',')
cv2.imshow("image", image)
if cv2.waitKey(1) == 27:
cv2.destroyAllWindows()
cv2.waitKey(100)
#np.savetxt('image.csv', image, delimiter=',')]
print(image)
myobj.set_data(image)
plt.draw(), plt.pause(1e-3)

#cv2.imshow("image", image)
if keyInput == True:
#if cv2.waitKey(1) == 27:
#cv2.destroyAllWindows()
#cv2.waitKey(100)
break # esc to quit
print('End capture')

Expand Down Expand Up @@ -277,6 +306,7 @@ def main():
sys.exit(1)



daq_inst = uart_daq()
daq_inst.capture(comport = comport, baudrate = baudrate)

Expand Down

0 comments on commit b479829

Please sign in to comment.