>

2014년 12월 4일 목요일

opencv 2.4.9 & 3.0.0 둘 다 설치하기; install both

1. 2.4.9 를 설치한다.

$ brew tap homebrew/science
$ brew install opencv --with-ffmpeg --with-tbb

1.1. 설치가 끝난후에 다음을 확인한다.

$ ls -l /usr/local/Cellar/opencv
drwxr-xr-x  9 yndk  wheel  306 12  3 16:48 2.4.9

1.2. 맨 마지막 2.4.9 가 디렉토리의 이름이고, 그 안을 살펴보면 다음과 같다.

$ ls -l /usr/local/Cellar/opencv/2.4.9
 -rw-r--r--   1 yndk  staff   489 12  3 16:48 INSTALL_RECEIPT.json
 -rw-r--r--   1 yndk  wheel  1772 10  1 16:33 LICENSE
 -rw-r--r--   1 yndk  wheel   636 10  1 16:33 README.md
 drwxr-xr-x   6 yndk  wheel   204 12  3 16:48 bin
 drwxr-xr-x   4 yndk  wheel   136 12  3 16:48 include
 drwxr-xr-x  59 yndk  wheel  2006 12  3 16:48 lib
 drwxr-xr-x   3 yndk  wheel   102 12  3 16:48 share

2. cmake 를 이용하여 3.0.0 을 직접 컴파일하고 설치한다.
설치 디렉토리는 자신이 좋아하는 곳으로. 예를 들면 /usr/local/opencv-3.0.0-beta

2.1 make; make install 후에 /usr/local/opencv-3.0.0-beta 디렉토리를 보면 다음과 같이 되어있다.

$ ls -l /usr/local/opencv-3.0.0-beta
drwxr-xr-x    5 yndk  wheel   170 11 21 14:31 bin
drwxr-xr-x    4 yndk  wheel   136 11 21 13:45 include
drwxr-xr-x  110 yndk  wheel  3740 11 21 14:31 lib
drwxr-xr-x    3 yndk  wheel   102 11 21 13:45 share

2.2 이 디렉토리를 /usr/local/Cellar/opencv/3.0.0으로 복사한다.

$ cp -r /usr/local/opencv-3.0.0-beta /usr/local/Cellar/opencv/3.0.0

3. brew 를 실행하여 사용하고싶은 버전으로 설치한다.

* opencv 3.0 을 사용할 경우

$ brew switch opencv 3.0.0

* 확인해본다. 3.0.0 으로 설치한 후

$ ls -l /usr/local/include/opencv*
 lrwxr-xr-x  1 yndk  wheel  37 12  5 09:07 /usr/local/include/opencv@ -> ../Cellar/opencv/3.0.0/include/opencv
 lrwxr-xr-x  1 yndk  wheel  38 12  5 09:07 /usr/local/include/opencv2@ -> ../Cellar/opencv/3.0.0/include/opencv2

* opencv 2.4.9를 사용할 경우

$ brew switch opencv 2.4.9

* brew 실행할 때 특정 파일들이 중복된다거나 지우라는 내용이 나오면 그대로 실행하면 된다.
* 둘 다 설치되어 있지만 실제로 사용할 때는 한 개만 선택해서 사용하는 것으로 이해하는 것이 좋음.


끝.

cv::cascadeClassifier training & example

Quick Start
1. cut and make a template image (size: 164x164), save it to faceSample.png.

2. do the following
    $ opencv_createsamples -img faceSample.png -vec faceSample.vec -num 10000

2. have a look at the samples
   $ opencv_createsamples -show -vec faceSample.vec

3. run
   $ opencv_haartraining -data result -vec faceSample.vec  -bg bg.txt

4. test
   $ ./haarObjectDetection result.xml group.jpg

Here is group.jpg downloaded from google image search. sorry, privacy.

Actually, the template image is cropped from the group.jpg.

* haarObjectDetection.cpp
----------------------------------------------------------------------------
// modifed version of objectDetect.cpp
/**
 * @file objectDetection.cpp
 * @author A. Huaman ( based in the classic facedetect.cpp in samples/c )
 * @brief A simplified version of facedetect.cpp, show how to load a cascade classifier and how to find objects (Face + eyes) in a video stream
 */
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

/** Function Headers */
void detectAndDisplay( Mat frame );

/** Global variables */
//-- Note, either copy these two files from opencv/data/haarscascades to your current folder, or change these locations
CascadeClassifier face_cascade;
string window_name = "Capture - Face detection";
RNG rng(12345);

