Programming/openCV2015. 9. 27. 21:00

슬라이더라고 해야하려나?

그거 추가하는 내용


그나저나.. 2.4.11.0 문서인데 왜 cpp가 아니라 c로 된게 있지 -ㅁ-?


[링크 : http://docs.opencv.org/modules/highgui/doc/user_interface.html]

[링크 : http://docs.opencv.org/doc/tutorials/highgui/trackbar/trackbar.html]

'Programming > openCV' 카테고리의 다른 글

opencv 템플릿 매칭 관련  (0) 2015.09.28
openCV 에피폴라 기하 관련 내용  (0) 2015.09.28
opencv2 마우스 이벤트 / 클릭 위치  (0) 2015.09.25
opencv2.. VideoCapture 클래스..  (0) 2015.09.25
openCV Mat Class  (0) 2014.07.04
Posted by 구차니
Programming/openCV2015. 9. 25. 16:01

클릭할 경우 마우스 이벤트에서 좌표가 나오는군..

윈도우 사이즈랑은 따로 구해야 하려나?..


[링크 : http://opencv-srf.blogspot.kr/2011/11/mouse-events.html]

[링크 : http://docs.opencv.org/modules/highgui/doc/user_interface.html#setmousecallback]

'Programming > openCV' 카테고리의 다른 글

openCV 에피폴라 기하 관련 내용  (0) 2015.09.28
opencv highgui trackbar  (0) 2015.09.27
opencv2.. VideoCapture 클래스..  (0) 2015.09.25
openCV Mat Class  (0) 2014.07.04
openCV2 관련 꿍시렁 꿍시렁  (0) 2014.07.04
Posted by 구차니
Programming/openCV2015. 9. 25. 10:09

예전에 받아둔걸로 다시 해보는데..

음.. 비디오가 몇개 있는진 알 수 없다 인가?!

새로운 API가 나오기 전까지는 일일이 open 해보고 리턴값으로 체크해야 할 듯..


[링크 : http://docs.opencv.org/.../reading_and_writing_images_and_video.html?highlight=videocapture]

[링크 : http://stackoverflow.com/questions/24630158/how-to-get-video-capture-devices-information]

'Programming > openCV' 카테고리의 다른 글

opencv highgui trackbar  (0) 2015.09.27
opencv2 마우스 이벤트 / 클릭 위치  (0) 2015.09.25
openCV Mat Class  (0) 2014.07.04
openCV2 관련 꿍시렁 꿍시렁  (0) 2014.07.04
opencv2 highgui  (0) 2014.07.03
Posted by 구차니
Programming/openCV2014. 7. 4. 18:13
도서관에서 빌려와서 보는 책 정리중
OpenCV2를활용한컴퓨터비전프로그래밍
카테고리 컴퓨터/IT > 프로그래밍/언어
지은이 로버트 라가니에 (에이콘출판, 2012년)
상세보기

가장 많이 쓰일 클래스는 Mat인데 Matrix 답게 이미지를 행렬로 처리하는 클래스이다.

변수
rows , cols, step 은 이미지의 수직, 수평 해상도와 step은 실제 폭(색상이나 바이트 얼라인 포함한 data width)을 나타내며
data는 순수 이미지에 대한 포인터를 돌려준다.

메소드
row() col()은 해당 행/열에 대한 새로운 Matrix를 생성하고
channels()는 몇 채널인지를 알려준다. 만약 RGB라면 3개 채널(R,G,B) 흑백이라면 1채널을 돌려준다.
ptr()은 해당 데이터에 대한 포인터를
at()은 해당 데이터를 돌려준다.

class CV_EXPORTS Mat
{
public:
    //! returns a new matrix header for the specified row
    Mat row(int y) const;
    //! returns a new matrix header for the specified column
    Mat col(int x) const;

    /*! includes several bit-fields:
         - the magic signature
         - continuity flag
         - depth
         - number of channels
     */
    int flags;
    //! the matrix dimensionality, >= 2
    int dims;
    //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
    int rows, cols;
    //! pointer to the data
    uchar* data;

    //! returns element type, similar to CV_MAT_TYPE(cvmat->type)
    int type() const;
    //! returns element type, similar to CV_MAT_DEPTH(cvmat->type)
    int depth() const;
    //! returns element type, similar to CV_MAT_CN(cvmat->type)
    int channels() const;

    //! returns pointer to (i0,i1) submatrix along the dimensions #0 and #1
    uchar* ptr(int i0, int i1);
    const uchar* ptr(int i0, int i1) const;

    //! template version of the above method
    template<typename _Tp> _Tp* ptr(int i0=0);

    //! the same as above, with the pointer dereferencing
    template<typename _Tp> _Tp& at(int i0=0);

    MSize size;
    MStep step;

}; 

Posted by 구차니
Programming/openCV2014. 7. 4. 13:23
openCV 2.3.1
디버그 모드로 하면 tbb_debug.dll 을 요구함
-> intel TBB 설치 하등가..
[링크 : http://stackoverflow.com/questions/7293160/c-tbb-debug-dll-missing]

크아아아앙 45MB에 2분이나 걸려 받았더니 여기에 두구둥!!!



openCV 2.4.7 / 2.4.9
라이브러리가 깨졌는지 메모리 침범하는 듯한 현상 발생
[링크 : http://stackoverflow.com/.../why-do-the-characters-iiii-get-stuck-onto-the-begining-of-my-strings]


걍 짜증나서 2.3.1에 릴리즈 모드 사용중 ㅠㅠ
일단 tbb 정도는 설치해 볼까나..

'Programming > openCV' 카테고리의 다른 글

opencv2.. VideoCapture 클래스..  (0) 2015.09.25
openCV Mat Class  (0) 2014.07.04
opencv2 highgui  (0) 2014.07.03
opencv2 VideoCapture::get() / set() - 웹캠 설정 읽어오기  (2) 2014.07.03
opencv2 채널분리하기(split)  (0) 2014.07.03
Posted by 구차니
Programming/openCV2014. 7. 3. 15:02
highgui는 이미지를 불러오거나 GUI를 꾸미기 위한 기능을 지원한다.

크게는 윈도우 생성/조절/파괴 및 키 입력대기
CV_EXPORTS_W void namedWindow(const string& winname, int flags = WINDOW_AUTOSIZE);
CV_EXPORTS_W void destroyWindow(const string& winname);
CV_EXPORTS_W void destroyAllWindows();

CV_EXPORTS_W void resizeWindow(const string& winname, int width, int height);
CV_EXPORTS_W void moveWindow(const string& winname, int x, int y);

CV_EXPORTS_W int waitKey(int delay = 0);

이미지 불러오기/저장/출력
CV_EXPORTS_W void imshow(const string& winname, InputArray mat);
 
CV_EXPORTS_W Mat imread( const string& filename, int flags=1 );
CV_EXPORTS_W bool imwrite( const string& filename, InputArray img, const vector<int>& params=vector<int>());
CV_EXPORTS_W Mat imdecode( InputArray buf, int flags );
CV_EXPORTS Mat imdecode( InputArray buf, int flags, Mat* dst );
CV_EXPORTS_W bool imencode( const string& ext, InputArray img,
                            CV_OUT vector<uchar>& buf,
                            const vector<int>& params=vector<int>()); 

비디오 캡쳐(파일 및 웹캠 지원)
class CV_EXPORTS_W VideoCapture
{
public:
    CV_WRAP VideoCapture();
    CV_WRAP VideoCapture(const string& filename);
    CV_WRAP VideoCapture(int device);

    virtual ~VideoCapture();
    CV_WRAP virtual bool open(const string& filename);
    CV_WRAP virtual bool open(int device);
    CV_WRAP virtual bool isOpened() const;
    CV_WRAP virtual void release();

    CV_WRAP virtual bool grab();
    CV_WRAP virtual bool retrieve(CV_OUT Mat& image, int channel=0);
    virtual VideoCapture& operator >> (CV_OUT Mat& image);
    CV_WRAP virtual bool read(CV_OUT Mat& image);

    CV_WRAP virtual bool set(int propId, double value);
    CV_WRAP virtual double get(int propId);

protected:
    Ptr<CvCapture> cap;
};


class CV_EXPORTS_W VideoWriter
{
public:
    CV_WRAP VideoWriter();
    CV_WRAP VideoWriter(const string& filename, int fourcc, double fps,
                Size frameSize, bool isColor=true);

    virtual ~VideoWriter();
    CV_WRAP virtual bool open(const string& filename, int fourcc, double fps,
                      Size frameSize, bool isColor=true);
    CV_WRAP virtual bool isOpened() const;
    CV_WRAP virtual void release();
    virtual VideoWriter& operator << (const Mat& image);
    CV_WRAP virtual void write(const Mat& image);

protected:
    Ptr<CvVideoWriter> writer;
};  




Posted by 구차니
Programming/openCV2014. 7. 3. 14:35

v4l2의 문제인지 설정은 잘안되고
못 불러 오는 설정사항도 많다 -_-a

VideoCapture::get
C++: double VideoCapture::get(int propId)
C: double cvGetCaptureProperty(CvCapture* capture, int property_id)

propId – Property identifier. It can be one of the following:
– CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds or video capture timestamp.
– CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
– CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file: 0 - start of the film, 1 - end of the film.
CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
– CV_CAP_PROP_FPS Frame rate.
– CV_CAP_PROP_FOURCC 4-character code of codec.
– CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.
– CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() .
– CV_CAP_PROP_MODE Backend-specific value indicating the current capture mode.
– CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for cameras).
– CV_CAP_PROP_CONTRAST Contrast of the image (only for cameras).
– CV_CAP_PROP_SATURATION Saturation of the image (only for cameras).
– CV_CAP_PROP_HUE Hue of the image (only for cameras).
– CV_CAP_PROP_GAIN Gain of the image (only for cameras).
– CV_CAP_PROP_EXPOSURE Exposure (only for cameras).
– CV_CAP_PROP_CONVERT_RGB Boolean flags indicating whether images should be converted to RGB.
– CV_CAP_PROP_WHITE_BALANCE Currently not supported
– CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently) 

웹캠 설정 덤프
주석처리한 두개는 2.3.1에서는 지원하지 않고 2.4.9 에서 지원하는 항목이다.
                VideoCapture cap(0);
 
               cout << "POS_MSEC : "           << cap.get(CV_CAP_PROP_POS_MSEC) << endl;
                cout << "POS_FRAMES : "         << cap.get(CV_CAP_PROP_POS_FRAMES) << endl;
                cout << "POS_AVI_RATIO : "      << cap.get(CV_CAP_PROP_POS_AVI_RATIO) << endl;
                cout << "POS_FRAME_WIDTH : "    << cap.get(CV_CAP_PROP_FRAME_WIDTH) << endl;
                cout << "POS_FRAME_HEIGHT : "   << cap.get(CV_CAP_PROP_FRAME_HEIGHT) << endl;
                cout << "FPS : "                << cap.get(CV_CAP_PROP_FPS) << endl;
                cout << "FOURCC : "             << cap.get(CV_CAP_PROP_FOURCC) << endl;
//              cout << "FRAME_OUT : "          << cap.get(CV_CAP_PROP_FRAME_OUT) << endl;
                cout << "FORMAT : "             << cap.get(CV_CAP_PROP_FORMAT) << endl;
                cout << "MODE : "               << cap.get(CV_CAP_PROP_MODE) << endl;
                cout << "BRIHTNESS : "          << cap.get(CV_CAP_PROP_BRIGHTNESS) << endl;
                cout << "CONTRAST : "           << cap.get(CV_CAP_PROP_CONTRAST) << endl;
                cout << "SATURATION : "         << cap.get(CV_CAP_PROP_SATURATION) << endl;
                cout << "HUE : "                << cap.get(CV_CAP_PROP_HUE) << endl;
                cout << "GAIN : "               << cap.get(CV_CAP_PROP_GAIN) << endl;
                cout << "EXPOSURE : "           << cap.get(CV_CAP_PROP_EXPOSURE) << endl;
                cout << "CONVERT_RGB : "        << cap.get(CV_CAP_PROP_CONVERT_RGB) << endl;
//              cout << "WHITE_BALANCE : "      << cap.get(CV_CAP_PROP_WHITE_BALANCE) << endl;
                cout << "RECTIFICATION : "      << cap.get(CV_CAP_PROP_RECTIFICATION) << endl; 



'Programming > openCV' 카테고리의 다른 글

openCV2 관련 꿍시렁 꿍시렁  (0) 2014.07.04
opencv2 highgui  (0) 2014.07.03
opencv2 채널분리하기(split)  (0) 2014.07.03
opencv2 rgb2hsv color space 변환하기  (0) 2014.07.02
openCV2 2.3.1 ubuntu 컴파일하기  (0) 2014.07.01
Posted by 구차니
Programming/openCV2014. 7. 3. 14:02
core.hpp에 선언되어 있는 split을 사용하면 된다.
//! makes multi-channel array out of several single-channel arrays
CV_EXPORTS void merge(const Mat* mv, size_t count, OutputArray dst);
//! makes multi-channel array out of several single-channel arrays
CV_EXPORTS_W void merge(const vector<Mat>& mv, OutputArray dst);
    
//! copies each plane of a multi-channel array to a dedicated array
CV_EXPORTS void split(const Mat& src, Mat* mvbegin);
//! copies each plane of a multi-channel array to a dedicated array
CV_EXPORTS_W void split(const Mat& m, CV_OUT vector<Mat>& mv); 

vector<Mat> 형으로 변수를 선언하여
split(src, dst); 식으로 사용하면 되며
imshow에서 channel[0] 이런식으로 하면 채널별로 출력하면 된다.

[링크 : http://opencvexamples.blogspot.com/2013/10/split-and-merge-functions.html#.U7TjMPl_vKl]
[링크 : http://compvisionlab.wordpress.com/2013/03/07/opencv-basics-splitting-rgb-channels/]
[링크 : http://denislantsman.com/?p=103]
[링크 : http://baram4815.tistory.com/entry/OpenCV-2이미지에서-RGB-채널-분리
[링크 : http://baram4815.tistory.com/entry/OpenCVsplit-and-merge]
Posted by 구차니
Programming/openCV2014. 7. 2. 23:45
어렵거나 대단한 코드는 아니고 단순하게 RGB를 HSV로 변환하는 코드이다.

BGR 이니까.. 블루값에 Hue 성분이 들어갔으려나?
나중에 색상 조절해서 채널별로 출력을 해봐야겠다



#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
        VideoCapture cap(0);
        if(!cap.isOpened())
        {
                cout << "No camera detected" << endl;
                return -1;
        }
        else
        {
                cout << "In capture ..." << endl;
        }

        namedWindow( "Display window", WINDOW_AUTOSIZE );

    for(;;)
    {
                Mat frame;
                Mat hsv;
                if(!cap.read(frame)) break;

                cvtColor(frame,hsv, CV_BGR2HSV);
                imshow("Display window", frame);
                imshow("HSV window", hsv);
                if(waitKey(30) >= 0) break;
    }

        return 0;
}

imgproc.hpp에 다음과 같이 정의 되어 있으며
cvtColor()는 독립된 함수로 되어있다.(클래스 랩핑이 안되어 있다)
enum
{
    COLOR_BGR2HSV     =40,
    COLOR_RGB2HSV     =41,
 
    COLOR_COLORCVT_MAX  = 135
};
 
//! converts image from one color space to another
CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn=0 ); 
Posted by 구차니
Programming/openCV2014. 7. 1. 17:49
소스는 이전글 참조
2014/07/01 - [Programming/openCV] - openCV2 2.4.9 + VS2008 좌충우돌 프로젝트 생성하기 

$ g++ cv2cam.cpp `pkg-config --libs opencv` 

$ pkg-config --libs opencv
-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann

[링크 : https://help.ubuntu.com/community/OpenCV ] 

일단.. #if 로 막은 아래소스를 사용한건데
2.3.1에서는 문제없이 되는 것을 봐서는 윈도우에서 라이브러리 버전이 꼬였거나 먼가 설정 문제인 듯 하다.




Posted by 구차니