alicevision / CCTag

Detection of CCTag markers made up of concentric circles.
https://cctag.readthedocs.io
Mozilla Public License 2.0
351 stars 87 forks source link

can I move this code to windows? #73

Closed bubulv closed 4 years ago

bubulv commented 6 years ago

Dose this code have some limiting? I want to build it in windows with VS2013

simogasp commented 6 years ago

Hi @bubulv, I don't know if @zvrba ever built this on windows, but I think it is not possible to build it as-it-is now as there are few calls to unix library (eg <sys/stat.h> etc) that will cause errors on windows.

On the other hand, the majority of the code relies on C/C++ standard library and dependency libraries that can be found on windows as well, so it is possible to port the code on windows, it's a matter of replacing those few platform specific calls with either the windows counterpart or, better, replace with another cross-platform library. For example, there are few calls to ::mkdir (from <sys/stat.h>) that can be easily replaced by boost::filesystem::create_directory() from boost library which is already a dependency of the project.

If you are motivated to give it a try we can help you, as it would be great to have full portability of the code on the 3 major platforms.

S.

zvrba commented 6 years ago

I've never tried to build it on Windows.

bubulv commented 6 years ago

Thank you for your reply!I have build it on windows already. But some exceptions appear when the code run CompleteFlowComponent function. I buid cctag with CUDA and NDEBUG use VS2015. Further more, can you explain more details about how to choose the appropriate params for myself datas? My image size is about 500*500, and just 1 or 2 cctag markers are in it. Now it is 60-80ms for one image detect with cuda, I want to improve the efficiency. Have you every test the spent time? Any params setting can help me?

xena

在 2018年4月22日,21:14,Simone Gasparini notifications@github.com 写道:

Hi @bubulv, I don't know if @zvrba ever built this on windows, but I think it is not possible to build it as-it-is now as there are few calls to unix library (eg <sys/stat.h> etc) that will cause errors on windows.

On the other hand, the majority of the code relies on C/C++ standard library and dependency libraries that can be found on windows as well, so it is possible to port the code on windows, it's a matter of replacing those few platform specific calls with either the windows counterpart or, better, replace with another cross-platform library. For example, there are few calls to ::mkdir (from <sys/stat.h>) that can be easily replaced by boost::filesystem::create_directory() from boost library which is already a dependency of the project.

If you are motivated to give it a try we can help you, as it would be great to have full portability of the code on the 3 major platforms.

S.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

simogasp commented 6 years ago

Thank you for your reply!I have build it on windows already.

That's very cool! If you want to contribute to the project please do not hesitate to make a pull request so we can make the library available on windows platforms!

But some exceptions appear when the code run CompleteFlowComponent function. I buid cctag with CUDA and NDEBUG use VS2015.

Can you be more precise and report the error?

Further more, can you explain more details about how to choose the appropriate params for myself datas? My image size is about 500*500, and just 1 or 2 cctag markers are in it. Now it is 60-80ms for one image detect with cuda, I want to improve the efficiency. Have you every test the spent time? Any params setting can help me?

just as reference, can you try to run it on the sample images in the samples directory and report your results (number of detected markers and execution time). BTW which nvidia card are you using? I think the default parameters should be a good trade-off for speed and accuracy. But for more insight on that we need the authors @lcalvet @griwodz to jump in.

griwodz commented 6 years ago

I'm not the right person to ask theoretical things about CCTags, but 80ms for a 500x500 image sounds like an older card. However, it could also be (1) not compiled for exactly the right CUDA Compute Capability, (2) having some debug features switched on, or (3) an image whose greyscale version has lots of parallel lines (straight lines or arcs).

For (1), you can change CCTAG_CUDA_CC_LIST to your card's CC. When I don't remember, I look at the Wikipedia page about CUDA. My 1080 card has CC=61 for example.

For (2), I'm not sure. VISUAL_DEBUG=OFF, CCTAG_NO_COUT=ON, CCTAG_SERIALIZE=OF I suppose.

For (3): images with parallel lines or arcs force CCTags to check if those are parallel lines are part of a concentric ring, and if the number of parallel stripes is good (more than 3 or more than 4, depending on parameter), it will try to compute the center. Only afterwards does it check if that was a "good" CCTag. The reason is, of course, to make CCTags resilient to occlusion, but it can steal a lot of time.

bubulv commented 6 years ago

@simogasp @griwodz You are so nice. But I don't know how to make a pull request. I just change some windows' libraries and set some options on VS2015. For(1): My gpu is Titan xp and cuda 9.1. In vs2015 I only can set the compute=35 max, if I set 61 the vs will report some errors: "too many share datas". And until now I dont't know how to solve it. image

