Partage

How to link a video capture and a picture analysis

Using OpenCV, given the fact that the picture has to be in jpg.

11 septembre 2017 à 15:43:33

<form id="form-t3_6zfcqscrm" class="usertext warn-on-unload" style="margin: 0px; padding: 0px; font-size: small;" action="https://www.reddit.com/r/opencv/comments/6zfcqs/how_to_link_a_video_capture_and_a_framebyframe/#">

Hello, I'm looking to make a Python program using OpenCV, which could both capture a video from the webcam, and analyse its pictures. So, the program is in two parts.

The video capture, which works correctly :

import cv2 import numpy as np cap0 = cv2.VideoCapture(0) while True: _, frame = cap0.read() hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) lower_beige = np.array([90,00,40]) upper_beige = np.array([150,255,135]) mask = cv2.inRange(hsv, lower_beige, upper_beige) res = cv2.bitwise_and(frame,frame, mask= mask) 

And the image analysis :

imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) ret,thresh = cv2.threshold(imgray,127,255,0) image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) cnt = contours[0] area=cv2.contourArea(cnt) perimeter = cv2.arcLength(cnt,True) hull = cv2.convexHull(cnt) img = cv2.drawContours(img, hull, -1, (0,0,255), 3) area = cv2.contourArea(cnt) print(area) 

What I wanted to do is to use each 'mask' variable, which is a frame of the video ( although a bit modified ), and analyse it in real time, for example with : "img = cv2.imread(mask,-1)" bewteen the two programs, in order to link them. However, since 'mask' is a frame of the video, and 'img' HAS TO be a .jpg picture, how could I manage to link the programs ?

Thank you

</form>
Staff 11 septembre 2017 à 22:03:28

Hello, I move in the forum in English
Se démerder tout seul (par grafikart)

How to link a video capture and a picture analysis

× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
  • Editeur
  • Markdown