int main( int argc, char *argv[] )
{
  Mat frame;

  if (argc!=3) {
cerr << "usage: " << argv[0] << " haar_cascade.xml   testimage.jpg" << endl;
return 0;
  }

  //-- 1. Load the cascades
  if( !face_cascade.load( argv[1] ) ){ printf("--(!)Error loading\n"); return -1; };

  //-- 2. Read the video stream
      frame = imread (argv[2]);

      //-- 3. Apply the classifier to the frame
      if( !frame.empty() )
       { detectAndDisplay( frame ); }
      else
       { printf(" --(!) No captured frame -- Break!"); return 0; }

      int c = waitKey();

  return 0;
}

/**
 * @function detectAndDisplay
 */
void detectAndDisplay( Mat frame )
{
   std::vector<Rect> faces;
   Mat frame_gray;

   cvtColor( frame, frame_gray, COLOR_BGR2GRAY );
   equalizeHist( frame_gray, frame_gray );
   //-- Detect faces
   face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

   for( size_t i = 0; i < faces.size(); i++ )
    {
      Point center( faces[i].x + faces[i].width/2, faces[i].y + faces[i].height/2 );
      ellipse( frame, center, Size( faces[i].width/2, faces[i].height/2), 0, 0, 360, Scalar( 255, 0, 255 ), 2, 8, 0 );
    }
   //-- Show what you got
   imshow( window_name, frame );
}
----------------------------------------------------------------------------


-------------
http://docs.opencv.org/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.html
http://docs.opencv.org/doc/user_guide/ug_traincascade.html


opencv_traincascade 
supports both Haar [Viola2001] and LBP [Liao2007] (Local Binary Patterns) features.

opencv_createsamples 
is used to prepare a training dataset of positive and test samples.
The output is a file with *.vec extension, it is a binary format which contains images.

-- Training Data Preparation
Set of negative samples must be prepared manually, whereas set of positive samples is created using opencv_createsamples utility.

-- Negative Samples
Make a file of imagefile names
$ cat bg.txt
img/bg1.png
img/bg2.png

-- Positive Samples
Positive samples are created by opencv_createsamples utility. 
They may be created from a single image with object 
or from a collection of previously marked up images.

2014년 12월 1일 월요일

caffe compile and install in Mac OSX 10.10.1, CUDA 6.5

** gflags 1.0  must be installed!
** glog 0.3.3 based on gflags 1.0.
** Make test gives run time error
[----------] 1 test from SolverTest/1, where TypeParam = caffe::DoubleCPU
[ RUN      ] SolverTest/1.TestInitTrainTestNets
test_all.testbin(95309,0x7fff7d0e2300) malloc: *** error for object 0x110afa7a0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

make: *** [runtest] Abort trap: 6

--------------------
mybuild $ cmake ..
-- Found leveldb in /usr/local/include /usr/local/lib/libleveldb.dylib
-- Found Snappy: /usr/local/lib/libsnappy.dylib  
-- LMDB lib: /usr/local/lib/liblmdb.dylib
-- LMDB include: 
-- Found LMDB: /usr/local/include  
-- Boost version: 1.56.0
-- Found the following Boost libraries:
--   system
--   thread
-- Found PROTOBUF: /usr/local/lib/libprotobuf.dylib  
-- Found PROTOBUF Compiler: /usr/local/bin/protoc
-- Examples enabled
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/yndk/Downloads/caffe-master/mybuild

mybuild $ make all
Scanning dependencies of target gtest
[  1%] Building CXX object src/gtest/CMakeFiles/gtest.dir/gtest-all.cpp.o
In file included from /Users/yndk/Downloads/caffe-master/src/gtest/gtest-all.cpp:39:
/Users/yndk/Downloads/caffe-master/src/gtest/gtest.h:1561:13: fatal error: 'tr1/tuple' file not
      found
#   include <tr1/tuple>  // NOLINT
            ^
1 error generated.
--------------------------
So, I modified the line 28 of CMakeList.txt file as follows

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -stdlib=libstdc++") # set global flags
--------------------------
mybuild $ make all
...
caffe-master/include/caffe/util/mkl_alternate.hpp:11:10: fatal error: 
      'cblas.h' file not found
#include <cblas.h>
         ^

