def run_detection(in_fn, out_fn): img_color = cv2.imread(in_fn) img_gray = cv2.cvtColor(img_color, cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) rects = detect(img_gray) print "Copied " + in_fn + " to " + out_fn img_out = img_color.copy() draw_rects(img_out, rects, (0, 255, 0)) cv2.imwrite(out_fn, img_out)
def demo(in_fn, out_fn): img_color = cv2.imread(in_fn) img_gray = cv2.cvtColor(img_color, cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) #print in_fn, img_gray.shape #print ">>> Detecting faces..." rects = detect(img_gray) img_out = img_color.copy() draw_rects(img_out, rects, (0, 255, 0)) for x1,y1,x2,y2 in rects: img_out = img_out[(y1-80):(y2+80),(x1-50):(x2+50)] cv2.imwrite(out_fn, img_out)
def detectOnPict(in_fn, out_fn): '''draw the detection on a picture''' img_color = cv2.imread(in_fn) #get the gray level of the pict img_gray = cv2.cvtColor(img_color, cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) rects = detect(img_gray) img_out = img_color.copy() #Replace face with a picture trollImage = cv2.imread("trollface.png") for x1, y1, x2, y2 in rects: trollImage = cv2.resize(trollImage, (x2-x1, y2-y1)) img_out[y1:y1+trollImage.shape[0], x1:x1+trollImage.shape[1]] = trollImage cv2.imwrite(out_fn, img_out)
def demo(in_fn, out_fn): print ">>> Loading image..." img_color = cv2.imread(in_fn) img_gray = cv2.cvtColor(img_color, cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) print in_fn, img_gray.shape print ">>> Detecting faces..." start = time.time() rects = detect(img_gray) end = time.time() print 'time:', end - start img_out = img_color.copy() draw_rects(img_out, rects, (0, 255, 0)) cv2.imwrite(out_fn, img_out)
def detectOnPict(in_fn, out_fn): '''draw the detection on a picture''' img_color = cv2.imread(in_fn) #get the gray level of the pict img_gray = cv2.cvtColor(img_color, cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) rects = detect(img_gray) img_out = img_color.copy() #Replace face with a picture trollImage = cv2.imread("trollface.png") for x1, y1, x2, y2 in rects: trollImage = cv2.resize(trollImage, (x2 - x1, y2 - y1)) img_out[y1:y1 + trollImage.shape[0], x1:x1 + trollImage.shape[1]] = trollImage cv2.imwrite(out_fn, img_out)
def detectOnPict(in_fn, out_fn): '''draw the detection on a picture''' img_color = cv2.imread(in_fn) #get the gray level of the pict img_gray = cv2.cvtColor(img_color, cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) rects = detect(img_gray)#CF cv2_detect.py img_out = img_color.copy() #sys.argv[3] = image to overlay trollImage = cv2.imread(sys.argv[3]) for x1, y1, x2, y2 in rects: #Resize at the size of the face trollImage = cv2.resize(trollImage, (x2-x1, y2-y1)) #Overlay img_out[y1:y1+trollImage.shape[0], x1:x1+trollImage.shape[1]] = trollImage cv2.imwrite(out_fn, img_out)
def detectOnPict(in_fn, out_fn): '''draw the detection on a picture''' img_color = cv2.imread(in_fn) #get the gray level of the pict img_gray = cv2.cvtColor(img_color, cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) rects = detect(img_gray) #CF cv2_detect.py img_out = img_color.copy() #sys.argv[3] = image to overlay trollImage = cv2.imread(sys.argv[3]) for x1, y1, x2, y2 in rects: #Resize at the size of the face trollImage = cv2.resize(trollImage, (x2 - x1, y2 - y1)) #Overlay img_out[y1:y1 + trollImage.shape[0], x1:x1 + trollImage.shape[1]] = trollImage cv2.imwrite(out_fn, img_out)
def run_detection(): cap = cv2.VideoCapture(0) rects = None counter = 10 while(True): ret, frame = cap.read() img_gray = cv2.cvtColor(frame,cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) if(counter == 10): rects = detect(img_gray) counter = 0 counter = counter + 1 draw_rects(frame, rects, (0,255,0)) cv2.imshow('feed',frame) if cv2.waitKey(1) & 0xFF == ord('q'): break # When everything done, release the capture cap.release() cv2.destroyAllWindows()
def faces(in_fn, out_dir): print ">>> Loading image..." #time.sleep(0.2) img_color = cv2.imread(in_fn) img_gray = cv2.cvtColor(img_color, cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) print ">>> Detecting faces in " + in_fn rects = detect(img_gray) print "faces detected: ", len(rects) if not len(rects) == 0: if not os.path.exists(out_dir): os.makedirs(out_dir) if not out_dir.endswith("/"): out_dir = out_dir + "/" img_out = img_color.copy() draw_rects(img_out, rects, (0, 255, 0)) cv2.imwrite(out_dir + in_fn, img_out) else: miss_file = "miss/" if not os.path.exists(miss_file): os.makedirs(miss_file) cv2.imwrite(miss_file + in_fn, img_color)
def faces(in_fn, out_dir): print ">>> Loading image..." #time.sleep(0.2) img_color = cv2.imread(in_fn) img_gray = cv2.cvtColor(img_color, cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) print ">>> Detecting faces in "+in_fn rects = detect(img_gray) print "faces detected: ", len(rects) if not len(rects)==0: if not os.path.exists(out_dir): os.makedirs(out_dir) if not out_dir.endswith("/"): out_dir=out_dir+"/" img_out = img_color.copy() draw_rects(img_out, rects, (0, 255, 0)) cv2.imwrite(out_dir+in_fn, img_out) else: miss_file="miss/" if not os.path.exists(miss_file): os.makedirs(miss_file) cv2.imwrite(miss_file+in_fn, img_color)
print("FAILED: {0}".format(e)) return id, vol, page, imgno, identifier, title, author, pubplace, publisher, guesseddate, decoded, tags, filename if __name__ == "__main__": if len(sys.argv) == 2: suggested_img = sys.argv[1] if r.sismember("images", "/static/e/"+suggested_img): print("Using '{0}'".format(suggested_img)) filename = suggested_img.split("/")[1] id, vol, page, imgno, identifier, title, author, pubplace, publisher, guesseddate, decoded, tags, filename = post_not_so_random_image("/static/e/"+suggested_img) else: id, vol, page, imgno, identifier, title, author, pubplace, publisher, guesseddate, decoded, tags, filename = post_not_so_random_image() try: img = cv2.imread(os.path.join(root, guesseddate, filename)) rectlist, hit = detect(img, minSize=(60,60), scaleFactor=1.3, minNeighbors=5) if hit: for match in rectlist.keys(): if rectlist[match] != []: rect = rectlist[match].tolist() orientation, haar = match.split("_") tag = "" if orientation == "r": tag += "sideways_" rect = [[ rect[0][1], img.shape[1] - rect[0][0], rect[0][3], img.shape[1] - rect[0][2] ]] tag += haar+"_detected"+rect_to_tag(rectlist[match]) tags.append(tag) except KeyError: print("Whoops") caption = generate_caption(vol, decoded)
#On est au centre center_face_pub.publish("Centre") def demo(data): global bridge try : img_color = bridge.imgmsg_to_cv(data,"bgr8") img_color = np.asarray(img_color) except CvBridgeError, e: print e img_gray = cv2.cvtColor(img_color, cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) print ">>> Detecting faces..." start = time.time() rects = detect(img_gray) end = time.time() print start-end draw_rects(img_color, rects, (0, 255, 0)) # cv2.imshow("img",img_color) # cv.WaitKey(3) def main(): try : rospy.init_node("TestFace",anonymous=True) image_sub = rospy.Subscriber("/camera/rgb/image_color",Image, demo) cv.NamedWindow("img", 1) while not rospy.is_shutdown(): rospy.sleep(2); except rospy.ROSInterruptException:
if __name__ == "__main__": if len(sys.argv) == 2: suggested_img = sys.argv[1] if r.sismember("images", "/static/e/" + suggested_img): print("Using '{0}'".format(suggested_img)) filename = suggested_img.split("/")[1] id, vol, page, imgno, identifier, title, author, pubplace, publisher, guesseddate, decoded, tags, filename = post_not_so_random_image( "/static/e/" + suggested_img) else: id, vol, page, imgno, identifier, title, author, pubplace, publisher, guesseddate, decoded, tags, filename = post_not_so_random_image( ) try: img = cv2.imread(os.path.join(root, guesseddate, filename)) rectlist, hit = detect(img, minSize=(60, 60), scaleFactor=1.3, minNeighbors=5) if hit: for match in rectlist.keys(): if rectlist[match] != []: rect = rectlist[match].tolist() orientation, haar = match.split("_") tag = "" if orientation == "r": tag += "sideways_" rect = [[ rect[0][1], img.shape[1] - rect[0][0], rect[0][3], img.shape[1] - rect[0][2] ]] tag += haar + "_detected" + rect_to_tag(rectlist[match]) tags.append(tag)