amueller / gco_python

Python wrappers for GCO alpha-expansion and alpha-beta-swaps
136 stars 64 forks source link

Convert Python to C++ #24

Closed HyungJoo-Kwon closed 1 year ago

HyungJoo-Kwon commented 1 year ago

Hi, there I have question related to converting code. I want to use cut_from_graph in C++.

# Python

refine_labels = cut_from_graph(edges, unaries, pairwise)    #  edges (14956,3), unaries(9999, 15), pairwise (15, 15) 
refine_labels (9999,)
// C++ 
int edges[14956][3];
int unaries[9999][15];
int pairwise[15][15];
int *refined_labels = new int[9999];
GCoptimizationGeneralGraph *gc = new GCoptimizationGeneralGraph(9999, 15);

for (int i = 0; i < 14956; i++)
    gc->setNeighbors(edges[i][0], edges[i][1], edges[i][2]);
gc->setDataCost(*unaries);
gc->setSmoothCost(*pairwise);

gc->expansion(5);

for (int i = 0; i < decimated->GetNumberOfCells(); i++)
    refined_labels[i] = gc->whatLabel(i);

I stored edges, unaries, and pairwise in the same way as Python. And use cut_from_graph() in C++ using converting code that i refer to cut_from_graph() in gco_python.pyx The code was executed without error, but the result is not refine. Is it right to convert the code like this? Is there anything I missed or made a mistake ? Please give me some advice... Thanks !

HyungJoo-Kwon commented 1 year ago

i have mistake related to input data.. I solved it..