For(2): I set VISUAL_DEBUG=OFF, CCTAG_NO_COUT=ON, CCTAG_SERIALIZE=OF and so on. For(3): My images real have many parallel lines, I use the cctag to detect the moved robots and identifiy their id. For(4): I test the sample/01.png, it spent 475ms, and I set the kDefaultNumberOfMultiresLayers=1. the result as follow: image For(5): I test a video to detect the cctag with gpu, the frame size is 1920*1080, and kDefaultNumberOfMultiresLayers=1, other params are defalut.
The exception error are: image

bubulv commented 6 years ago

Hello, I have solve the question (1), my compute set sm=60, and the spent time improve to about 40ms one frame(1000*1000). But the main question is (5). Although it is a dubug information. Did it has any effects on the results? If it has no effect I will ignore this error. When I build cctag under Linux this information never appears, so I'm a little woried. @griwodz Can you give me some advises to set the default parameters on myself data? This code and default parameters do very well on your sample image, but not good on my data. Hope you can help me. Thanks very much. When I done all the project I'm appreciate to share the experiences about building it on windows. Just a sharing, your code is good.

simogasp commented 6 years ago

But the main question is (5). Although it is a dubug information. Did it has any effects on the results? If it has no effect I will ignore this error. When I build cctag under Linux this information never appears, so I'm a little woried.

You can try to add another catch clause before the generic one https://github.com/alicevision/CCTag/blob/develop/src/cctag/Detection.cpp#L262 like

  catch (std::exception& e)
  {
    DO_TALK( CCTAG_COUT_DEBUG( "exception: " +  e.what() ); )
  }
  catch (...)
  {
    DO_TALK( CCTAG_COUT_DEBUG( "Exception raised in the second main loop." ); )
  }

so we can see what kind of exception and message is thrown. And from there we can move up to the source throw.

bubulv commented 6 years ago

q1 Here is my 3 major errors. The default parameter kDefaultThrMedianDistanceEllipse=3.0, what does it mean?

simogasp commented 6 years ago

Again I'm not the expert on the algorithmic part but those seem to me just debugging info, not really errors, they are just normal conditions not met during the detection that enable an early return. I wouldn't be too worried about those.

bubulv commented 6 years ago

@simogasp Thanks again for your reply. They are just some debug information. But I think maybe I can change some default parameters to help detect. But I don't know which parameters are good for me.

Can you help me?@griwodz

simogasp commented 6 years ago

could you share one image or one frame of your video so that we can have an idea of the problem/settings etc?

griwodz commented 6 years ago

@bubulv I'm sorry but the parameters are not my domain. The theory was the work of @lcalvet .

I remember some of them:

The Canny Threshold variables change how strong a gradient (brightness difference between a bright and a dark pixel) must be to be recognized as an edge. The CCTags need 6 (n=3) or 8 (n=4) pretty sharp edges. If your threshold is very low, everything looks like an edge you cannot find shapes. If it is too high, CCTags in the shadow are not noticed.

RatioVoting says: if you draw a line from every pixel on an outer ring to the CCTag center, how many different pixels do cross on the inner ring? The radius difference of the outer and inner wring forces this to be 3. So if your CCTags are perfect, you should probably set this to 3 instead of 4.

CCTags is robust to occlusion. So it believes that it must construct each ring from little pieces (arc segments). The arc segments are neighouring pixels from the Canny edge image that could be extended into a ring-like shape. So, they are not winding like a snake, but form a curve. Before trying to estimate whether such arc segments can be connected into a ring, all the pieces shorter than SampleCutLength are thrown away.

griwodz commented 6 years ago

@bubulv I think you should increase kDefaultNumberOfMultiresLayers. If your image is blurred, you don't have a strong gradient between brightness outside of the outer wring and brightness on the outer ring. The Canny threshold test can fail because of that. The next lower resolution can hide that blur and the gradient can be good enough.

griwodz commented 6 years ago

I have had bad gradient orientations for 2 reasons:

[and when I had inverted gradient computations, but that bug was fixed]

griwodz commented 6 years ago

..

simogasp commented 6 years ago

In your example, if you don't get any detection, you should upscale x2 your image so that the ring thickness is greater than 3 or 4 pixels. Indeed, a transition edge, not edge, edge, etc. must appear on the edge detection response (canny)

@griwodz @lcalvet If I recall correctly there was a minimum detectable size for the cctag in the image, HxW pixels. I don't know if I remember correctly or if it is not the case anymore. In case we should add it in the doc.

