Answer to Question #141367 in Python for Bowe

Question #141367
The following code lines represent a simple expert system about a
cancer image detection under computer vision. You are required to
identify and explain the effect of the different command lines;
3import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(1):
_, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_red = np.array([0,0,0])
upper_red = np.array([255,255,180])
mask = cv2.inRange(hsv, lower_red, upper_red)
res = cv2.bitwise_and(frame,frame, mask= mask)
cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('res',res)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
cap.release()
1
Expert's answer
2020-11-02T11:21:00-0500
# Importing a library OpenCV for working with images and videos
import cv2 
# Importing a library NumPy for working with numeric data
import numpy as np 
# Capture streaming video from camcorder 0
cap = cv2.VideoCapture(0) 
# Creating an endless loop
while(1):
# Receive video frame parameter size is ignored
    _, frame = cap.read() 
# Convert image frame from BGR to HSV
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
#  define range of color in HSV
    lower_red = np.array([0,0,0])
    upper_red = np.array([255,255,180])
# Threshold HSV image to get only the selected color
    mask = cv2.inRange(hsv, lower_red, upper_red) 
# Bitwise-AND mask and original image
    res = cv2.bitwise_and(frame,frame, mask= mask)
# Show the video frame of the mask used and the result of the mask overlay
    cv2.imshow('frame',frame)
    cv2.imshow('mask',mask)
    cv2.imshow('res',res) 
# Pause for 5 milliseconds if ESC is pressed, exit from endless cycle
    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break 
# Closing all windows created OpenCV
cv2.destroyAllWindows()
# Freeing up the resources of the involved video camera
cap.release()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS