Skip to content

Instantly share code, notes, and snippets.

@srvanderplas
Last active February 1, 2019 14:08
Show Gist options
  • Save srvanderplas/a76b174d4a7296fde27088bade7a29bc to your computer and use it in GitHub Desktop.
Save srvanderplas/a76b174d4a7296fde27088bade7a29bc to your computer and use it in GitHub Desktop.
Stub of a function to get Hough Line information out of opencv in python
library(reticulate)
library(tidyverse)
library(stringr)
library(imager)
main <- import_main()
cv2 <- import("cv2", as = "cv2")
source_python("./inst/HoughLines.py")
chunk_edges <- list.files("inst/processed/slices/", pattern = "_edge", full.names = T)
tmp <- lapply(chunk_edges[1:100], calcHoughLines)
hist(tmp[[1]][,,2])
res <- map_df(1:length(tmp), ~data.frame(img=.x, link=chunk_edges[.x], thetas=tmp[[.x]][,,2]))
ggplot(data = res) + geom_density(aes(x = thetas)) + facet_wrap(~img)
plot(load.image(chunk_edges[1]))
import cv2
import numpy as np
def calcHoughLines(file):
img = cv2.imread(file)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
lines = cv2.HoughLines(edges,1,np.pi/180,15)
return lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment