>

2014년 11월 26일 수요일

NVidia Cuda, Mac OS X 10.10.1; Quadro K4200 install

* Quadro K4200 is installed instead of the original graphic card in my Mac Pro 5,1 (Mid 2010).
 - Don't worry about the power cable. I used the cable in the computer for the old graphic card.
 - during the booting, the initial screen does not appear. No worries.
 - Since the original graphic board occupied two x16 slots (even if it needs only one) due to its thickness, I could not use it anymore. Kept it safe.
 - Both of the graphic cards may be used if you can put them into x16 slots at the same time. Then, you need another power cable for the new graphic card. In my case, K4200 box had several power cables but without the one I needed. So have one made in Yong-San, Seoul, Korea. 
  Wants to make it DIY? 8pin-8pin mini, 1-1, 2-2, no cable twist connection. Then, the cable looks twisted when straightened. Or, find one from Amazon.

* Software install.
1. install the Nvidia cuda toolkit for program development: 

2. install Cuda driver

3. install NVIDIA Mac OS X Driver Release 343.01.02: 

4. reboot (automatic)

------------
System Preferences

CUDA

NVIDIA Driver Manager

CUDA driver check

CUDA program compile
output of deviceQuery


output of bandwidthTest


Done.

----------------------------------


Tue August 12, 2014 Nvidia unveiled its next generation of Quadro GPUs


NVIDIA CUDA Getting Started Guide for Mac OS X

Read more at: http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-mac-os-x/index.html#ixzz3KEOZ59AU


CUDA, opencv-3.0.0-beta install - libstdc++

A gui version of CMake was used and the following error happened:

Scanning dependencies of target opencv_test_cudev
[ 32%] Building CXX object modules/cudev/test/CMakeFiles/opencv_test_cudev.dir/test_main.cpp.o
Linking CXX executable ../../../bin/opencv_test_cudev
Undefined symbols for architecture x86_64:
  "cv::PrintTo(cv::Size_<int> const&, std::ostream*)", referenced from:
      std::string testing::PrintToString<cv::Size_<int> >(cv::Size_<int> const&) in opencv_test_cudev_generated_test_warp.cu.o
  "testing::internal::StringStreamToString(std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >*)", referenced from:
      testing::AssertionResult testing::internal::CmpHelperFloatingPointEQ<float>(char const*, char const*, float, float) in opencv_test_cudev_generated_test_reduction.cu.o

-------------------
** libc++ or libstdc++, that is the question!

$ vi cmake/OpenCVDetectCUDA.cmake

117   # NVCC flags to be set

118   set(NVCC_FLAGS_EXTRA " -Xcompiler -stdlib=libstdc++; -Xlinker -stdlib=libstdc++")

$ vi cmake/OpenCVCompilerOptions.cmake

 26 set(OPENCV_EXTRA_FLAGS "")
 27 set(OPENCV_EXTRA_C_FLAGS "")
 28 set(OPENCV_EXTRA_CXX_FLAGS " -stdlib=libstdc++")
 29 set(OPENCV_EXTRA_FLAGS_RELEASE "")
 30 set(OPENCV_EXTRA_FLAGS_DEBUG "")
 31 set(OPENCV_EXTRA_EXE_LINKER_FLAGS " -stdlib=libstdc++")
 32 set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "")

 33 set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "")

---
now it was done!

gpu $ make optical_flow
clang++ -stdlib=libstdc++   -L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_videoio -lopencv_video -lopencv_cuda -lopencv_cudaarithm -lopencv_cudabgsegm -lopencv_cudafeatures2d -lopencv_cudafilters -lopencv_cudaimgproc -lopencv_cudalegacy -lopencv_cudaoptflow -lopencv_cudastereo -lopencv_cudawarping  optical_flow.cpp   -o optical_flow

yndkMacHost:11.28[15:35:13]gpu $ ./optical_flow ../data/rubberwhale1.png ../data/rubberwhale2.png 
Brox : 0.17475 sec
init done
opengl support available
LK : 0.0214009 sec
Farn : 0.0369818 sec
TVL1 : 0.185709 sec
BM : 0.34601 sec
Fast BM : 0.0497536 sec

! Finished.

----
A method, which had been tried but not recommended.
opencv-3.0.0-beta/build $ vi CMakeCache.txt 

// line 449
//Semi-colon delimit multiple arguments.
CUDA_NVCC_FLAGS:STRING= -Xcompiler -stdlib=libstdc++; -Xlinker -stdlib=libstdc++

---

// line 196
//Flags used by the compiler during all build types.
CMAKE_CXX_FLAGS:STRING= -stdlib=libstdc++

