First of all, I'm very new to programming in general and Python in particular, I've been studying it for about 1.5 weeks, so any detailed criticism and/or explained corrections are welcome.
We are producing a certain device at my company and it is being tested at the QA station by using a shell script that is provided by the developer. I'm not allowed to change the said script.
At a certain point of the test, a comparison between two images is needed, it is done by showing the pictures to the operator of the station and asking for his/her input in y/n format.
I'm trying to come up with a python script that would be able to provide this input automatically based on the score that I got from the image comparison.
I have 2 problems, first being that I can't seem to catch the moment of the script reading the input, only an echo before or after. Second is that I can't seem to find a way to provide the input and let the script continue to do it's thing.
Now onto the tech details: I'm using this module to handle the image comparison.
from skimage.measure import compare_ssim as ssim
import cv2 as cv2
class Compare_images:
def __init__(self):
self.s = None
self.original = cv2.imread("img1.png")
self.contrast = cv2.imread("img2.png")
def compare_images(self):
self.s = ssim(self.original, self.contrast, multichannel = True)
return self.s
This is the example of the shell script
echo "Welcome!"
#something happens here
read -p "Script is asking for user input as in y/n:" userinput
if [ "$userinput" = "n" ]
then
#script continues 1 way
else
#script continues another way
fi
And this is my main script.
from subprocess import Popen, PIPE
from compare_images import Compare_images
reply = None
def run(command):
process = Popen(command, stdout=PIPE, shell=True)
while True:
line = process.stdout.readline().rstrip()
if not line:
break
yield line
if __name__ == "__main__":
for path in run("./shellscript.sh"):
if 'Script is asking for user input as in y/n:' in path.decode():
a = Compare_images()
a.compare_images()
result = a.s
if result<0.9:
reply = "n"
#input to shell script is given
print(f'comparison result is {result}')
else:
reply = "y"
#input to shell script is given
print(f'comparison result is {result}')
I'm using python 3.6 and running on ubuntu 18.04. Thank you for your help in advance!