Extract Cuda code from OPENCV--ORB_GPU algorithm (i) __ algorithm

Source: Internet
Author: User

This is a wonderful idea ... We don't talk about whether it means anything.


This wonderful idea appears based on the following 2 points:

1, OPENCV code once compiled into a library file, it is difficult to modify the internal code, although most of the need to modify the part has been referred to the interface above.

2, OpenCV in the use of Cuda accelerated code written or very efficient, however, the corresponding large, complex C + + interface conversion, resulting in the original high-speed execution time is slowed down, although it is hundreds of or even just dozens of milliseconds, but for real-time video processing problems are already very fatal, Digging out the Cuda code facilitates further modification of the code into its fully controllable interface.


The author has encountered this problem in a line detection algorithm based on Hough, the handwriting program does not guarantee the accuracy and real-time, direct use of OPENCV but the time is long, mainly because of the conversion of Gpumat, so the method used is to pull OpenCV code, To our own Cudamalloc code interface, and deleted a lot of the middle for our meaningless visit, and finally put on the TX1 platform, speed around 110ms. The direct call at that time was about 450ms, which seemed to be the number of OPENCV.


Now let's talk about picking up code from the OPENCV:


1, preparation tools: The use of Cuda compiled OpenCV library, VS2012 and above, with NVIDIA graphics card computer

2. Process:

A, first compile and run a ORB_GPU demo;

B, interrupt point, and use single step debugging (the statement-by-sentence) to prevent missed what other content;

Look, into the OPENCV function inside, but we still do not know what this (*this) is a what, it does not matter, continue to run the statement-by-word, remember that in the function run to the last bracket to step out of the statement, or you may miss a lot. Incidentally, here (*this) contains the following:

	 Where (*this) (image, Mask, d_keypoints_, descriptors); followed by:
	 cv::gpu::orb_gpu::buildscalepyramids (const gpumat& Image, Const gpumat& mask)
	 cv::gpu::orb_gpu::computekeypointspyramid ()
			keypoints use Cv::gpu::fast_gpu to get
			use HARRISRESPONSES_GPU to get Harris response
	 Cv::gpu::orb_gpu::computedescriptors (gpumat& descriptors)
	 CV:: Gpu::orb_gpu::mergekeypoints (gpumat& keypoints)

C, to determine the content of the function, the next step is to create a new project to perform the code we posted from the OpenCV, where there is a namespace conflict problem, my approach is to define the Orb algorithm namespace Cv::gpu replaced by the LMW, and the name of the class replaced by the Orb_ GPU0.

D, the code to copy out, but also need a large number of header files, the final need to change, edit 4 files: orb_gpu0 in the header file. Cuh,c++ interface. Cpp,cuda code. CU, and main function. cpp. and need to put the dependent unified file Cv::gpu::d evice of each inline function, header file, defined parts, are added to the compiled project, or directly added to the reference directory.


Results:

In order to show the difference with the original project, I added a "done!" output to the internal function.

Well, the change was a success.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.