griwodz commented 6 years ago

There was not. The most relevant criterion remains the maximal ring thickness in the image (not constant due to perspective distortion). That value must be greater than 3 or 4 pixels approximately.

lcalvet commented 6 years ago

Sorry, I was logged as @griwodz

Hi @bubulv Thanks for your interest. You MUST respect the white margin as described on the github repo webpage (https://github.com/alicevision/CCTag/): first WARNING... . Margins should be white, not black. You must use the markers to print provided here: https://github.com/alicevision/CCTag/tree/develop/markersToPrint . There must not be any pattern printed inside the inner white circle (in your example, it seems that you added the marker ID). The provided algorithm is designed to be robust to highly challenging shooting conditions but the price to pay is to not change the provided patterns and to be supported by a very flat surface. I highly recommend to not change any of the default parameters. In your example, if you don't get any detection, you should upscale x2 your image so that the ring thickness is greater than 3 or 4 pixels. Indeed, a transition edge, not edge, edge, etc. must appear on the edge detection response (canny) along a curve (field line) from outside the imaged marker to its center that may require an image upscale. Don't worry about the log. Good luck

richard-bmc commented 6 years ago

@bubulv It's really encouraging to know someone had built CCTag on Windows. I was trying the same thing but I got no luck. I wonder what the version of Boost you are using. I built CCTag with Boost 1.67, which was installed via vcpkg, but I got a lot of errors from Boost include files.

simogasp commented 6 years ago

Hi @richard-bmc , please note that there is a working in progress porting to windows #78 You can try to check out that branch devWindozeFixes. It works for the CPU part, there may be still some issue with CUDA for the gpu part. You can build the cpu part by passing -DWITH_CUDA:BOOL=OFF Of course any feedback and contribution is welcome :-)

richard-bmc commented 6 years ago

@simogasp OK! I'll try that branch!

richard-bmc commented 6 years ago

@simogasp I've just built CCTag (without CUDA) on my computer successfully! The only thing I modified is defining CV_CAP_PROP_FRAME_COUNT in src/applications/regression/TestLog.cpp. Its definition is somewhere else in the OpenCV, but it's not included in TestLog.cpp.

simogasp commented 6 years ago

great! Does it work too? You can try to run

build/src/detection -n 3 -i sample/01.png

(it may crash in Debug mode, it should work in Release, because of #74 that has to be fixed)

simogasp commented 6 years ago

The only thing I modified is defining CV_CAP_PROP_FRAME_COUNT in src/applications/regression/TestLog.cpp. Its definition is somewhere else in the OpenCV, but it's not included in TestLog.cpp.

@richard-bmc Which version of opencv are you using?

richard-bmc commented 6 years ago

great! Does it work too? Yes! It detects 4 markers in 01.png in 0.924 seconds, and 6 markers in 02.png in 1.076 seconds. Which version of opencv are you using? My OpenCV version is 4.0.0-pre. Perhaps it's too new.

watchmexiang commented 6 years ago

Hi@bubulv I hear that you successfully move this code to Windows,please,Can you share the following code that you moved to Windows,Thank you

bubulv commented 6 years ago

@zhangyuqiqiyuzhang There are many dependent packages should be added. First you should install them successfully. In addition, I just replace some functions which can not use on windows.

watchmexiang commented 6 years ago

Hi@simogasp I hear that you successfully move this code to Windows,please,Can you share the following code that you moved to Windows,Thank you

watchmexiang commented 6 years ago

@bubulv Thank you for your reply,Can you share the code after you replace the function for me to learn about,Thank you

simogasp commented 6 years ago

@zhangyuqiqiyuzhang There is a working in progress pull request to port the code to windows #78 . You can try to check out that branch devWindozeFixes. It works for the CPU part, there may be still some issue with CUDA for the gpu part. You can build the cpu part by passing -DWITH_CUDA:BOOL=OFF. In that branch I haven't updated yet the documentation to build on windows. The easiest way is to use vcpkg to build the dependencies. Once you have vcpkg in place you can follow this file https://github.com/alicevision/CCTag/blob/devWindozeFixes/appveyor.yml#L15 for installing the dependencies (it's the continuous integration file on windows, so the steps are really similar)

simogasp commented 6 years ago

@richard-bmc

Which version of opencv are you using? My OpenCV version is 4.0.0-pre. Perhaps it's too new.

yes and no :-) There is actully something to fix in our code because we were mixing C and C++ headers. I hope to find the time to update all this asap...

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

simogasp commented 4 years ago

The latest version can now build on windows, at least for the CPU part