{"id":28092400,"url":"https://github.com/rayryeng/xiaohuluvpdetection","last_synced_at":"2025-10-27T17:05:23.250Z","repository":{"id":45469737,"uuid":"178946973","full_name":"rayryeng/XiaohuLuVPDetection","owner":"rayryeng","description":"This is a Python + OpenCV implementation of the Vanishing Point algorithm by Xiaohu Lu et al. - http://xiaohulugo.github.io/papers/Vanishing_Point_Detection_WACV2017.pdf","archived":false,"fork":false,"pushed_at":"2023-06-26T17:38:57.000Z","size":98,"stargazers_count":140,"open_issues_count":0,"forks_count":29,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T15:50:22.020Z","etag":null,"topics":["computer-vision","image-processing","line-detection","opencv","python","rotation-matrix","vanishing-points"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rayryeng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-01T21:06:08.000Z","updated_at":"2025-03-06T12:22:05.000Z","dependencies_parsed_at":"2024-11-14T18:45:41.504Z","dependency_job_id":null,"html_url":"https://github.com/rayryeng/XiaohuLuVPDetection","commit_stats":{"total_commits":21,"total_committers":3,"mean_commits":7.0,"dds":0.4285714285714286,"last_synced_commit":"29e961290e96688f68edda7580d677a5cc445fd7"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rayryeng%2FXiaohuLuVPDetection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rayryeng%2FXiaohuLuVPDetection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rayryeng%2FXiaohuLuVPDetection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rayryeng%2FXiaohuLuVPDetection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rayryeng","download_url":"https://codeload.github.com/rayryeng/XiaohuLuVPDetection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253948441,"owners_count":21988957,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","image-processing","line-detection","opencv","python","rotation-matrix","vanishing-points"],"created_at":"2025-05-13T13:11:24.472Z","updated_at":"2025-10-27T17:05:23.170Z","avatar_url":"https://github.com/rayryeng.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XiaohuLuVPDetection\nThis is a Python + OpenCV implementation of the Vanishing Point algorithm by Xiaohu Lu et al. - http://xiaohulugo.github.io/papers/Vanishing_Point_Detection_WACV2017.pdf\n\n# Requirements\n* Python \u003e= 3.8\n* OpenCV Contrib 4.x\n* NumPy\n\n# Setup\n\n## Method #1 - Cloning this repo and installing locally\n\nSimply clone this repo, then run the included `setup.py` file to get it to install onto your local machine:\n\n```\n$ python setup.py build\n$ python setup.py install\n```\n\n## Method #2 - Through PyPI\n\nThis project is now available through PyPI: https://pypi.org/project/lu-vp-detect/\n\nIf don't want to clone this repo, you can simply use `pip install` to install this project on your system.\n\n```\n$ pip install lu-vp-detect\n```\n\n## After installation\n\nThe `lu_vp_detect` package should be installed at this point which will\ncontain the implementation of the algorithm as well as a command-line test\nscript to test out the algorithm.\n\n# How to use\n\nThe main detection algorithm is written in the `lu_vp_detect` package and is\nimplemented in the file `vp_detection.py`.  The `VPDetection` class is what\nis required and there are two methods of interest in the class:\n\n* `find_vps`: Finds the vanishing points in normalized 3D space\n* `create_debug_VP_image`: Creates a debug image for showing which\ndetected lines in the image align with each vanishing point.\n\nThe main parameters for affecting performance are:\n\n* `length_thresh`: The minimum length of the lines detected to find the\nvanishing points\n* `principal_point`: The principal point of the camera that took the image\n(in pixels).  The default is to assume the image centre.\n* `focal_length`: The focal length of the camera (in pixels).  The default\nis 1500.\n* `seed`: An optional integer ID that specifies the seed for reproducibility\nas part of the algorithm uses RANSAC.  Default is `None` so no seed is used.\n\nSimply create a `VPDetection` object with the desired parameters and run the\ndetection algorithm with the desired image.  You can read in the image yourself\nor you can provide a path to the image.  Note that the returned vanishing\npoints will be a 3 x 3 NumPy array such that the first row corresponds to the\nvanishing point appearing to the right of the image, the second row\ncorresponds to the vanishing point appearing to the left of the image and the\nlast row corresponding to the vertical vanishing point:\n\n```python\nfrom lu_vp_detect import VPDetection\nlength_thresh = ... # Minimum length of the line in pixels\nprincipal_point = (...,...) # Specify a list or tuple of two coordinates\n                            # First value is the x or column coordinate\n                            # Second value is the y or row coordinate\nfocal_length = ... # Specify focal length in pixels\nseed = None # Or specify whatever ID you want (integer)\n\nvpd = VPDetection(length_thresh, principal_point, focal_length, seed)\n\nimg = '...' # Provide a path to the image\n# or you can read in the image yourself\n# img = cv2.imread(path_to_image, -1)\n\n# Run detection\nvps = vpd.find_vps(img)\n\n# Display vanishing points\nprint(vps)\n\n# You can also access the VPs directly as a property\n# Only works when you run the algorithm first\n# vps = vpd.vps\n\n# You can also access the image coordinates for the vanishing points\n# Only works when you run the algorithm first\n# vps_2D = vpd.vps_2D\n```\n\nYou can optionally create a debug image that shows which detected lines align\nwith which vanishing point in the image.  They are colour coded so that each\nunique colour corresponds to the lines that provide support for a vanishing\npoint.  Lines that are black correspond to \"outlier\" lines, meaning that they\ndid not contribute any information in calculating any vanishing points.\n\n```python\n# Create debug image\nvpd.create_debug_VP_image(show_image=True, save_image='./path/to/debug.png')\n```\n\nThe `show_image` flag will open a OpenCV `imshow` window that will display the\nimage.  The `save_image` if it's not set to `None` will write the corresponding\nimage to file.  Of course, different combinations of the input variables will\nallow you to customize what outputs you want to consume or save.\n\n# Command-line test script\n\nThe `run_vp_detect.py` file is a command-line script that uses `argparse` to\ntake in the parameters from the command-line, runs the algorithm and shows\nthe vanishing points in both 3D normalised space and 2D image coordinate space\nin the console.  You can additionally show the debug image and save the debug\nimage to file by setting the right parameters.\n\n```\n$ run_vp_detect -h\nusage: run_vp_detect [-h] -i IMAGE_PATH [-lt LENGTH_THRESH]\n                     [-pp PRINCIPAL_POINT PRINCIPAL_POINT] [-f FOCAL_LENGTH]\n                     [-d] [-ds] [-dp DEBUG_PATH] [-s SEED]\n\nMain script for Lu's Vanishing Point Algorithm\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -i IMAGE_PATH, --image-path IMAGE_PATH\n                        Path to the input image\n  -lt LENGTH_THRESH, --length-thresh LENGTH_THRESH\n                        Minimum line length (in pixels) for detecting lines\n  -pp PRINCIPAL_POINT PRINCIPAL_POINT, --principal-point PRINCIPAL_POINT PRINCIPAL_POINT\n                        Principal point of the camera (default is image\n                        centre)\n  -f FOCAL_LENGTH, --focal-length FOCAL_LENGTH\n                        Focal length of the camera (in pixels)\n  -d, --debug           Turn on debug image mode\n  -ds, --debug-show     Show the debug image in an OpenCV window\n  -dp DEBUG_PATH, --debug-path DEBUG_PATH\n                        Path for writing the debug image\n  -s SEED, --seed SEED  Specify random seed for reproducible results\n```\n\nTake note that the principal point requires two arguments so you can\nseparate the `x` and `y` coordinate by a space.\n\n# Example running of the script\n\nA sample image was extracted from [TinyHomes.ie](https://tinyhomes.ie),\nspecifically this image: [https://www.tinyhomes.ie/wp-content/uploads/2015/09/02.jpg](https://www.tinyhomes.ie/wp-content/uploads/2015/09/02.jpg).\nIt is saved as `test_image.jpg` in this repository.\n\nThe image has been reduced down to 1/4 of the resolution for ease.\nThe new image has dimensions of `968 x 648`.  The image was originally\ntaken with a Nikon D40X whose focal length is 18 mm and the CCD width is\n15.8 mm.  Therefore, the estimated focal length should be:\n\n`968 x (18 / 15.8) = 1102.79 pixels`\n\nTo test the algorithm and reproduce the results below, set the\nseed to be 1337 and set the minimum line length to be 60 pixels.  Also,\nset the focal length to be what was computed above.  The principal\npoint is assumed to be the centre of the image.\n\n`$ run_vp_detect -i ./test_image.jpg -f 1102.79 -s 1337 -ds -lt 60`\n\nFor completeness, to do this programmatically:\n\n```python\nfrom lu_vp_detect import VPDetection\nlength_thresh = 60\nprincipal_point = None\nfocal_length = 1102.79\nseed = 1337\n\nimg = './test_image.jpg'\n\nvpd = VPDetection(length_thresh, principal_point, focal_length, seed)\nvps = vpd.find_vps(img)\nprint(vps) # 3D vanishing points\nprint(vpd.vps_2D) # 2D vanishing points\n```\n\nWe get the following output and debug image:\n\n```\nInput path: ./test_image.jpg\nSeed: 1337\nLine length threshold: 60.0\nFocal length: 1102.79\nPrincipal point: [484. 324.]\nThe vanishing points in 3D space are:\nVanishing Point 1: [0.3774699  0.01993015 0.92580736]\nVanishing Point 2: [-0.9260219   0.00812403  0.37738246]\nVanishing Point 3: [-0.         -0.9997684   0.02152233]\n\nThe vanishing points in image coordinates are:\nVanishing Point 1: [933.6292 347.7401]\nVanishing Point 2: [-2222.0286   347.7401]\nVanishing Point 3: [   484.    -50903.473]\nCreating debug image and showing to the screen\n```\n![](https://i.imgur.com/svI8tSC.png)\n\n# License\n\nThis code is currently distributed under the MIT license.  Please modify and\nuse the code as you see fit.  I only ask that you not only include this\nlicense as part of your work but to please acknowledge where you got this\nwork from!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frayryeng%2Fxiaohuluvpdetection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frayryeng%2Fxiaohuluvpdetection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frayryeng%2Fxiaohuluvpdetection/lists"}