def main(): args = get_arguments() range_filter = args['filter'].upper() # if args['image']: # image = cv2.imread(args['image']) # if range_filter == 'RGB': # frame_to_thresh = image.copy() # else: # frame_to_thresh = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) # else: # camera = cv2.VideoCapture(0) # change 0 to 1 to change webcam number if args['webcam']: camera = cv2.VideoCapture(0) # change 0 to 1 to change webcam number else: # Initialize VREP-ARIF simulation sim = arif.simulation().start() # Get the camera instance camera = arif.VideoCapture(sim, 'v0') setup_trackbars(range_filter) while True: # if args['webcam']: ret, image = camera.read() # if not ret: # break if range_filter == 'RGB': frame_to_thresh = image.copy() else: frame_to_thresh = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) v1_min, v2_min, v3_min, v1_max, v2_max, v3_max = get_trackbar_values( range_filter) thresh = cv2.inRange(frame_to_thresh, (v1_min, v2_min, v3_min), (v1_max, v2_max, v3_max)) if args['preview']: preview = cv2.bitwise_and(image, image, mask=thresh) cv2.imshow("Preview", preview) else: cv2.imshow("Original", image) cv2.imshow("Thresh", thresh) if cv2.waitKey(1) & 0xFF is 27: break
''' import cv2 import numpy as np import imutils import math '''--- For using the ARIF simulation ---''' import sys, os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) os.chdir("..\\ariflib") # <-- if in Windows # os.chdir("../ariflib") # <-- if in Linux from ariflib import arif '''--------------------------------------''' # Initialize VREP-ARIF simulation sim = arif.simulation().start() # Get the camera and robot instances cap = arif.VideoCapture(sim, 'v0') robot = arif.PioneerP3DX(sim) # Threshold the HSV image for only orange colors hsv_range = { 'lower_green': np.array([58, 70, 70]), 'upper_green': np.array([71, 255, 255]), 'lower_blue': np.array([115, 70, 70]), 'upper_blue': np.array([128, 255, 255]), 'lower_yellow': np.array([28, 70, 70]), 'upper_yellow': np.array([49, 255, 255]), 'lower_red': np.array([0, 70, 70]), 'upper_red': np.array([26, 255, 255]) }