I am creating an application in which i need that in one page there is a button and one view. When i click on that button i want to open camera in that view only not separate view of camera. Is it possible? And if yes, please provide me some hint or code. Thank you.
This code opens the camera separately and not in the designated area
enter code here
def onclicked(self):
u_nam = self.txt_name
img_counter = 0
self.cap = cv2.VideoCapture(0)
while self.cap.isOpened():
ret, frame = self.cap.read()
frame = cv2.flip(frame, 1)
if ret == True:
cv2.imshow(' ', frame)
k = cv2.waitKey(1)
if k%256 == 27:
# ESC pressed
print("Escape hit, closing...")
break
elif k%256 == 32:
#elif k == btn1:
# SPACE pressed
cv2.imwrite("registered/{u_nam}/frame_{img_counter}.jpg", frame)
print("Successfully captured!")
ret, frame = self.cap.read()
img_counter += 1
self.cap.release()
cv2.destroyAllWindows()
Related
I am trying to figure out how to replace keyboard press into mouse left click..
I tried pynput, but for somewhat reason it doesn't seem to be working. Can anyone help with this?
IS there a way to receive this input even while doing something else? For example browsing the internet and still getting screenshots when mouse is clicked.
cam = cv2.VideoCapture(1)
cv2.namedWindow("test")
img_counter = 0
while True:
ret, frame = cam.read()
if not ret:
print("failed to grab frame")
break
cv2.imshow("test", frame)
k = cv2.waitKey(1)
if k%256 == 27:
# ESC pressed
print("Escape hit, closing...")
break
elif k%256 == 32:
# SPACE pressed
img_name = "opencv_frame_{}.png".format(img_counter)
cv2.imwrite(img_name, frame)
print("{} written!".format(img_name))
img_counter += 1
cam.release()
cv2.destroyAllWindows()
Video Stream
Video Frame Capture
Is there any way to get these both to run simultaneously? Like making the video stream run in the bg or something.
Video Stream:
def gen(camera):
while True:
frame = camera.get_frame()
yield frame
#eel.expose
def video_feed():
x = VideoCamera()
y = gen(x)
for each in y:
# Convert bytes to base64 encoded str, as we can only pass json to frontend
blob = base64.b64encode(each)
blob = blob.decode("utf-8")
eel.updateImageSrc(blob, 'output')
Frame Capture:
#eel.expose
def CamDetection():
cap = cv2.VideoCapture(1)
img_counter = 0
if True:
ret, frame = cap.read()
if not (cap.isOpened()):
print("failed to grab frame")
# break
# cv2.imshow("test", frame)
# k = cv2.waitKey(1)
# if k%256 == 27:
# # ESC pressed
# print("Escape hit, closing...")
# break
# if k%256 == 32:
# # SPACE pressed
img_name = "SKH_frame.png".format(img_counter)
path = 'F:\Tensorflow\yolov5\webcamimage'
cv2.imwrite(os.path.join(path, img_name), frame)
print("{} written!".format(img_name))
img_counter += 1
cap.release()
I am using the code below to capure frames from the camera when space key is pressed and save the frame to file. This code works OK.
import cv2
cam = cv2.VideoCapture("rtsp://10.0.0.90:554/?chID=1&streamType=main&linkType=tcp")
cv2.namedWindow("test")
img_counter = 0
while True:
ret, frame = cam.read()
cv2.imshow("test", frame)
if not ret:
break
k = cv2.waitKey(1)
if k%256 == 27:
# ESC pressed
print("Escape hit, closing...")
break
elif k%256 == 32:
# SPACE pressed
img_name = "opencv_frame_{}.png".format(img_counter)
cv2.imwrite(img_name, frame)
print("{} written!".format(img_name))
img_counter += 1
cam.release()
cv2.destroyAllWindows()
I need your help to edit this code and create new loop where every half second 2 last frames will blink so I can
cv2.imshow('image', previous_frame)
time.sleep(0.5)
cv2.imshow('image', last_frame)
time.sleep(0.5)
So the task is when the programm starts show the first still frame (opencv_frame_0.png). When the space key pressed start flashing 2 images (opencv_frame_0 and opencv_frame_1) every 0.5 sec. When space key pressed again the images that will flash will be opencv_frame_1 and opencv_frame_2.
I am noob in python and opencv and need some help.
Thank you in advance.
I am creating a camera application using opencv and pyautogui.The function is not getting evaluated.
from utils import CFEVideoConf, image_resize
def recog():
cap = cv2.VideoCapture(0)
save_path = 'saved-media/video.avi'
frames_per_seconds = 24.0
config = CFEVideoConf(cap, filepath=save_path, res='720p')
out = cv2.VideoWriter(save_path, config.video_type, frames_per_seconds, config.dims)
while (True):
# Capture frame-by-frame
ret, frame = cap.read()
out.write(frame)
# Display the resulting frame
cv2.imshow('frame',frame)
if cv2.waitKey(20) & 0xFF == ord('q'):
op = pyautogui.confirm("")
if op == 'OK':
print("Out")
break
cap.release()
out.release()
cv2.destroyAllWindows()
opt =pyautogui.confirm(text= 'Chose an option', title='Camcorder', buttons=['Record', 'Capture', 'Exit'])
if opt == 'START':
print("Starting the app")
recog()
if opt == 'Exit':
print("Quit the app")
Please correct the mistakes if there are any.
The function recog is not getting evaluated because of below if statement
if opt == 'START':
There is no button named START. Your confirm() function displays a message box with Record, Capture, Exit buttons, but no START button. So, there is no way confirm() function returned value will be equal to START.
I am viewing a webcam camera live feed. I would like to incorporate this into a Tkinter GUI and have a dropdown selection that allows one to change the camera index, and therefore the webcam being used, on the fly.
How can this be achieved?
Example code:
import cv2
def show_webcam(mirror=False):
cam = cv2.VideoCapture(0)
while True:
ret_val, img = cam.read()
if mirror:
img = cv2.flip(img, 1)
cv2.imshow('my webcam', img)
if cv2.waitKey(1) == 27:
break # esc to quit
cv2.destroyAllWindows()
def main():
show_webcam(mirror=True)
if __name__ == '__main__':
main()
To change camera at run time all you need to change is the index you pass in
cv2.VideoCapture(index).
Find out how many camera you will be using for your app and for 3 cameras, you can change it through changing index to 0 or 1 or 2.
Add one more parameter as index
show_webcam(mirror=True, index)
in function side you can use this
def show_webcam(mirror=False,index):
cam = cv2.VideoCapture(index)
while True:
ret_val, img = cam.read()
if mirror:
img = cv2.flip(img, 1)
cv2.imshow('my webcam', img)
if cv2.waitKey(1) == 27:
break # esc to quit
cv2.destroyAllWindows()