1 error generated.
--------------------------
So, I modified the line 28 of CMakeList.txt file as follows

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -stdlib=libstdc++ -I/System/Library/Frameworks/Accelerate.framework/Versions/C    urrent/Frameworks/vecLib.framework/Versions/Current/Headers -framework Accelerate") # set global flags
--------------------------
mybuild $ make
-- Found leveldb in /usr/local/include /usr/local/lib/libleveldb.dylib
-- LMDB lib: /usr/local/lib/liblmdb.dylib
-- LMDB include: 
-- Boost version: 1.56.0
-- Found the following Boost libraries:
--   system
--   thread
-- Found PROTOBUF Compiler: /usr/local/bin/protoc
-- Examples enabled
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/yndk/Downloads/caffe-master/mybuild
[  1%] Built target gtest
[  1%] Built target gtest_main
[  4%] Built target proto
[  5%] Building NVCC (Device) object src/caffe/CMakeFiles/caffe_cu.dir/util/./caffe_cu_generated_math_functions.cu.o
clang: warning: -framework Accelerate: 'linker' input unused
clang: warning: -framework Accelerate: 'linker' input unused
clang: warning: -framework Accelerate: 'linker' input unused
clang: warning: -framework Accelerate: 'linker' input unused
clang: warning: -framework Accelerate: 'linker' input unused
/usr/local/include/boost/config/suffix.hpp(496): error: identifier "__int128" is undefined

/usr/local/include/boost/config/suffix.hpp(497): error: expected a ";"

2 errors detected in the compilation of "/var/folders/cn/yf6gmhss2g96zb6933m4v0t00000gn/T//tmpxft_00012ea7_00000000-12_math_functions.compute_35.cpp1.ii".
CMake Error at caffe_cu_generated_math_functions.cu.o.cmake:264 (message):
  Error generating file
  /Users/yndk/Downloads/caffe-master/mybuild/src/caffe/CMakeFiles/caffe_cu.dir/util/./caffe_cu_generated_math_functions.cu.o


make[2]: *** [src/caffe/CMakeFiles/caffe_cu.dir/util/./caffe_cu_generated_math_functions.cu.o] Error 1
make[1]: *** [src/caffe/CMakeFiles/caffe_cu.dir/all] Error 2
make: *** [all] Error 2

------------------------------------
So, I added the following to /usr/local/include/boost/config/compiler/nvcc.hpp
// yndk
#ifdef BOOST_HAS_INT128
#undef BOOST_HAS_INT128
#endif
------------------------------------

mybuild $ make
-- Found leveldb in /usr/local/include /usr/local/lib/libleveldb.dylib
-- LMDB lib: /usr/local/lib/liblmdb.dylib
-- LMDB include: 
-- Boost version: 1.56.0
-- Found the following Boost libraries:
--   system
--   thread
-- Found PROTOBUF Compiler: /usr/local/bin/protoc
-- Examples enabled
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/yndk/Downloads/caffe-master/mybuild
[  1%] Built target gtest
[  1%] Built target gtest_main
[  4%] Built target proto
[  5%] Building NVCC (Device) object src/caffe/CMakeFiles/caffe_cu.dir/util/./caffe_cu_generated_math_functions.cu.o
clang: warning: -framework Accelerate: 'linker' input unused
clang: warning: -framework Accelerate: 'linker' input unused
clang: warning: -framework Accelerate: 'linker' input unused
clang: warning: -framework Accelerate: 'linker' input unused
clang: warning: -framework Accelerate: 'linker' input unused
/usr/local/include/boost/config/suffix.hpp(496): error: identifier "__int128" is undefined

/usr/local/include/boost/config/suffix.hpp(497): error: expected a ";"

2 errors detected in the compilation of "/var/folders/cn/yf6gmhss2g96zb6933m4v0t00000gn/T//tmpxft_00012ea7_00000000-12_math_functions.compute_35.cpp1.ii".
CMake Error at caffe_cu_generated_math_functions.cu.o.cmake:264 (message):
  Error generating file
  /Users/yndk/Downloads/caffe-master/mybuild/src/caffe/CMakeFiles/caffe_cu.dir/util/./caffe_cu_generated_math_functions.cu.o


make[2]: *** [src/caffe/CMakeFiles/caffe_cu.dir/util/./caffe_cu_generated_math_functions.cu.o] Error 1
make[1]: *** [src/caffe/CMakeFiles/caffe_cu.dir/all] Error 2
make: *** [all] Error 2

