지금 사용하고 있는 opencv 버전의 설치 위치인
D:\opencv 2.4.9\build\python\2.7\x86
에 있는
cv2.pyd 파일을 다음 위치로 복사한다.
C:\Python27\Lib\site-packages
Python IDLE에서
>>import cv2
특별한 함수가 설치되었는지 유무는
>>help(cv2.SIFT())
또는
>>help(cv2)
등으로 체크할 수 있다.
참고
[1] http://imky.egloos.com/2969966
2014년 12월 22일 월요일
2014년 12월 1일 월요일
OpenCV - Color image In/Out
#pragma once
#include <iostream>
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace std;
using namespace cv;
// Write grayscale image
void WriteIm(String str, unsigned char* im, const Size& sz)
{
Mat bIm = Mat(sz.height, sz.width, CV_8UC1, im);
imwrite(str, bIm);
}
void main()
{
Mat image = imread("face.jpg");
if (image.empty()) return;
cv::Size sz = image.size();
// hsl channel split
Mat hsl;
cvtColor(image, hsl, CV_RGB2HLS);
Mat hslChannels[3];
split(hsl, hslChannels);
unsigned char *im_l = hslChannels[1].ptr<unsigned char>();
unsigned char *im_h = hslChannels[0].ptr<unsigned char>();
unsigned char *im_s = hslChannels[2].ptr<unsigned char>();
// rgb channel split
Mat rgbChannels[3];
split(image, rgbChannels);
unsigned char *im_r = rgbChannels[0].ptr<unsigned char>();
unsigned char *im_g = rgbChannels[1].ptr<unsigned char>();
unsigned char *im_b = rgbChannels[2].ptr<unsigned char>();
// access image pointer
for(int i=0; i<sz.height; i++)
{
for(int j=0; j<sz.width; j++)
{
im_r[i*sz.width+j] = 255 - im_r[i*sz.width+j];
}
}
// Write image
WriteIm("inv_red.jpg", im_r, sz);
waitKey();
}
#include <iostream>
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace std;
using namespace cv;
// Write grayscale image
void WriteIm(String str, unsigned char* im, const Size& sz)
{
Mat bIm = Mat(sz.height, sz.width, CV_8UC1, im);
imwrite(str, bIm);
}
void main()
{
Mat image = imread("face.jpg");
if (image.empty()) return;
cv::Size sz = image.size();
// hsl channel split
Mat hsl;
cvtColor(image, hsl, CV_RGB2HLS);
Mat hslChannels[3];
split(hsl, hslChannels);
unsigned char *im_l = hslChannels[1].ptr<unsigned char>();
unsigned char *im_h = hslChannels[0].ptr<unsigned char>();
unsigned char *im_s = hslChannels[2].ptr<unsigned char>();
// rgb channel split
Mat rgbChannels[3];
split(image, rgbChannels);
unsigned char *im_r = rgbChannels[0].ptr<unsigned char>();
unsigned char *im_g = rgbChannels[1].ptr<unsigned char>();
unsigned char *im_b = rgbChannels[2].ptr<unsigned char>();
// access image pointer
for(int i=0; i<sz.height; i++)
{
for(int j=0; j<sz.width; j++)
{
im_r[i*sz.width+j] = 255 - im_r[i*sz.width+j];
}
}
// Write image
WriteIm("inv_red.jpg", im_r, sz);
waitKey();
}
피드 구독하기:
글 (Atom)