Exemple #1
0
def main():
    import sys
    sys.path.remove('/opt/ros/kinetic/lib/python2.7/dist-packages'
                    )  # in order to import cv2 under python3
    import cv2
    sys.path.append('/opt/ros/kinetic/lib/python2.7/dist-packages'
                    )  # append back in order to import rospy

    # parse arguments
    args = parse_args()
    if args is None:
        exit()

    # open session
    tf_config = tf.ConfigProto()
    tf_config.gpu_options.allow_growth = True
    tf_config.allow_soft_placement = True
    with tf.Session(config=tf_config) as sess:
        gan = MUNIT(sess, args)

        # build graph
        gan.build_model()

        # show network architecture
        show_all_variables()

        if args.phase == 'train':
            # launch the graph in a session
            gan.train()
            print(" [*] Training finished!")

        if args.phase == 'test':
            gan.test()
            print(" [*] Test finished!")

        if args.phase == 'guide':
            gan.style_guide_test()
            print(" [*] Guide finished!")

        if args.phase == 'opencv':
            edge = np.zeros((256, 256, 3), dtype=np.uint8)
            sketcher = Sketcher('image', [edge], lambda:
                                ((255, 255, 255), 255))

            while True:
                key = cv2.waitKey()

                if key == ord('q'):
                    exit()
                if key == ord('r'):
                    edge[:] = np.zeros((256, 256, 3), dtype=np.uint8)
                    sketcher.show()
                if key == 32:  # hit spacebar
                    break

            results = gan.test_opencv(edge)
            print(" [*] Test finished!")

            cv2.imshow('result', results)
            cv2.waitKey(0)
Exemple #2
0
import os, sys

MODE = 'remove'  # 'remove', 'protect'
img_path = sys.argv[1]


def nothing(x):
    pass


img = cv2.imread(img_path, cv2.IMREAD_COLOR)
img_masked = img.copy()
mask = np.zeros(img.shape[:2], np.uint8)

sketcher = Sketcher('image', [img_masked, mask], lambda:
                    ((255, 255, 255), 255))

cv2.createTrackbar('width', 'image', img.shape[1], img.shape[1] * 2, nothing)
cv2.createTrackbar('height', 'image', img.shape[0], img.shape[0] * 2, nothing)

while True:
    key = cv2.waitKey()

    if key == ord('q'):  # quit
        break
    if key == ord('r'):  # reset
        print('reset')
        img_masked[:] = img
        mask[:] = 0
        sketcher.show()
    if key == 32:  # hit spacebar
from VideoAnalyzer import VideoAnalyzer
from Sketcher import Sketcher
import cv2

# input
model = cv2.imread('res/input/target.jpg')
video_name = 'res/input/video.mp4'
bullseye_point = (325,309)
inner_diameter_px = 50
inner_diameter_inch = 1.5
rings_amount = 6
display_in_cm = False

# get a sample frame from the video
cap = cv2.VideoCapture(video_name)
_, test_sample = cap.read()

# calculate the sizes of the frame and the input
model_h, model_w, _ = model.shape
frame_h, frame_w, _ = test_sample.shape
pixel_to_inch = inner_diameter_inch / inner_diameter_px
pixel_to_cm = pixel_to_inch * 2.54
measure_unit = pixel_to_cm if display_in_cm else pixel_to_inch
measure_unit_name = 'cm' if display_in_cm else '"'

# analyze
sketcher = Sketcher(measure_unit, measure_unit_name)
video_analyzer = VideoAnalyzer(video_name, model, bullseye_point, rings_amount, inner_diameter_px)
video_analyzer.analyze('res/output/output.mp4', sketcher)
# create the video capture.
video_capture = cv2.VideoCapture(0)

# initialize the correlation tracker.
tracker = dlib.correlation_tracker()

# this is the variable indicating whether to track the object or not.
tracked = False

cap = cv2.VideoCapture("video5.mp4")
ret, image = cap.read()
img_masked = image.copy()
mask = np.zeros(image.shape[:2], np.uint8)
point = []
sketcher=Sketcher('image', [img_masked, mask], lambda : ((255, 255, 255), 255), point)
cap.release()

# saving all points and find largest rectangle
while True:
    key = cv2.waitKey()
    if key == 32:
        print('processing')
        break
max_x = 0
max_y = 0
min_x = 9999
min_y = 9999
for pt in point:
    if max_x < pt[0] : max_x = pt[0]
    if max_y < pt[1] : max_y = pt[1]
Exemple #5
0
print('load model...')
model = PConvUnet(vgg_weights=None, inference_only=True)
model.load('data/logs/MyDataset_phase1/weights.75-0.51.h5', train_bn=False)
# model.summary()
import os
src = 'D:\git\crawler\zigbang\\test\class\\'
dest = 'images\\'
def random_pick(path):
  return os.listdir(path)[np.random.randint(0,len(os.listdir(path)))]
img = cv2.imread(os.path.join(src,random_pick(src)), cv2.IMREAD_COLOR)

img_masked = img.copy()
mask = np.zeros(img.shape[:2], np.uint8)

sketcher = Sketcher('image', [img_masked, mask], lambda : ((255, 255, 255), 255))
chunker = ImageChunker(512, 512, 30)

while True:
  key = cv2.waitKey()
  if key == ord('s'): #save
    sketcher.save_files(dest)
  if key == ord('c'):
    new_img = cv2.imread(os.path.join(src, random_pick(src)), cv2.IMREAD_COLOR)
    new_mask = np.zeros(new_img.shape[:2],np.uint8)
    sketcher.dests[0] = new_img
    sketcher.dests[1] = new_mask
    sketcher.show()
  if key == ord('q'): # quit
    break
  if key == ord('r'): # reset