def main(): if Carl: runLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) if Carl: tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: image = cv2.imread(args["image"]) cv2.imshow("Original", image) # flip horizontally flipped = cv2.flip(image, 1) cv2.imshow("Flipped Horizontally", flipped) # flip verically flipped = cv2.flip(image, 0) cv2.imshow("Flipped Vertically", flipped) # flip both horiz and vert flipped = cv2.flip(image, -1) cv2.imshow("Flipped Horiz and Vert", flipped) cv2.waitKey(0) except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() if Carl: runLog.logger.info("Finished") sleep(1)
def main(): if Carl: runLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) if Carl: tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: image = cv2.imread(args["image"]) cv2.imshow("Original", image) (h, w) = image.shape[:2] center = (w // 2, h // 2) # (point about to rotate, angle to rotate, scale factor) M = cv2.getRotationMatrix2D(center, 45, 1.0) rotated = cv2.warpAffine(image, M, (w, h)) cv2.imshow("Rotated by 45 Degrees", rotated) M = cv2.getRotationMatrix2D(center, -90, 1.0) rotated = cv2.warpAffine(image, M, (w, h)) cv2.imshow("Rotated -90 Degrees", rotated) rotated = imutils.rotate(image, 180) cv2.imshow("Rotated 180 Degrees", rotated) cv2.waitKey(0) except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() if Carl: runLog.logger.info("Finished") sleep(1)
def main(): lifeLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: # loop loopSleep = 1 # second loopCount = 0 keepLooping = False while keepLooping: loopCount += 1 image = cv2.imread(args["image"]) print("width: {} pixels".format(image.shape[1])) print("height: {} pixels".format(image.shape[0])) cv2.imshow("Original", image) cv2.waitKey(0) cv2.imwrite("newimage.jpg", image) keepLooping = False sleep(loopSleep) except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() lifeLog.logger.info("Finished") sleep(1)
def main(): if Carl: runLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) if Carl: tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: image = cv2.imread(args["image"]) cv2.imshow("Original", image) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.imshow("Gray", gray) hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) cv2.imshow("HSV", hsv) lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB) cv2.imshow("L*a*b*", lab) cv2.waitKey(0) cv2.destroyAllWindows() except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() if Carl: runLog.logger.info("Finished") sleep(1)
def main(): if Carl: runLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) if Carl: tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: image = cv2.imread(args["image"]) cv2.imshow("Original", image) M = np.float32([[1, 0, 25], [0, 1, 50]]) shifted = cv2.warpAffine(image, M, (image.shape[1], image.shape[0])) cv2.imshow("Shifted Down and Right", shifted) M = np.float32([[1, 0, -50], [0, 1, -90]]) shifted = cv2.warpAffine(image, M, (image.shape[1], image.shape[0])) cv2.imshow("Shifted Up and Left", shifted) shifted = imutils.translate(image, 0, 100) cv2.imshow("imutils.translate() Down 100", shifted) cv2.waitKey(0) except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() if Carl: runLog.logger.info("Finished") sleep(1)
def main(): if Carl: runLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) if Carl: tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: image = cv2.imread(args["image"]) cv2.imshow("Original", image) mask = np.zeros(image.shape[:2], dtype="uint8") (cX, cY) = (image.shape[1] // 2, image.shape[0] // 2) cv2.rectangle(mask, (cX - 75, cY - 75), (cX + 75, cY + 75), 255, -1) cv2.imshow("Mask", mask) masked = cv2.bitwise_and(image, image, mask=mask) cv2.imshow("Mask Applied to Image", masked) mask = np.zeros(image.shape[:2], dtype="uint8") cv2.circle(mask, (cX, cY), 100, 255, -1) cv2.imshow("Circle Mask", mask) masked = cv2.bitwise_and(image, image, mask=mask) cv2.imshow("Circle Mask Applied to Image", masked) cv2.waitKey(0) except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() if Carl: runLog.logger.info("Finished") sleep(1)
def main(): lifeLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: # loop loopSleep = 1 # second loopCount = 0 keepLooping = True while keepLooping: loopCount += 1 image = cv2.imread(args["image"]) print("width: {} pixels".format(image.shape[1])) print("height: {} pixels".format(image.shape[0])) cv2.imshow("Image", image) # myimutils.display("Image", image, scale_percent=30) (b, g, r,) = image[0,0] print("Pixel at (0,0) - Red: {}, Green: {}, Blue: {}".format(r,g,b)) (b, g, r,) = image[219,90] print("Pixel at (x:90,y:219) - Red: {}, Green: {}, Blue: {}".format(r,g,b)) print("Setting Pixel at (0,0) to Red") image[0,0] = (0, 0, 255) (b, g, r,) = image[0,0] print("Pixel at (0,0) - Red: {}, Green: {}, Blue: {}".format(r,g,b)) corner = image[0:100, 0:100] cv2.imshow("Corner", corner) image[0:100, 0:100] = (0, 255, 0) cv2.imshow("Updated", image) cv2.waitKey(0) # cv2.imwrite("newimage.jpg", image) keepLooping = False sleep(loopSleep) except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() lifeLog.logger.info("Finished") sleep(1)
def main(): if Carl: lifeLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) if Carl: myconfig.setParameters(egpg) tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: keepLooping = True while keepLooping: # Create memory stream stream = io.BytesIO() # capture a frame from camera to the streem with picamera.PiCamera() as camera: # camera.resolution = (320, 240) camera.resolution = (640, 480) camera.capture(stream, format='jpeg') frame_time = datetime.datetime.now().strftime("%H:%M:%S.%f")[:12] # convert pic into numpy array buff = np.fromstring(stream.getvalue(), dtype=np.uint8) # create an OpenCV image image = cv2.imdecode(buff, 1) #myimutils.display("input",image) #cv2.waitKey(0) face_set = detect_faces(image) # myimutils.display("faces()", face_set[0],50 ) # 640x480 images cv2.imshow("faces()", face_set[0]) print("{}: faces() found {} faces".format(frame_time, len(face_set[1]))) for (x, y, w, h) in face_set[1]: print(" {}x{} face at ({},{})".format(h, w, x, y)) # wait time in ms: 500 to limit load, 1 to go as fast as possible (1 detect / sec) k = cv2.waitKey(1) if (k == 27): keepLooping = False cv2.destroyAllWindows() except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() if Carl: lifeLog.logger.info("Finished") sleep(1)
def main(): if Carl: runLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) if Carl: tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: image = cv2.imread(args["image"]) cv2.imshow("Original", image) # aspect ratio = new width over orig width r = 150 / image.shape[1] # new dimensions will be (new width, orig_height * aspect ratio) dim = (150, int(image.shape[0] * r)) resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA) cv2.imshow("Resized Width", resized) # aspect ratio = new height over orig height r = 50.0 / image.shape[0] # new dimesion = adjust width by aspect ratio dim = (int(image.shape[1] * r), 50) # Adrian says INTER_AREA is best resize interpolation type, lets try cubic resized = cv2.resize(image, dim, interpolation=cv2.INTER_CUBIC) cv2.imshow("Resized Height w/cubic", resized) resized = imutils.resize(image, width=100) cv2.imshow("imutils.resize width", resized) resized = imutils.resize(image, height=50) cv2.imshow("imutils.resize height w/area interp", resized) resized = imutils.resize(image, width=120, height=60) cv2.imshow("imutils.resize w120 h60", resized) cv2.waitKey(0) except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() if Carl: runLog.logger.info("Finished") sleep(1)
def main(): if Carl: runLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) if Carl: tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: #image = cv2.imread(args["image"]) #cv2.imshow("Original", image) rectangle = np.zeros((300, 300), dtype = "uint8") cv2.rectangle( rectangle, (25,25), (275,275), 255, -1) cv2.imshow("Rectangle", rectangle) circle = np.zeros((300,300), dtype = "uint8") cv2.circle(circle, (150,150), 150, 255, -1) cv2.imshow("Circle", circle) bitwiseAnd = cv2.bitwise_and(rectangle, circle) cv2.imshow("AND", bitwiseAnd) bitwiseOr = cv2.bitwise_or(rectangle,circle) cv2.imshow("OR", bitwiseOr) bitwiseXor = cv2.bitwise_xor(rectangle, circle) cv2.imshow("XOR", bitwiseXor) bitwiseNot = cv2.bitwise_not(circle) cv2.imshow("NOT", bitwiseNot) cv2.waitKey(0) except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() if Carl: runLog.logger.info("Finished") sleep(1)
def main(): if Carl: runLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) if Carl: tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: image = cv2.imread(args["image"]) #cv2.imshow("Original", image) (B, G, R) = cv2.split(image) cv2.imshow("Red", R) cv2.imshow("Green", G) cv2.imshow("Blue", B) merged = cv2.merge([B, G, R]) cv2.imshow("Merged", merged) cv2.waitKey(0) cv2.destroyAllWindows() zeros = np.zeros(image.shape[:2], dtype = "uint8") cv2.imshow("Red", cv2.merge([zeros, zeros, R])) cv2.imshow("Green", cv2.merge([zeros, G, zeros])) cv2.imshow("Blue", cv2.merge([B, zeros, zeros])) cv2.waitKey(0) cv2.destroyAllWindows() except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() if Carl: runLog.logger.info("Finished") sleep(1)
def main(): if Carl: runLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) if Carl: tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: image = cv2.imread(args["image"]) cv2.imshow("Original", image) print("max of 255: {}".format(cv2.add(np.uint8([200]), np.uint8([100])))) print("min of 0: {}".format(cv2.subtract(np.uint8([50]), np.uint8([100])))) print("wrap around: {}".format(np.uint8([200]) + np.uint8([100]))) print("wrap around: {}".format(np.uint8([50]) - np.uint8([100]))) M = np.ones(image.shape, dtype = "uint8") * 100 added = cv2.add(image, M) cv2.imshow("Added", added) M = np.ones(image.shape, dtype = "uint8") * 50 subtracted = cv2.subtract(image, M) cv2.imshow("Subtracted", subtracted) cv2.waitKey(0) except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() if Carl: runLog.logger.info("Finished") sleep(1)
def main(): if Carl: runLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) if Carl: tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: image = cv2.imread(args["image"]) cv2.imshow("Original", image) # Remember - np image arrays are [y,x] cropped = image[30:120, 240:335] cv2.imshow("T-Rex Face", cropped) cv2.waitKey(0) except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() if Carl: runLog.logger.info("Finished") sleep(1)
def main(): if Carl: lifeLog.logger.info("Started") egpg = easygopigo3.EasyGoPiGo3(use_mutex=True) if Carl: myconfig.setParameters(egpg) tiltpan.tiltpan_center() sleep(0.5) tiltpan.off() try: image_orig = cv2.imread(args["image"], 1) # test effect of smaller images (detect takes 3s on fullsize, <1s for 640x480) import imutils image = imutils.resize(image_orig, 640, 480) myimutils.display("input", image) cv2.waitKey(0) print(cv2.data.haarcascades) # but the data files are missing # Convert to grayscale gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Load a cascade file for detecting faces # face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml") # face_cascade = cv2.CascadeClassifier() # face_cascade.load('haarcascade_frontalface_default.xml') # full size: face1,3,4 good, face2 finds face and false face in floor # 640x480: face1,3,4 good, face2.jpg finds face and false face in floor face_cascade = cv2.CascadeClassifier( "/home/pi/Carl/Examples/OpenCV/opencv-3.4.4/data/haarcascades/haarcascade_frontalface_default.xml" ) # 640x480: finds in face1 and face2.jpg, fails face3 and face4 # fullsize:fails face1, ok in face2.jpg,face3 and 4 # face_cascade = cv2.CascadeClassifier("/home/pi/Carl/Examples/OpenCV/opencv-3.4.4/data/lbpcascades/lbpcascade_frontalface.xml") # full size: finds face in face1, 2, 3, and 4 # 640x480: finds face1, fails face2, 3, 4 # face_cascade = cv2.CascadeClassifier("/home/pi/Carl/Examples/OpenCV/opencv-3.4.4/data/lbpcascades/lbpcascade_frontalface_improved.xml") # Look for faces in the image using the loaded cascade file faces = face_cascade.detectMultiScale(gray, 1.1, 5) print("Found " + str(len(faces)) + " face(s) in resized image") # make a copy to draw on found = image # Draw a rectangle around every face found for (x, y, w, h) in faces: cv2.rectangle(found, (x, y), (x + w, y + h), (255, 0, 0), 2) # Save the result image # cv2.imwrite('faces_in_image_output.jpg',found) myimutils.display("faces", found) face_set = detect_faces(image_orig) myimutils.display("faces()", face_set[0]) print("faces() found {} faces".format(len(face_set[1]))) for (x, y, w, h) in face_set[1]: print(" {}x{} face at ({},{})".format(h, w, x, y)) k = cv2.waitKey(0) if k == 27: # Esc to kill everything cv2.destroyAllWindows() except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. if (egpg != None): egpg.stop() # stop motors print("\n*** Ctrl-C detected - Finishing up") sleep(1) if (egpg != None): egpg.stop() if Carl: lifeLog.logger.info("Finished") sleep(1)