Git Product home page Git Product logo

gslicr's Introduction

gSLICr: SLIC superpixels at over 250Hz

sample

This is the software bundle "gSLICr", a library for real-time superpixel segmentation written in C++ and CUDA. The current version is maintained by:

Carl Yuheng Ren : [email protected]
Victor Adrian Prisacariu : [email protected]
Ian D Reid : [email protected]

For more information about gSLICr please visit the project website http://www.robots.ox.ac.uk/~victor/gslicr.

Other related projects can be found in the Oxford Active Vision Library http://www.oxvisionlib.org.

1. Updates from gSLIC

  • Works for any size / number of super pixels
  • With GTX Titan X, 3.4ms@640x480, 12ms@1280x960, 20ms@1920x1080 image
  • Multi-platform supported
    • Win8 Visual Studio
    • Ubuntu 14.04
    • Mac OSX 10.10

2. Building the System

2.1 Requirements

Several 3rd party libraries are needed for compiling gSLICr. The given version numbers are checked and working, but different versions might be fine as well. Some of the libraries are optional, and skipping them will reduce functionality.

2.2 Build Process

To compile the system, use the standard cmake approach:

  $ mkdir build
  $ cd build
  $ cmake /path/to/gSLICr
  $ make

To run demo:

  • plug in a webcam
  • use the standard cmake approach:
mkdir build
cd build
cmake ../
make
./demo
  • press s to save current segmentation result to current folder.

3. What to cite

If you use this code for your research, please kindly cite:

@article{gSLICr_2015,
	author = {{Ren}, C.~Y and {Prisacariu}, V.~A. and {Reid}, I.~D},
	title = "{gSLICr: SLIC superpixels at over 250Hz}",
	journal = {ArXiv e-prints},
	eprint = {1509.04232},
	year = 2015,
	month = sep
}

arxiv linke

gslicr's People

Contributors

bittnt avatar bryant1410 avatar carlren avatar cyren avatar jhjin avatar np-csu avatar varunjampani avatar victorprad avatar yuhengren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gslicr's Issues

cudaSafeCall() Runtime API error : no CUDA-capable device is detected.

I'm using Ubuntu 16.04 machine and I've successfully build the code here, but I failed to run command ./demo, where I got the error:

/home/ee303/WORKSPACE/Super-pixels/gSLICr/gSLICr_Lib/engines/../../ORUtils/MemoryBlock.h(196) : cudaSafeCall() Runtime API error : no CUDA-capable device is detected.

My dependencies:

  • Ubuntu 16.04
  • Cmake 3.5.1
  • Cuda 9.1
  • OpenCV 3.4.0

Additionally, here's the output of cmake command:

ee303@ee303-All-Series:~/WORKSPACE/Super-pixels/gSLICr/build$ cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found CUDA: /usr/local/cuda-9.1 (found version "9.1") 
-- Found OpenCV: /usr/local (found version "3.4.0") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ee303/WORKSPACE/Super-pixels/gSLICr/build

And here is the output of make command:

ee303@ee303-All-Series:~/WORKSPACE/Super-pixels/gSLICr/build$ make -j8
[ 12%] Building NVCC (Device) object CMakeFiles/gSLICr_lib.dir/gSLICr_Lib/engines/gSLICr_lib_generated_gSLICr_seg_engine_GPU.cu.o
Scanning dependencies of target ORUtils
[ 25%] Building CXX object ORUtils/CMakeFiles/ORUtils.dir/Dummy.cpp.o
[ 37%] Linking CXX static library libORUtils.a
[ 37%] Built target ORUtils
/home/ee303/WORKSPACE/Super-pixels/gSLICr/gSLICr_Lib/engines/gSLICr_seg_engine_GPU.cu(228): warning: __shared__ memory variable with non-empty constructor or destructor (potential race between threads)

/home/ee303/WORKSPACE/Super-pixels/gSLICr/gSLICr_Lib/engines/gSLICr_seg_engine_GPU.cu(229): warning: __shared__ memory variable with non-empty constructor or destructor (potential race between threads)

Scanning dependencies of target gSLICr_lib
[ 62%] Building CXX object CMakeFiles/gSLICr_lib.dir/gSLICr_Lib/engines/gSLICr_core_engine.cpp.o
[ 62%] Building CXX object CMakeFiles/gSLICr_lib.dir/gSLICr_Lib/engines/gSLICr_seg_engine.cpp.o
/home/ee303/WORKSPACE/Super-pixels/gSLICr/gSLICr_Lib/engines/gSLICr_seg_engine.cpp:3:9: warning: #pragma once in main file
 #pragma once
         ^
/home/ee303/WORKSPACE/Super-pixels/gSLICr/gSLICr_Lib/engines/gSLICr_core_engine.cpp:3:9: warning: #pragma once in main file
 #pragma once
         ^
[ 75%] Linking CXX static library libgSLICr_lib.a
[ 75%] Built target gSLICr_lib
Scanning dependencies of target demo
[ 87%] Building CXX object CMakeFiles/demo.dir/demo.cpp.o
[100%] Linking CXX executable demo
[100%] Built target demo

