Cv2.imshow is not working even if my camera is on and I'm getting the frame printed?

Asked
Active3 hr before
Viewed126 times

6 Answers

camera
90%

Resources Guide ,VideoCapture(path, apiPreference) ,Error opening the video file, A single argument from an enumerated list that allows you to retrieve a variety of metadata associated with the video frames, 

Example_snippet/controller/utility/_camera.js/ import cv2 # Create a video . . .
import cv2

# Create a video capture object, in this
case we are reading the video from a file
vid_capture = cv2.VideoCapture('Resources/Cars.mp4')

if (vid_capture.isOpened() == False):
   print("Error opening the video file")
# Read fps and frame count
else :
   # Get frame rate information
# You can replace 5 with CAP_PROP_FPS as well, they are enumerations
fps = vid_capture.get(5)
print('Frames per second : ', fps, 'FPS')

# Get frame count
# You can replace 7 with CAP_PROP_FRAME_COUNT as well, they are enumerations
frame_count = vid_capture.get(7)
print('Frame count : ', frame_count)

while (vid_capture.isOpened()):
   # vid_capture.read() methods returns a tuple, first element is a bool
# and the second is frame
ret, frame = vid_capture.read()
if ret == True:
   cv2.imshow('Frame', frame)
# 20 is in milliseconds,
   try to increase the value, say 50 and observe
key = cv2.waitKey(20)

if key == ord('q'):
   break
else :
   break

# Release the video capture object
vid_capture.release()
cv2.destroyAllWindows()
load more v
88%

I’m trying to feed the cuda detection output to OpenCV and having no luck! Using: Python3, CSI RPi camera, Jetson Nano Detection works fine, and I can save the Numpy image to disk, but cannot get it to render or display via cv2, and I don’t get any errors, and the process doesn’t complete,,Dusty, I tried suggested changes, but still no luck; terminal window freezes at the same line of the print output

Example_snippet/controller/utility/_camera.js/ img, width, height = camera.Ca. . .
img, width, height = camera.CaptureRGBA(zeroCopy = 1)
jetson.utils.cudaDeviceSynchronize()
detections = net.Detect(img)
cv2imgRGBA = jetson.utils.cudaToNumpy(img, width, height, 4)
cv2img = cv2.cvtColor(cv2imgRGBA, cv2.COLOR_RGBA2BGR)
cv2.imshow('showDetectNet', cv2img)
load more v
72%

your code freezes when camera gets on, There is some mistake in line 11 where you made the break condition

Example_snippet/controller/utility/_camera.js/ import numpy as np import cv2 . . .
import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while cap.isOpened():
   flags, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('img', gray)
if cv2.waitKey(0):
   break

cap.release()
cv2.destroyAllWindows()
load more v
65%

Note, that you must have tensorflow and opencv libraries installed to run this code, You can do it manually or simply run pip install -r requirements

Example_snippet/controller/utility/_model.js/ me_not_me_detector├───article├. . .
me_not_me_detector├─── article├─── datasets│├─── face_dataset_test_images│├─── face_dataset_train_aug_images│└─── face_dataset_train_images├─── models│.gitignore│ data_augmentation.ipynb│ me_not_me_classifier.ipynb│ me_not_me_classifier_model_comparison.ipynb│ me_not_me_detector.ipynb│ README.md└── requirements.txt
load more v
75%

A: The full form for OpenCV is Open Source Computer Vision Library,,If this is not the message you see, I suggest reinstalling python into your system

Example_snippet/controller/utility/_model.js/ conda install -c conda-forge o. . .
conda install - c conda - forge opencv
load more v
40%

Making statements based on opinion; back them up with references or personal experience,,I am trying to send live video from a client to server everything works fine but I'm not able to see the cv2 window I can see the light on my camera indicating that it is on and I can also see the array but the cv2 window is not appearing

Example_snippet/controller/utility/_model.js/ import socket import sys impor. . .
import socket
import sys
import cv2
import pickle
import numpy as np
import struct

HOST = 'host'
PORT = 8089

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print('Socket created')

s.bind((HOST, PORT))
print('Socket bind complete')
s.listen(10)
print('Socket now listening')

conn, addr = s.accept()

data = b ''
payload_size = struct.calcsize("L")
while True:
   while len(data) < payload_size:
   data += conn.recv(4096)
packed_msg_size = data[: payload_size]
data = data[payload_size: ]
msg_size = struct.unpack("L", packed_msg_size)[0]
while len(data) < msg_size:
   data += conn.recv(4096)
frame_data = data[: msg_size]
data = data[msg_size: ]
# # #

frame = pickle.loads(frame_data)
cv2.imshow('frame', frame) # here this is not bringing up the cv2 window
print(frame)
load more v