1

Is there something I am missing? I would like to run software without having to go install a monitor on a virtual machine and hit a key every time it processes another image. The concept of forcing the GUI dependence on the user seems rather odd... Why assume a physical monitor?

I have jumped through the hoops for the "AGG" backend to remove the X server dependence, but this changes nothing. How can I force it to not try and draw to a non-existent display?

import cv2
import numpy as np
import os
from decimal import Decimal
from PIL import Image 
from PIL.ExifTags import TAGS 
import time
import matplotlib

matplotlib.use('Agg')
import matplotlib.pyplot as plt



chans = cv2.split(img)
colors = ("b", "g", "r")
plt.figure()
#plt.axis('off')
features = []

# loop over the image channels
for (chan, color) in zip(chans, colors):
    chist = cv2.calcHist([chan], [0], None, [256], [0, 256])
    features.extend(chist)

# plot the histogram
plt.plot(chist, color = color)
plt.xlim([0, 256])
plt.savefig('histchart.png', bbox_inches=0)

No matter what I do, it still forces that stupid GUI dependance. Is there any way to totally and completely remove the dependency?

Matt King
  • 19
  • 2
  • In principle your code seems correct, judging from [this question](http://stackoverflow.com/questions/4931376/generating-matplotlib-graphs-without-a-running-x-server). You would need to go into more detail about what is wrong with it, and/or produce a [MCVE]. Because you're not showing the complete code, it may be that you are importing pyplot already beforehands (possibly hidden in some other import?). – ImportanceOfBeingErnest Jan 09 '17 at 16:52
  • Updated with full imports. The issue is the unwanted pop up window. I can jump through hoops and make the OS think there is a display, but someone still needs to press a button on the plot to make it go away and let the program continue. I struggle to understand why that dependency is built in by default. Which makes it likely that I am missing something. I also dont understand why using the 'Agg' backend does not solve the issue as advertised. The evidence indicates here as well I am missing something.... – Matt King Jan 10 '17 at 01:35
  • As I said, the code should work. When I add a line to define `img`, like `img = cv2.imread("some_file.png")`, the script runs without displaying anything on the screen. This is on windows 8 with python 2.7, matplotlib 1.5, opencv 2.4. So it may be an issue of your OS? Adding details about your system might help others to reproduce the issue. – ImportanceOfBeingErnest Jan 10 '17 at 08:18

0 Answers0