Define Tuple with PuthonObject

Trying to convert the below opencv python code to mojolang:
import cv2 as cv

cap = cv.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
exit()
while True:
# Capture frame-by-frame
ret, frame = cap.read()

# if frame is read correctly ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
# Our operations on the frame come here
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# Display the resulting frame
cv.imshow('frame', gray)
if cv.waitKey(1) == ord('q'):
break

# When everything done, release the capture
cap.release()
cv.destroyAllWindows()
import cv2 as cv

cap = cv.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
exit()
while True:
# Capture frame-by-frame
ret, frame = cap.read()

# if frame is read correctly ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
# Our operations on the frame come here
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# Display the resulting frame
cv.imshow('frame', gray)
if cv.waitKey(1) == ord('q'):
break

# When everything done, release the capture
cap.release()
cv.destroyAllWindows()
So, I wrote the below:
from python import Python

def main():
# This is equivalent to Python's `import numpy as np`
cv = Python.import_module("cv2")

cap = cv.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
# exit()
while True:
# Capture frame-by-frame
var ret, frame = cap.read() # I get the error here

# if frame is read correctly ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
# Our operations on the frame come here
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# Display the resulting frame
cv.imshow('frame', gray)
if cv.waitKey(1) == ord('q'):
break

# When everything done, release the capture
cap.release()
cv.destroyAllWindows()
from python import Python

def main():
# This is equivalent to Python's `import numpy as np`
cv = Python.import_module("cv2")

cap = cv.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
# exit()
while True:
# Capture frame-by-frame
var ret, frame = cap.read() # I get the error here

# if frame is read correctly ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
# Our operations on the frame come here
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# Display the resulting frame
cv.imshow('frame', gray)
if cv.waitKey(1) == ord('q'):
break

# When everything done, release the capture
cap.release()
cv.destroyAllWindows()
I got the error: declaration must have either a type or an initializer at the line var ret, frame = cap.read()
4 Replies
DobyDabaDu
DobyDabaDu2mo ago
Dont use var in def function (to solve the issue)
cr = cap.read()
ret = cr[0]
frame = cr[1]
cr = cap.read()
ret = cr[0]
frame = cr[1]
Hasan Yousef
Hasan YousefOP2mo ago
I got use of unknown declaration 'ret'
DobyDabaDu
DobyDabaDu2mo ago
This is a working approach
Hasan Yousef
Hasan YousefOP2mo ago
Thanks a lot, it worked well.
Want results from more Discord servers?
Add your server