>

2017년 4월 17일 월요일

Install OpenCV 3.2 in Mac OS X


$ brew update
$ brew info opencv3

## this is my own choice

$ brew install --force opencv3 --c++11 --with-contrib --with-examples --with-ffmepg --with-gphoto2 --with-opengl --with-python3 --with-qt --with-tbb


2016년 10월 23일 일요일

install opencv3 into openframeworks, once and for all

opencv library comes separately, so whenever opencv is required for an OF project, we need extra setup.

Now, this is a one-time set-up method.

  1. install opencv library somewhere like '/usr/local'. You need to make a static library! Then, combine all the static libraries into one file: libopencv.a
  2. copy the header files and library into $OF/libs/opencv/include and $OF/libs/opencv/lib
  3. edite CoreOF.xcconfig in the openframeworks folder, or you can find it in xcode by opening any example project.
  4. done.



If you have a dynamic libraries, do the above only for include files. Libraries are included in your project through the xcode-project. Make 'New Group' and put all the dynamic libraries; they will be linked automatically during the Build time.

2016년 9월 26일 월요일

using opencv histogram cv::calcHist()

The example in opencv distribution is not clear.
Here I added some more to make it clear.

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

#include <iostream>

using namespace cv;
using namespace std;

int _brightness = 100;
int _contrast   = 100;

Mat image;

/* brightness/contrast callback function */
static void updateBrightnessContrast( int /*arg*/, void* )
{
    int brightness = _brightness - 100;
    int contrast = _contrast - 100;

    /*
     * The algorithm is by Werner D. Streidt
     * (http://visca.com/ffactory/archives/5-99/msg00021.html)
     */
    double a, b;
    if( contrast > 0 )
    {
        double delta = 127.*contrast/100;
        a = 255./(255. - delta*2);
        b = a*(brightness - delta);
    }
    else
    {
        double delta = -128.*contrast/100;
        a = (256.-delta*2)/255.;
        b = a*brightness + delta;
    }

    Mat dst, hist;
    image.convertTo(dst, CV_8U, a, b);
    imshow("image", dst);

    int nImages = 1;
    int channels[1] = {0};
    const int histDim = 1;
    int histSize[histDim] = {64};
    float hist_range[] = {0,256};
    const float *ranges[] = { hist_range };
    calcHist(&dst, nImages, channels, Mat(), 
             hist, histDim/*dimension of the histogram*/, 
             histSize, ranges);

    Mat histImage = Mat::ones(200, 320, CV_8U)*255;

    normalize(hist, hist, 0, histImage.rows, CV_MINMAX, CV_32F);

    histImage = Scalar::all(255);
    int binW = cvRound((double)histImage.cols/histSize[0]);

    for( int i = 0; i < histSize[0]; i++ )
        rectangle( histImage, Point(i*binW, histImage.rows),
                   Point((i+1)*binW, histImage.rows - cvRound(hist.at<float>(i))),
                   Scalar::all(0), -1, 8, 0 );
    imshow("histogram", histImage);
}
static void help()
{
    std::cout << "\nThis program demonstrates the use of calcHist() -- histogram creation.\n"
              << "Usage: \n" << "demhist [image_name -- Defaults to baboon.jpg]" << std::endl;
}

const char* keys =
{
    "{1| |baboon.jpg|input image file}"
};

int main( int argc, const char** argv )
{
    help();

    CommandLineParser parser(argc, argv, keys);
    string inputImage = parser.get<string>("1");

    // Load the source image. HighGUI use.
    image = imread( inputImage, 0 );
    if(image.empty())
    {
        std::cerr << "Cannot read image file: " << inputImage << std::endl;
        return -1;
    }

    namedWindow("image", 0);
    namedWindow("histogram", 0);

    createTrackbar("brightness", "image", &_brightness, 200, updateBrightnessContrast);
    createTrackbar("contrast", "image", &_contrast, 200, updateBrightnessContrast);

    updateBrightnessContrast(0, 0);
    waitKey();

    return 0;

}

2016년 9월 4일 일요일

Using OpenCV3.x in OpenFrameworks0.9.3, Mac OS X

0. Well, you need to install opencv3.1 somewhere in your computer. In my case, I installed it in /usr/local/ocv3 because I have opencv2.x version previously installed. All the opencv3.x files are in /usr/local/ocv3.

1. In your Xcode project, find the file Project.xconfig, and put the search path as shown in the image below.

2. Likewise, put the library files in the opencv3 folder, which was created by yourself.


3. Now, you can use opencv in openframeworks.


In the following, 
 - An image named 'bikers.jpg' is loaded into bikersImage, which is an instance of ofImage
 - The image information of bikersImage  is put into cvImg, which is an instance of cv::Mat
 - In ofApp::update() function, some image processing is applied to cvImg. In this case cv::blur() enforces box filtering.
 - To display the filtered result on the screen, you need bikersImage.update(), which updates its texture memory for display. 
 - In ofApp::display() function, the command bikersImage.update(0,0) will show you a very much blurred image, I am sure.


EOF

2016년 8월 29일 월요일

Simple Setup: ssh login without password from Mac to Linux


Step 1. In your Mac computer. Use terminal of course.

$ ssh-keygen 

Some questions will be provided. Just press Enter key.

Step 2. Copy ~/.ssh/id_rsa.pub to Linux

$ cat ~/.ssh/id_rsa.pub | ssh user_id@your.linux.machine "umask 077; mkdir -p .ssh ; cat >> .ssh/authorized_keys"

You will be asked to provide password for user_id@your.linux.machine.

Step 3. ssh login to Linux machine without password.

$ ssh your.linux.machine

Done.

2016년 8월 17일 수요일

ssh X11 Forwarding Ubuntu Server Setting


$ sudo vi /usr/share/lightdm/lightdm.conf.d/50-xserver-command.conf 
  1 [SeatDefaults]
  2 # Dump core
  3 xserver-command=X -core

  4 xserver-allow-tcp=true

* At the client side (Not sure if X11 needs be run before the followings)
$ xhost +
$ ssh -X user@ubuntu.host

2016년 2월 4일 목요일

Installing OpenCV 3.1, Qt5.5

date: 2015.02.05

Qt5.5

update: Cuda, NVIDIA Web Driver.

[ 25%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_gpu_mat.cu.o
nvcc fatal   : The version ('70002') of the host compiler ('Apple clang') is not supported
CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:206 (message):
  Error generating
  /Users/yndk/Desktop/github/opencv/myBuild-make/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o


NVIDIA compilation is not compatible with OS X El Capitane.
There is a way.

https://devtalk.nvidia.com/default/topic/879431/nvcc-amp-clang-7-no-typo-here-

But, I don't like it.

So disable CUDA.


Done.