graph-cut-ransac icon indicating copy to clipboard operation
graph-cut-ransac copied to clipboard

cpp_example test2DLineFitting can not get any line

Open githublqs opened this issue 3 years ago • 4 comments

my data generate code below: cv::Mat detected_edges(Size(640,480),CV_8UC1,Scalar(0)); cv::line(detected_edges, Point(detected_edges.cols / 4, detected_edges.rows / 4), Point(detected_edges.cols * 3 / 4, detected_edges.rows * 3 / 4), Scalar(255)); cv::Mat points(0, 2, CV_64F), point(1, 2, CV_64F); for (size_t row = 0; row < detected_edges.rows; row += 1) { for (size_t col = 0; col < detected_edges.cols; col += 1) { if (detected_edges.at(row, col) > std::numeric_limits::epsilon()) { point.at(0) = col; point.at(1) = row; points.push_back(point); } } } and the is output: Neighborhood calculation time = 0.001370 secs Elapsed time = 0.535391 secs Inlier number before = 0 Applied number of local optimizations = 0 Applied number of graph-cuts = 0 Number of iterations = 5000

githublqs avatar Sep 08 '21 17:09 githublqs

I can confirm that now, even after the linefitting procedure was exposed to public it still works very strange. I tried the recent version from master (as long as it is mentioned that line-fit procedure was merged) and experienced the following:

  1. SampleProject detects the line at least on adam1.png image
  2. Python bindings do not work: when I pass the points array as points.astype(float) it simply returns None, when I cast it to points.astype(int) it silently dies without any message.

My code looks like:

import pygcransac

h1, w1 = image1_orig.shape
line, mask = pygcransac.findLine2D(corners1.astype(int), w1, h1, threshold = 2.0, conf=0.99, max_iters=1000,
                                  spatial_coherence_weight = 0.8, min_inlier_ratio_for_sprt = 0.001,
                                  neighborhood_size = 20.0)
print(line)

mikoff avatar Oct 06 '21 11:10 mikoff

Dear All,

Yeah, I realized that I simply forgot to implement the C++ side of the Python binding. From C++, it works. From Python, it calls an empty function. I will solve this in a few days.

danini avatar Oct 06 '21 11:10 danini

@mikoff @danini for me python bindings work

However, one should run .astype(np.float64) and not float or int. Also, neighborhood_size is not there image

ducha-aiki avatar Oct 06 '21 11:10 ducha-aiki

@ducha-aiki On my side I tried .astype(np.float64) and still have None as output from the function (working with master branch). Nevertheless I figured out why jupyter kernel simply dies whenever I cast the the values to anything except int. If I uncomment the following line %config InlineBackend.figure_format='retina' it dies. If it is commented, I have None:

import pygcransac
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
#%config InlineBackend.figure_format='retina'

filename = 'grafA.png'

image1_orig = cv.imread(filename, 0)

det = cv.ORB_create(1000)
kp1 = det.detect(image1_orig)
corners = np.array([k.pt for k in kp1]).astype(np.float64)

h1, w1 = image1_orig.shape
line, mask = pygcransac.findLine2D(corners, w1, h1, threshold = 2.0, conf=0.99, max_iters=1000,
                                  spatial_coherence_weight = 0.8, min_inlier_ratio_for_sprt = 0.001)
print(line)

mikoff avatar Oct 06 '21 12:10 mikoff