So what have been wrong?

TensorFlow op

are there any plans to integrate this code with TensorFlow as an op? It would be great to easily mix SLIC into deep learning workflows.

Build failing with error: ‘memcpy’ was not declared in this scope

Ubuntu 16.04 build fails with the following output

/usr/include/string.h: In function ‘void* __mempcpy_inline(void*, const void*, size_t)’:
/usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
return (char *) memcpy (__dest, __src, __n) + __n;
^
CMake Error at gSLICr_lib_generated_gSLICr_seg_engine_GPU.cu.o.cmake:266 (message):
Error generating file
/home/paperspace/gSLICr/build/CMakeFiles/gSLICr_lib.dir/gSLICr_Lib/engines/./gSLICr_lib_generated_gSLICr_seg_engine_GPU.cu.o

CMakeFiles/gSLICr_lib.dir/build.make:265: recipe for target 'CMakeFiles/gSLICr_lib.dir/gSLICr_Lib/engines/gSLICr_lib_generated_gSLICr_seg_engine_GPU.cu.o' failed
make[2]: *** [CMakeFiles/gSLICr_lib.dir/gSLICr_Lib/engines/gSLICr_lib_generated_gSLICr_seg_engine_GPU.cu.o] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/gSLICr_lib.dir/all' failed
make[1]: *** [CMakeFiles/gSLICr_lib.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

when local_id<32 , the code is different from local_id < 64;

Each SM splits its own blocks into Warps (currently with a maximum size of 32 threads).

All the threads in a warp executes concurrently on the resources of the SM ?

__syncthreads();
	if (should_add)
	{
		if (local_id < 128)
		{
			color_shared[local_id] += color_shared[local_id + 128];
			xy_shared[local_id] += xy_shared[local_id + 128];
			count_shared[local_id] += count_shared[local_id + 128];
		}
		__syncthreads();

		if (local_id < 64)
		{
			color_shared[local_id] += color_shared[local_id + 64];
			xy_shared[local_id] += xy_shared[local_id + 64];
			count_shared[local_id] += count_shared[local_id + 64];
		}
		__syncthreads();

		if (local_id < 32)
		{
			color_shared[local_id] += color_shared[local_id + 32];
			color_shared[local_id] += color_shared[local_id + 16];
			color_shared[local_id] += color_shared[local_id + 8];
			color_shared[local_id] += color_shared[local_id + 4];
			color_shared[local_id] += color_shared[local_id + 2];
			color_shared[local_id] += color_shared[local_id + 1];

			xy_shared[local_id] += xy_shared[local_id + 32];
			xy_shared[local_id] += xy_shared[local_id + 16];
			xy_shared[local_id] += xy_shared[local_id + 8];
			xy_shared[local_id] += xy_shared[local_id + 4];
			xy_shared[local_id] += xy_shared[local_id + 2];
			xy_shared[local_id] += xy_shared[local_id + 1];

			count_shared[local_id] += count_shared[local_id + 32];
			count_shared[local_id] += count_shared[local_id + 16];
			count_shared[local_id] += count_shared[local_id + 8];
			count_shared[local_id] += count_shared[local_id + 4];
			count_shared[local_id] += count_shared[local_id + 2];
			count_shared[local_id] += count_shared[local_id + 1];
		}
	}
__syncthreads();
__syncthreads();
		if (local_id < 32)
		{
			color_shared[local_id] += color_shared[local_id + 32];
			xy_shared[local_id] += xy_shared[local_id + 32];
			count_shared[local_id] += count_shared[local_id + 32];
		}
__syncthreads();
if (local_id < 16)
		{
			color_shared[local_id] += color_shared[local_id + 16];
			xy_shared[local_id] += xy_shared[local_id + 16];
			count_shared[local_id] += count_shared[local_id + 16];
		}
__syncthreads();

Retrieve super pixels as cv::Contours

how can you retreive the super pixels as cv::contours? or some data structure similar, so that you can then further process each super pixel individually

why the demo gives three copies of image

In the demo, why the following code gives me a segmentation image with three copies??

load_image(out_img, boundry_draw_frame);
		imshow("segmentation", boundry_draw_frame);

edge_0000

And the following code can't save the image to pgm. It only gives a black image as following, is there something wrong?

sprintf(out_name, "seg_%04i.pgm", save_count);	gSLICr_engine->Write_Seg_Res_To_PGM(out_name);

GPU Memory Leak

There appears to be a memory leak on the GPU using the code you've provided. After processing about 2000 images, my 12GB Titan X ran out of memory. I was able to watch it fill up with sequential nvidia-smi calls too. It looks like the image memory is both duplicated is never destroyed on the GPU, but I'm not quite sure where in the code that ought to occur.

My C++ segmenting function is below. As it's the only GPU code, your seg_engine ought to be what's causing the leak, but I'm not sure why that's happening. As you can see at the end of my function, I am explicitly calling the destructor on the core_engine which destroys the seg_engine as well.

void ImageSLICSegmenter::segmentImage(const std::string &input_path, const std::string &output_path)
{
	cv::Mat old_frame = cv::imread(input_path);
	
	if (!old_frame.data){ EXCEPTION_THROWER(Util::Exception::IOException, "Error loading image") }

	// Set image size from loaded image (scaling appropriately)
	_settings.img_size.x = (int)(_scale * old_frame.cols);
	_settings.img_size.y = (int)(_scale * old_frame.rows);

	// Instantiate a core_engine
	gSLICr::engines::core_engine* gSLICr_engine = new gSLICr::engines::core_engine(_settings);

	// gSLICr takes gSLICr::UChar4Image as input and output
	gSLICr::UChar4Image* in_img = new gSLICr::UChar4Image(_settings.img_size, true, true);
	gSLICr::UChar4Image* out_img = new gSLICr::UChar4Image(_settings.img_size, true, true);

	cv::Size s(_settings.img_size.x, _settings.img_size.y);

	cv::Mat frame;
	cv::resize(old_frame, frame, s);

	load_image(frame, in_img);

	cv::Mat boundry_draw_frame;
	boundry_draw_frame.create(s, CV_8UC3);

	StopWatchInterface *my_timer;
	sdkCreateTimer(&my_timer);
	sdkResetTimer(&my_timer);
       sdkStartTimer(&my_timer);
	
	gSLICr_engine->Process_Frame(in_img);
	
	sdkStopTimer(&my_timer);
	std::cout<<"\rsegmentation in:["<<sdkGetTimerValue(&my_timer)<<"]ms" << std::flush;

	gSLICr_engine->Draw_Segmentation_Result(out_img);
		
	load_image(out_img, boundry_draw_frame);
	
	std::string fname = Util::Files::getFilenameFromPath(input_path);
	std::string full_out_path = Util::Files::joinPathAndFile(output_path, fname);
	std::string pgm_out_name = full_out_path + ".slic.pgm";
	std::string viz_out_name = full_out_path + ".viz.png";
	
	gSLICr_engine->Write_Seg_Res_To_PGM(pgm_out_name.c_str());
	bool success = cv::imwrite(viz_out_name, boundry_draw_frame);
	if (!success) {	EXCEPTION_THROWER(Util::Exception::IOException, "Error writing image") }

	out_img->~Image();
	in_img->~Image();
	gSLICr_engine->~core_engine();
}

How to access superpixel information

Hey there,

I can't figure out how to access the superpixel result correctly. I don't need the drawn output image itself but the actual superpixel information. I basically want to store the superpixel ID for each pixel as a 4th channel in the image. Is there no trivial way to do this, or am I just missing something? I also need a way to determine neighboring superpixels, if it's possible.

Best,
Alex

Suggested minor bugfix?

In gSLICr_seg_engine_GPU.cu, line 67:
max_xy_dist = 1.0f / (1.4242f * spixel_size); // sqrt(2) * spixel_size

Replace 1.4242f with 1.4142f
Since sqrt(2) = 1.41421...

Superpixel components are disconnected

The goal (at least mine) of using superpixels is to divide image into segments, in which each segment should group connected similar pixels.

In your implementation, I noticed that many disconnected segments are considered the same superpixel even though they are separated by other superpixels. Unfortunately, coh_weight and do_enforce_connectivity did not fix that behavior. Therefore, I am reporting it as an issue!

To make things clearer, I am providing an example!
In the following input image, I selected to visualize the superpixel that the red marked pixels belongs to.
input

I am using the idx_img to point to the corresponding spixel(s) inside spixel_map, mark them, then visualize pixels that belongs to the marked spixel(s), again, through idx_img.

As you can see, the output of that returned a single superpixel, but many disconnected segments. The center of that superpixel is surrounded by four red pixels as shown.
output

I would appreciate it if I get a workaround as near as possible!

Issue with different size of superpixel

Hello,

I tried gSLICr by specifying different size of superpixel :

  • For spixel_size = 10, it results in a strange segmentation like on the picture [slic_size10] , with totally squared spixel. Is it supposed to work only with specific spixel_size?

  • For spixel_size = 50, there are still "orphan" superpixels as we can see on image [slic_size50]. Is the function "do_enforce_connectivity" not supposed to remove them?

    I have tried with other images and other machines but the problem seems recurrent.

slic_size10
slic_size50

Can it be written compatibly with 64bit compilation?

I am new to CUDA, and its version is 9.0 in my PC. My compilation process failed, and it says, "nvcc fatal : 32 bit compilation is only supported for Microsoft Visual Studio 2013 and earlier ", could you kindly tell me how to convert it to 64 bit version?

Segmented image where each super pixel has median value

Hi,

I am using this library in my application. It works great. But I need to get an image back where every pixels in individual super-pixel has same value. And that value should be median of all the pixels values in a particular super-pixel.
Now I could do it after getting segmented mask image but that's slowing things down. I was wondering if there a good way to incorporate this within the library to make it faster. If I take on this task, where should I look and where is the ideal location in library code to calculate median for all the all the pixel in a super-pixel.
Also let me know if it's going to be as slow as doing it afterwards.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.