Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

convert plt.show to image to show opencv

import matplotlib
matplotlib.use('TkAgg')
import numpy as np
import cv2
import matplotlib.pyplot as plt

...

fig = plt.figure()
# redraw the canvas
fig.canvas.draw()
# convert canvas to image
img = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
img  = img.reshape(fig.canvas.get_width_height()[::-1] + (3,))
# img is rgb, convert to opencv's default bgr
img = cv2.cvtColor(img,cv2.COLOR_RGB2BGR)
# display image with opencv or any operation you like
cv2.imshow("plot",img)
... 
 
PREVIOUS NEXT
Tagged: #convert #image #show #opencv
ADD COMMENT
Topic
Name
5+4 =