------------------------
So, another file. I placed at the beginning of the file: /usr/local/include/boost/config/suffix.hpp
//yndk
#if defined(BOOST_HAS_INT128)
#undef BOOST_HAS_INT128
#endif
//yndk
------------------------
mybuild $ make
[  1%] Built target gtest
[  1%] Built target gtest_main
[  4%] Built target proto
[  5%] Building NVCC (Device) object src/caffe/CMakeFiles/caffe_cu.dir/util/./caffe_cu_generated_math_functions.cu.o
...
[ 85%] Built target caffe
Scanning dependencies of target caffe.bin
[ 87%] Building CXX object tools/CMakeFiles/caffe.bin.dir/caffe.cpp.o
clang: warning: -framework Accelerate: 'linker' input unused
Linking CXX executable caffe
Undefined symbols for architecture x86_64:
  "cv::imread(std::string const&, int)", referenced from:
      caffe::ReadImageToDatum(std::string const&, int, int, int, bool, caffe::Datum*) in libcaffe.a(io.cpp.o)
      caffe::WindowDataLayer<float>::InternalThreadEntry() in libcaffe.a(window_data_layer.cpp.o)
      caffe::WindowDataLayer<double>::InternalThreadEntry() in libcaffe.a(window_data_layer.cpp.o)
  "google::SetUsageMessage(std::string const&)", referenced from:
      _main in caffe.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [tools/caffe] Error 1
make[1]: *** [tools/CMakeFiles/caffe.bin.dir/all] Error 2
make: *** [all] Error 2
-------------------------------
Now, I need an appropriate opencv for caffe.
opencv-3.0.0-beta with CUDA is installed.
----
caffe-master $ make
/usr/bin/clang++ src/caffe/layers/window_data_layer.cpp -stdlib=libstdc++ -framework Accelerate -pthread -fPIC -DNDEBUG -O2 -I/usr/local/include -I.build_release/src -I./src -I./include -I/usr/local/cuda/include -I/System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Versions/Current/Headers -Wall -Wno-sign-compare -Wno-unneeded-internal-declaration -c -o .build_release/src/caffe/layers/window_data_layer.o 2> .build_release/src/caffe/layers/window_data_layer.o.warnings.txt \
|| (cat .build_release/src/caffe/layers/window_data_layer.o.warnings.txt; exit 1)
clang: warning: -framework Accelerate: 'linker' input unused
src/caffe/layers/window_data_layer.cpp:230:48: error: use of undeclared identifier 'CV_LOAD_IMAGE_COLOR'
      cv::Mat cv_img = cv::imread(image.first, CV_LOAD_IMAGE_COLOR);
                                               ^
1 error generated.

make: *** [.build_release/src/caffe/layers/window_data_layer.o] Error 1
---------
line 230 is replaced as follows
      //cv::Mat cv_img = cv::imread(image.first, CV_LOAD_IMAGE_COLOR);
      cv::Mat cv_img = cv::imread(image.first, cv::IMREAD_COLOR);
--------

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.


2014년 8월 26일 화요일

Some useful terminal commands

// find some files and do some action to it
$ find . -name '.txt' -print
$ find . -type f -name '.avi' -delete
$ find . -type f -not -name '.mov' -delete
$ find . -type f -not -name '.o' -exec rm -f {} \;

// secure remote copy
$ scp thisfile.txt  id@aaa.bbb.ccc.ddd:/home/folder/destination

// Mac Finder Problem: http://osxdaily.com/2013/11/13/fix-finder-slow-high-cpu-use-mac-os-x/
rm ~/Library/Preferences/com.apple.finder.plist&&killall Finder

2014년 6월 26일 목요일

std::thread in Mac OS X maveric

Multi-thread programming in C++ with STL is so easy now.

C++ 멀티스레드 프로그래밍 아주 쉬워졌음.

$ clang++ thread_test.cpp -std=c++11 -o thrad_test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <vector>
#include <algorithm>
#include <thread>
void executebuf (std::vector<int>& buf, int i)
//void executebuf (int buf[], int i)
{
    buf[i] = i*10;
    if (i==2) // do something
    for (int j=0; j<1000000; j++)
        int x = j*i*i*i;
    fprintf (stderr, "ebuf= %d\n", i);
}
void execute()
{
    std::cout << "Hello Concurrent world" << std::endl;
}
std::string filename;
void execute2() 
{
    for (int i=0; i<1000000; i++// do something
        int x = i*i*i*i;
    std::cout << "Hello Concurrent world 2 " << filename << std::endl;
    filename = std::string("printed");
}
int main() 
{
    std::thread th(execute);
    filename = "this is filename.";
    std::thread th2(execute2);
    th.join();
    th2.join();
    std::cout << filename << std::endl;
    std::vector<int> buf(10);
    std::vector<std::thread> t;
    for (int i=0; i<4; i++) 
        t.push_back( std::thread (executebuf, std::ref(buf), i) );
    for (int i=0; i<4; i++)
        t[i].join();
    for (int i=0; i<4; i++)
        printf ("%d  \n", buf[i]);
        return(0);
}
//EOF//
End.