2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

がちもとさんAdvent Calendar 2022

Day 25

Vanishing Point Detectionの導入(Python 3.6、Windows 10)

Last updated at Posted at 2022-12-25

はじめに

消失点の検出を行います

開発環境

  • Windows10 PC
  • Python 3

導入

1.ライブラリをインストールします

pip install lu-vp-detect

2.OpenCVのバージョンが変わってしまうので注意(opencv-contrib-python==4.0.0.21)、4.5でやってみましたがLSDのエラーが出ました

3.プログラムの実行

extract_vps.py
import os
import numpy as np
import cv2
import argparse

from concurrent.futures import ProcessPoolExecutor
from multiprocessing import cpu_count
import tqdm
from functools import partial
import matplotlib.pyplot as plt
from PIL import Image
from lu_vp_detect import VPDetection

CROP=16
do_flip = False
cameraMatrix = [525.0, 0.0, 319.50, 0.0, 525.0, 239.50, 0.0, 0.0, 1.0]
length_thresh = 60

def extract_vps(filename, index):
    # image = pil_loader(filename)
    # im_name = filename.split('/')[-1].split('.')[0]
    # image = undistort(image)
    image = cv2.imread(filename)
    h, w, c = image.shape
    image = image[CROP : h-CROP, CROP : w-CROP]
    image = cv2.resize(image, (384,288))
    # flip
    if do_flip:
        image = cv2.flip(image, 1)

    fx = cameraMatrix[0]/(640-2*CROP)*384
    fy = cameraMatrix[4]/(480-2*CROP)*288
    cx = (cameraMatrix[2] - CROP)/(640-2*CROP)*384
    cy = (cameraMatrix[5]- CROP)/(480-2*CROP)*288
    # flip
    if do_flip:
        cx = 384 - cx
    principal_point = cx, cy
    # about how to choose fx or fy, the author's answer is https://github.com/rayryeng/XiaohuLuVPDetection/issues/4
    focal_length = fx
    seed = 2020
    vpd = VPDetection(length_thresh, principal_point, focal_length, seed)
    vps = vpd.find_vps(image) 
    #assert np.isnan(vps).all() == False, print(vps)
    #vpd.create_debug_VP_image(show_image=False, save_image='vps_vis_25/{}.jpg'.format(index)) 
    vps = np.vstack([vps, -vps]).astype(np.float32)

    return vps

filename = "fr3_long_office/1341847980.722988.png"
vps = extract_vps(filename, 0)
print(vps)
[[ 0.29538336  0.02425744  0.95507085]
 [-0.9435459  -0.14944299  0.29561457]
 [-0.14989948  0.98847276  0.02125496]
 [-0.29538336 -0.02425744 -0.95507085]
 [ 0.9435459   0.14944299 -0.29561457]
 [ 0.14989948 -0.98847276 -0.02125496]]
Input VPs
1341847980.722988.png 1341847980.722988.jpg

お疲れ様でした。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?