Python-Julia communication

Hi all,

I have the following python code:

import cv2

img = cv2.imread("/home/g2-test/julia_Hands_on/cat3.jpg")
cv2.imshow("original image", img)
img2 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("gray scale image", img2)
cv2.waitKey(0)
cv2.destroyAllWindows()

I want my julia code to call this python code. How can I do this using PyCall.

Can someone explain me. Should I do something with opencv?

Thanking you in advance.

using PyCall

py"""
import cv2

img = cv2.imread("/home/g2-test/julia_Hands_on/cat3.jpg")
cv2.imshow("original image", img)
img2 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("gray scale image", img2)
cv2.waitKey(0)
cv2.destroyAllWindows()
"""
1 Like

Alternatively:

using PyCall
cv2 = pyimport("cv2")
img = cv2.imread("/home/g2-test/julia_Hands_on/cat3.jpg")
cv2.imshow("original image", img)
img2 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("gray scale image", img2)
cv2.waitKey(0)
cv2.destroyAllWindows()

should also work. With PyCall now supporting . syntax, a lot of python code just works in julia.

4 Likes

This is woking. Thank you.

This is also working. Thank you.