// line 231
//Flags used by the linker.
CMAKE_EXE_LINKER_FLAGS:STRING= -stdlib=libstdc++

-------
build $ make
>> Make succeeded but it started compiling again when I did 'make install' So, this is no good!

2014년 11월 21일 금요일

getopt(); how to use.

맥에서도 getopt() 사용할 일이 가끔 생긴다.

Source: http://www.gnu.org/software/libc/manual/html_node/Example-of-Getopt.html

25.2.2 Example of Parsing Arguments with getopt

Here is an example showing how getopt is typically used. The key points to notice are:
  • Normally, getopt is called in a loop. When getopt returns -1, indicating no more options are present, the loop terminates.
  • switch statement is used to dispatch on the return value from getopt. In typical use, each case just sets a variable that is used later in the program.
  • A second loop is used to process the remaining non-option arguments.

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int
main (int argc, char **argv)
{
  int aflag = 0;
  int bflag = 0;
  char *cvalue = NULL;
  int index;
  int c;

  opterr = 0;

  while ((c = getopt (argc, argv, "abc:")) != -1)
    switch (c)
      {
      case 'a':
        aflag = 1;
        break;
      case 'b':
        bflag = 1;
        break;
      case 'c':
        cvalue = optarg;
        break;
      case '?':
        if (optopt == 'c')
          fprintf (stderr, "Option -%c requires an argument.\n", optopt);
        else if (isprint (optopt))
          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
        else
          fprintf (stderr,
                   "Unknown option character `\\x%x'.\n",
                   optopt);
        return 1;
      default:
        abort ();
      }

  printf ("aflag = %d, bflag = %d, cvalue = %s\n",
          aflag, bflag, cvalue);

  for (index = optind; index < argc; index++)
    printf ("Non-option argument %s\n", argv[index]);
  return 0;
}
Here are some examples showing what this program prints with different combinations of arguments:
% testopt
aflag = 0, bflag = 0, cvalue = (null)

% testopt -a -b
aflag = 1, bflag = 1, cvalue = (null)

% testopt -ab
aflag = 1, bflag = 1, cvalue = (null)

% testopt -c foo
aflag = 0, bflag = 0, cvalue = foo

% testopt -cfoo
aflag = 0, bflag = 0, cvalue = foo

% testopt arg1
aflag = 0, bflag = 0, cvalue = (null)
Non-option argument arg1

% testopt -a arg1
aflag = 1, bflag = 0, cvalue = (null)
Non-option argument arg1

% testopt -c foo arg1
aflag = 0, bflag = 0, cvalue = foo
Non-option argument arg1

% testopt -a -- -b
aflag = 1, bflag = 0, cvalue = (null)
Non-option argument -b

% testopt -a -
aflag = 1, bflag = 0, cvalue = (null)
Non-option argument -

ffmpeg install & usage

* Install: Just copy and paste the following.

$ brew install ffmpeg --with-fdk-aac --with-ffplay --with-fontconfig --with-freetype --with-frei0r --with-libass --with-libbluray --with-libcaca --with-libquvi --with-libsoxr --with-libvidstab --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-openssl --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools --with-x265

* Horizontal flip (with lossless compression)

$ ffmpeg -i input.avi -vf hflip -c:v ffv1 -c:a copy output.avi

* Making an avi from several image frames with lossless compression

$ ffmpeg -i image-%04d.png  -c:v ffv1   output.avi


* best quality of MPEG4 encoding (1~31)

$ ffmpeg -i frame-%04d.png -c:v mpeg4 -q:v 1 output.mp4

* playing a video

$ ffplay video.avi

2014년 11월 19일 수요일

libCinder + OpenCV

Why libcinder instead of OpenFrameworks?
   http://libcinder.org/
Well, My Mac OS X is making 64bit outcomes, but OF is restricted to 32bit only. Using other general tools is severely restricted.

Using OpenCV with libcinder seems much easier.

Qt5, OpenGL for OpenCV 2.4.9 in Mac OS X (10.10 Yosemite)

* OpenCV Mac OS version uses Cocoa for GUI.
* Therefore, OpenGL can only be used with Qt in Mac OS.

* OpenCV must be re-installed with new options.

1. Install Qt first.
   http://www.qt.io/download/


2. Run a gui version of cmake. 
  - CMake 3.0.1
  - The opencv is in Downloads/opencv-2.4.10

2.1 Choose Qt and OpenGL

2.2 Fill out the necessary Qt folders



* You would need to click <Configure> button in cmake several times to see the result.

2.3 You should check the result of your configuration in the output window of CMake as follows:

2.4 Press 'Generate' button. Now, we finished cmake.

3. go to terminal
   $ make; make install

4. Done.

----

* An example:


* Another Example


 End.