Search
 
SCRIPT & CODE EXAMPLE
 

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)
... 
Comment

PREVIOUS NEXT
Code Example
Python :: start ipython with any version 
Python :: pandas drop 1970 
Python :: input a number and print even numbers up to that number 
Python :: how to input a full array in one input in python 
Python :: pandas series to dataframe index as column 
Python :: hello world in python 3 
Python :: how to do formatting in python with format function 
Python :: minio python create bucket 
Python :: python selenium teardown class 
Python :: django delete table data 
Python :: foreign key django createview 
Python :: i = 1 while i <= 100: print(i * *") i = i + 1 
Python :: ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters 
Python :: mistborn books 
Python :: python replace in string 
Python :: tkinter asksaveasfile 
Python :: convert int to ascii python 
Python :: python string assignment by index 
Python :: how to create a function in python 
Python :: na.fill pyspark 
Python :: remove list from list python 
Python :: Python program to print all even numbers in a range 
Python :: items of list 
Python :: python code style 
Python :: pandas make currency with commas 
Python :: Django - Knox auth setup 
Python :: Get text without inner tags text in selenium 
Python :: controlling the mouse with pynput 
Python :: python for loop practice problems 
Python :: pd df merge 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =