Skip to Content
Menu
This question has been flagged
1 Reply
3066 Views

I am using odoo 12 Enterprise version. I created a function to take the picture and save it to odoo Using OpenCV module and its works fine for first time. I am calling the function in a button click. Below is the code


@api.multi
def method_webcam_trigger(self):
key = cv2.waitKey(1)
webcam = cv2.VideoCapture(0)
while True:
try:
print("4")
check, frame = webcam.read()
print(webcam.isOpened(),check,frame)
if check:
cv2.imshow("Capturing", frame)
print("*********")
key = cv2.waitKey(1)
if key == ord('s'):
print ("SAVE IMAGE")
cv2.imwrite(filename='product_image', img=frame)
img = PIimage.fromarray(frame, 'RGB')
img.save('my.png')
roiImg = img.crop()
imgByteArr = io.BytesIO()
roiImg.save(imgByteArr, format='PNG')
imgByteArr = imgByteArr.getvalue()
image_base64 = base64.b64encode(imgByteArr)
cv2.waitKey(1650)
cv2.destroyAllWindows()
vals = {
'image': image_base64,
}
self.write(vals)
break
elif key == ord('q'):
break
except(KeyboardInterrupt):
webcam.release()
cv2.destroyAllWindows()
break
webcam.release()
cv2.destroyAllWindows()

Above is the code to take the picture using webcam and save the picture when pressing 's' in keyboard.

When i click on the button a new window will appear and show the live webcam feed and when i press the 's' button it will save the image as the product image. And this is working fine. When i click the button on the second time the execution will stuck on the below line

cv2.imshow("Capturing", frame)

Please help me to solve this.
Avatar
Discard
Best Answer

this feels like you are opening a display window on the server?

From memory you need to write to file or some kind of buffer and then process it.



Avatar
Discard
Related Posts Replies Views Activity
1
Jun 23
1576
0
Oct 21
2532