Ejemplo n.º 1
0
def getImage(num):
    # ラズパイで画像が保存されている場所
    url = "http://49.135.3.100/~pi/python/images/annotation/"
    # ジングルベルはクラス数9個のため、9種類の連番ディレクトリを作成する
    for i in range(10):
        # 画像の保存フォルダ名
        images_dir = "Images/" + "{:03}".format(i + 1)
        os.makedirs(images_dir, exist_ok=True)
        # 取得画像のurl
        imageurl = url + num + ".jpg"
        # 元画像を保存するパス
        fileOrigin = "Images/original/" + num + ".jpg"
        # 変換後の画像を保存する相対パス
        filename = make_filename(images_dir, num, imageurl)
        # 画像をダウンロード
        image = download_image(imageurl)
        # 初回だけ元画像を保存
        if (i == 0):
            os.makedirs("Images/original", exist_ok=True)
            save_image(fileOrigin, image)
            print("saved original " + num + ".jpg in Images/original/")
        #グレイスケールで読み込み
        img = cv2.imread(fileOrigin, 0)
        # 歪み補正と直線補正
        img_tr = image_transform.image_transform(img)
        # 適応的2値化
        img_two = cv2.adaptiveThreshold(img_tr, 255,
                                        cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                        cv2.THRESH_BINARY, 11, 2)
        img_two = cv2.cvtColor(img_two, cv2.COLOR_GRAY2RGB)
        #切り出し
        img_two = img_two[300:600, 200:600]
        #2倍に拡大
        img_two = cv2.resize(img_two, None, fx=2, fy=2)
        cv2.imwrite(filename, img_two)
        print("saved two value " + num + ".jpg in " + images_dir)
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-
import image_transform
import image
import os
import sys
import signal
import cv2

# グレイスケールで読み込む
raw = cv2.imread("slide_image/3.jpg", 0)
cv2.imwrite("slide_image/raw.jpg", raw)
# 歪み補正と直線補正
warp = image_transform.image_transform(raw)
cv2.imwrite("slide_image/warp.jpg", warp)
# 切り出し
cut = warp[300:600, 200:600]
cv2.imwrite("slide_image/cut.jpg", cut)
# 2倍に拡大
enlarge = cv2.resize(cut, None, fx=2, fy=2)
cv2.imwrite("slide_image/enlarge.jpg", enlarge)
# 適応的2値化
binary = cv2.adaptiveThreshold(enlarge, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                               cv2.THRESH_BINARY, 11, 2)
binary = cv2.cvtColor(binary, cv2.COLOR_GRAY2RGB)
cv2.imwrite("slide_image/binary.jpg", binary)
Ejemplo n.º 3
0
 if (i == 0):
     #動く
     move.move()
 if (i == N-1):
     #止まる
     move.stop()
 """
 '''
 # グレイスケールで読み込む
 #img = cv2.imread("images/0.jpg",0)
 img = cv2.imread(
     "/home/sfc_kamata/work/BBox-Label-Tool/Images/original/test_" +
     str(i + 1) + ".jpg", 0)
 print('image read %f' % (time.time() - start_time))
 # 歪み補正と直線補正
 img_tr = image_transform.image_transform(img)
 print('transform %f' % (time.time() - start_time))
 # 適応的2値化
 img_two = cv2.adaptiveThreshold(img_tr, 255,
                                 cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                 cv2.THRESH_BINARY, 11, 2)
 img_two = cv2.cvtColor(img_two, cv2.COLOR_GRAY2RGB)
 print('cvt color %f' % (time.time() - start_time))
 # 切り出し
 img_two = img_two[300:600, 200:600]
 # 2倍に拡大
 img_two = cv2.resize(img_two, None, fx=2, fy=2)
 # 認識
 detectionResults = detectMusic.yoloDetect_net(img_two, net)
 print('detection %f' % (time.time() - start_time))
 #detectionResults = detectMusic.yoloDetect(img_two)
Ejemplo n.º 4
0
## saved in GPU -> load in CPU
# load_weights = torch.load(load_path, map_location={"cuda:0": "cpu"})

net.load_state_dict(load_weights)

## input
img_rootpath = "./dataset_lion_tiger"
file_type = "jpg"
val_list = make_datapath_list.make_datapath_list(img_rootpath,
                                                 file_type,
                                                 phase="val")

size = 224  #VGG16
mean, std = compute_images_mean_std.compute_images_mean_std(
    "./dataset_lion_tiger/train", "jpg", resize=size)
transform = image_transform.image_transform(size, mean, std)

## predict(0: lion, 1:tiger)
plt.figure()
i = 0
h = 4
w = 5

for img_path in val_list:
    img = Image.open(img_path)
    img_trasformed = transform(img)
    inputs = img_trasformed.unsqueeze_(0)
    outputs = net(inputs)
    predict_id = np.argmax(outputs.detach().numpy())
    predict_name = ""
    print(outputs)
Ejemplo n.º 5
0
filenames = os.listdir(source_path)
for filename in filenames:
    print(filename)
    if filename.endswith('0.bmp'):
        
        source_image_path = os.path.join(source_path, filename)
        img = cv2.imread(source_image_path)  #move below source_image_path to enable file location elsewhere than main
        rect = crop.cropping_points2(img)
        print(rect)
        if not np.any(rect):
                print('no save')
                os.remove(source_image_path)
                continue
        # print(rect)
        small_image = transform.image_transform(img, dest_path, rect)
        # print(small_image_path)
        # cv2.imshow('small' , small_image)
        answer = simpledialog.askstring("Input", "1: OK\n 2:Seaweed \n 3: Other issue\n 4: Faulty cropping-dont save\n 5:Quit", parent=application_window)
        if answer == '5':
                exit()
        elif answer == '4':
                continue
        # cv2.waitKey(0)
        
        small_image_name = filename[0:14]+'.'+answer+'.jpg'
        small_image_path = os.path.join(dest_path, small_image_name) 
        os.remove(source_image_path)
        print(small_image_path)
        print('source: ', source_image_path)
        cv2.imshow('small' , small_image)