I'm trying to invoke the python script from node application(test-cafe) and returning data i.e when we us print() in python it returns back to node,but here it does not returns anything and gets terminated directly without returning the errors.Can you please help me with getting the error from python and if possible to solving the error in the code.PS:Python standalone is working as designed but not working when invoked by python-shell in node.
Node js is not giving any error and this is the output:
**Output:**
Running tests in:
- Chrome 78.0.3904.97 / Windows 10
API
here
√ My first test
√ My first test
API
here
here also
√ should return last 10 posts
√ My first test
4 passed (1s)
***As you can see it is not giving any error and not printing the python output which it is supposed to print.Also the pythonshell.end() is not getting executed at all.***
**My Node js(TestCafe) file:**
импорт * как API из '../lib/apiModule'; import {PythonShell} из 'python -shell';
fixture`API`;
test('should return last 10 posts', async t => {
let pyshell = new PythonShell('D:\\Work\\TestCafe\\testcafe-example-master\\testcafe-example-master\\test2\\imageClassification.py',{
});
console.log('here')
// sends a message to the Python script via stdin
//pyshell.send('hello');
pyshell.on('message', function (message) {
// received a message sent from the Python script (a simple "print" statement)
console.log('here too')
console.log(message);
});
console.log('here also')
// end the input stream and allow the process to exit
pyshell.end(function (err,code,signal) {
if (err) throw err;
console.log('The exit code was: ' + code);
console.log('The exit signal was: ' + signal);
console.log('finished');
console.log('finished');
});
await t;
});
test('My first test', async t => {
});
Это файл python, который вызывается приложением узла ' ''
import cv2 из skimage.measure import compare_ssim import imutils импорт pytesseract из PIL import Изображение из pytesseract import image_to_string
def interProcess():
import numpy as np
print('abc')
print(2+3+4+5+6)
print(1+2)
original = cv2.imread("D:\\Work\\OfferPage_ExpectedPage_WithOffers.png")
duplicate = cv2.imread("D:\\Work\\OfferPage_ExpectedPage_WithOffers_Edited.png")
#print(original.shape)
#print(duplicate.shape)
#Convert the images to grayscale
grayA = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
grayB = cv2.cvtColor(duplicate, cv2.COLOR_BGR2GRAY)
# compute the Structural Similarity Index (SSIM) between the two
# images, ensuring that the difference image is returned
(score, diff) = compare_ssim(grayA, grayB, full=True)
diff = (diff * 255).astype("uint8")
print("SSIM: {}".format(score)) # 1: Similar, <1: Different
print(diff)
# threshold the difference image, followed by finding contours to
# obtain the regions of the two input images that differ
thresh = cv2.threshold(diff, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
# loop over the contours
for c in cnts:
# compute the bounding box of the contour and then draw the
# bounding box on both input images to represent where the two
# images differ
(x, y, w, h) = cv2.boundingRect(c)
cv2.rectangle(original, (x, y), (x + w, y + h), (0, 0, 255), 2)
cv2.rectangle(duplicate, (x, y), (x + w, y + h), (0, 0, 255), 2)
# show the output images
cv2.imshow("Original", original)
cv2.imshow("Modified", duplicate)
cv2.imshow("Diff", diff)
cv2.imshow("Thresh", thresh)
cv2.waitKey(0)
if __name__=="__main__":
interProcess()
'' '
Заранее спасибо !