0

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

  1. How do I send the image from mysql database as a parameter to the script?
  2. How do I execute the script and store the resulting image in the database?

1 Answer 1

1

Well, for starters You should redo your python script to make it parameterized.
Something like this:

img = cv2.imread('original.png')

should not exist in your script! You should receive filepath as a script's paramter.

The rest pretty much depends on how You implemented it and how do You want it to work.

If You want to execute programs from within php script please take a look at shell_exec() or exec()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.