Python Multiprocess OpenCV Webcam Get Request [closed]

2024/11/16 16:48:47

I'm new to multiprocessing but have spent a whole day trying to get the following to work properly.

I'm trying to run my Webcam using OpenCV (func_run_forever) in parallel with a single requests.get (func_run_once). So the expected result is my webcam running in a window (imshow), and a single Response 200 from requests.get while my webcam is running. However, the request.get won't run until I quit the OpenCV window.

Any help, tips, clues...or even answers would be much appreciated!

from multiprocessing import Process
import cv2
import requestsdef func_run_forever():cap = cv2.VideoCapture(0)while(True):ret, frame = cap.read()cv2.imshow('frame',frame)if cv2.waitKey(1) & 0xFF == ord('q'):breakcap.release()cv2.destroyAllWindows()def func_run_once():res = requests.get('https://www.google.com.au')print(res)if __name__ == '__main__':p1 = Process(target=func_run_forever())p2 = Process(target=func_run_once())p1.start()p2.start()p1.join()p2.join()
Answer

Mate, your code needs like 1% modification to work as intended. Change this:

p1 = Process(target=func_run_forever())
p2 = Process(target=func_run_once())

to this:

p1 = Process(target=func_run_forever)
p2 = Process(target=func_run_once)
https://en.xdnf.cn/q/119503.html

Related Q&A

error when trying to run my tensorflow code

This is a follow up question from my latest post: Put input in a tensorflow neural network I precoded a neural network using tensorflow with the MNIST dataset, and with the help of @FinnE was able to c…

ValueError: invalid literal for int() with base 10: Height (mm)

import csv from decimal import *def mean(data_set):return Decimal(sum(data_set)) / len(data_set)def variance(data_set):mean_res = mean(data_set)differences = []squared_res = []for elem in data_set:diff…

Having trouble in getting page source with beautifulsoup

I am trying to get the HTML source of a web page using beautifulsoup. import bs4 as bs import requests import urllib.request sourceUrl=https://www.pakwheels.com/forums/t/planing-a-trip-from-karachi-to-…

Cannot convert from pandas._libs.tslibs.timestamps.Timestamp to datetime.datetime

Im trying to convert from pandas._libs.tslibs.timestamps.Timestamp to datetime.datetime but the change is not saved: type(df_unix.loc[45,LastLoginDate])OUTPUT: pandas._libs.tslibs.timestamps.Timestampt…

string index out of range Python, Django

im using Django to develop a web application. When i try and run it on my web form i am receiving string index out of range error. However, when i hardcode a dictionary in to a python test file it work…

PyQt UI event control segregation

I am a beginner in python but my OOPS concept from Java and Android are strong enough to motivate me in making some tool in python. I am using PyQt for developing the application. In my application th…

How to re-run process Linux after crash? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.This question does not appear to be about a specific programming problem, a software algorithm, or s…

Number of pairs

I am trying to write a code that takes m. a, a list of integers n. b, an integer and returns the number of pairs (m,n) with m,n in a such that |m-n|<=b. So far, Ive got this def nearest_pairs(a, b):…

xml.etree.ElementTree.ParseError: not well-formed

I have the following code:from xml.etree import ElementTreefile_path = some_file_pathdocument = ElementTree.parse(file_path, ElementTree.XMLParser(encoding=utf-8))If my XML looks like the following it …

Convert nested XML content into CSV using xml tree in python

Im very new to python and please treat me as same. When i tried to convert the XML content into List of Dictionaries Im getting output but not as expected and tried a lot playing around.XML Content<…