Last active
December 18, 2015 00:19
-
-
Save hiccupzhu/5696180 to your computer and use it in GitHub Desktop.
opencv call sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* cvtest.c | |
* | |
* Created on: Mar 26, 2013 | |
* Author: szhu | |
Makefile: | |
CFLAGS=-g | |
CFLAGS+=$(shell pkg-config --cflags opencv) | |
LDFLAGS= $(shell pkg-config --libs opencv) | |
CC=gcc | |
CXX=g++ | |
TARGET=ezimage | |
LIBS=ezimage.lo | |
$(TARGET):$(LIBS) | |
libtool --mode=link $(CC) $(LDFLAGS) -o $@ $+ | |
%.lo: %.c | |
libtool --mode=compile $(CC) $(CFLAGS) -c -o $@ $< | |
%.lo: %.cpp | |
libtool --mode=compile $(CXX) $(CFLAGS) -c -o $@ $< | |
clean: | |
rm -rf *.o *.lo *.a *.la .libs $(TARGET) | |
*/ | |
#include <stdio.h> | |
#include <stdint.h> | |
#include <iostream> | |
#include <cv.h> | |
#include <highgui.h> | |
using namespace std; | |
int get_file_size(FILE* fp){ | |
int size, p1; | |
p1 = ftell(fp); | |
fseek(fp, 0, SEEK_END); | |
size = ftell(fp); | |
fseek(fp, p1, SEEK_SET); | |
return size; | |
} | |
void printIplImage(IplImage *pImage) | |
{ | |
cout << "IplImage大小:" << pImage->nSize << endl; | |
cout << "ID:" << pImage->ID << endl; | |
cout << "nChannels:" << pImage->nChannels << endl; | |
cout << "depth:" << pImage->depth << endl; | |
cout << "dataOrder:" << ((pImage->dataOrder == 0)?("交叉存取颜色通道") : ("分开的颜色通道")) << endl; | |
cout << "origin:" << ((pImage->origin == 0)? ("顶-左结构"):("底-左结构")) << endl; | |
cout << "width:" << pImage->width << endl; | |
cout << "height:" << pImage->height << endl; | |
cout << "ImageSize:" << pImage->imageSize << endl; | |
cout << "widthStep:" << pImage->widthStep << endl; | |
cout << "End" << endl << endl; | |
} | |
int main(int argc, char* argv[]){ | |
int i; | |
IplImage *src, *rimg_plane, *gimg_plane, *bimg_plane; | |
IplImage *img[4]; | |
char *buf, *start; | |
int width, heigh, bpp; | |
// if(argc < 2){ | |
// printf("The args too few.\n"); | |
// return 0; | |
// } | |
src = cvLoadImage("/mnt/hgfs/E/media/cat.bmp", CV_LOAD_IMAGE_ANYCOLOR); | |
printIplImage(src); | |
width = src->width; | |
heigh = src->height; | |
bpp = src->depth * src->nChannels; | |
cvNamedWindow("src", CV_WINDOW_AUTOSIZE); | |
cvNamedWindow("r", CV_WINDOW_AUTOSIZE); | |
cvNamedWindow("g", CV_WINDOW_AUTOSIZE); | |
cvNamedWindow("b", CV_WINDOW_AUTOSIZE); | |
for(i = 0; i < 4; i++){ | |
img[i] = cvCreateImage(cvSize(width, heigh), IPL_DEPTH_8U, bpp/8); | |
} | |
rimg_plane = cvCreateImage(cvSize(width, heigh), IPL_DEPTH_8U, 1); | |
gimg_plane = cvCreateImage(cvSize(width, heigh), IPL_DEPTH_8U, 1); | |
bimg_plane = cvCreateImage(cvSize(width, heigh), IPL_DEPTH_8U, 1); | |
// cvimg = cvLoadImage(argv[1], CV_LOAD_IMAGE_ANYCOLOR); | |
cvSplit(src, rimg_plane, gimg_plane, bimg_plane, NULL); | |
cvMerge(NULL, NULL, rimg_plane, NULL, img[0]); | |
cvMerge(NULL, gimg_plane, NULL, NULL, img[1]); | |
cvMerge(bimg_plane, NULL, NULL, NULL, img[2]); | |
cvShowImage("src", src); | |
cvShowImage("r", img[0]); | |
cvShowImage("g", img[1]); | |
cvShowImage("b", img[2]); | |
cvWaitKey(0); | |
cvDestroyWindow("src"); | |
cvDestroyWindow("r"); | |
cvDestroyWindow("g"); | |
cvDestroyWindow("b"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment