I have a python script which can preprocesses an image(increase contrast).
It works fine through the command line.
I want to call that script from PHP web application. And I want to use an image stored in MySQL database.
Here is the python script.
#!/usr/bin/env python
import cv2
import numpy as np
import cv2
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
plt.switch_backend('Qt4Agg')
img = cv2.imread('original.png')
bilateral = cv2.bilateralFilter(img,9,75,75)
img = cv2.imread('bilaterla_filtered.png')
# generating the kernels
kernel_sharpen_3 = np.array([[-1,-1,-1,-1,-1],
[-1,2,2,2,-1],
[-1,2,8,2,-1],
[-1,2,2,2,-1],
[-1,-1,-1,-1,-1]]) / 8.0
output_3 = cv2.filter2D(img, -1, kernel_sharpen_3)
cv2.imwrite('edge_enhancement.png',output_3)
img = cv2.imread('edge_enhancement.png')
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
hist,bins = np.histogram(gray_image.flatten(),256,[0,256])
cdf = hist.cumsum()
cdf_m = np.ma.masked_equal(cdf,0)
cdf_m = (cdf_m - cdf_m.min())*255/(cdf_m.max()-cdf_m.min())
cdf = np.ma.filled(cdf_m,0).astype('uint8')
img2 = cdf[img]
image_enhanced=img2
cv2.imwrite('Final.png',image_enhanced)
What should I do in the controller
- How do I send the image from mysql database as a parameter to the script?
- How do I execute the script and store the resulting image in the database?