Posts Tagged ‘OpenCv’

matlab and OpenCV development kit

January 26, 2013 Leave a comment

mexopencv comes from Kota Yamaguchi. It is a development kit which is collection of mex functions for bridging matlab and OpenCV. I have not used it till now, but it looks easy to use. Especially interesting to me is it provides the data conversion utility to transfer matlab data to OpenCV datatypes, so one can use them to write their own mex functions. 

So do use and provide feed back.

Categories: Uncategorized Tags: ,

IPP, new version of OpenCV, cmake and all the mess

June 12, 2010 Leave a comment

After some long time, had to work on OpenCV and for the first time had to use the IPP. IPP is Intel’s high performance routines. They many of them, but I had to work on OpenCV one.

Download it, run it.

Follow these two links for installation help

Before we move ahead, let’s look at the new version of OpenCV. It’s install guide is here. They were recommending CMake, so tried it. Because we are using the IPP here also so carefully have to give the bin address.

The IPP it appears, by searching online,  not to work properly with OpenCV’s new version. Had actually some problem, but it was I think because IPP libraries access the OpenCv libraries and these libraries have their names changed. So copy pasted them and changed new names to old names. Compiled and viola it’s linking.

Well while putting it here, it looks everything is working fine but it took some time before i was able to solve that.

Some lessons actually commonsense things which one forgets the moment you need it most.

1) Every time you add the Environment variable, restart Visual Studio

2) Bad idea to copy paste your dll’s, set their location path in the Environment Variable path.

OpenCv; Small Code using Erode and Dilate

February 16, 2009 Leave a comment

Small Code that reads pbm image, convert it into 1 channel image. Erodes it, dilates it and shows them

#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
#include <iostream>
#include "BlobResult.h"
#include "blob.h"

#ifdef _EiC

#define WIN32


using namespace std;

void main(void){

IplImage *inputImage = cvLoadImage( "0584.pbm", 1 );

IplImage *gray = cvCreateImage( cvSize(inputImage->width,inputImage->height), 8, 1 );

cvCvtColor( inputImage, gray, CV_BGR2GRAY );

IplImage*img = inputImage;

inputImage = gray;


cvNamedWindow( "orig", 1 );

cvShowImage( "orig", inputImage );

IplImage *outputImage;

IplImage *outputImage2;

outputImage = cvCreateImage( cvSize( inputImage->width, inputImage->height ), IPL_DEPTH_8U, 1 );

outputImage2 = cvCreateImage( cvSize( inputImage->width, inputImage->height ), IPL_DEPTH_8U, 1 );

cvErode(inputImage, outputImage, 0, 1);

cvNamedWindow( "erode", 1 );

cvShowImage( "erode", outputImage );

cvDilate(outputImage, outputImage2, 0, 2);

cvNamedWindow( "dilate", 1 );

cvShowImage( "dilate", outputImage2 );






connecting OpenCv with Matlab; Basic

November 13, 2008 24 comments

It took much of the time, but I was able to connect OpenCv with matlab.

Much thanks to the

I took the introductory program given in the

Also help from

Writing C Functions in Matlab form Jason Laska

And modified it to run through matlab.

I named it showImageMt.cpp

So the Matlab code for compiling it was

mex showImageMt.cpp

But for that you have setup the file ‘mexopts.bat‘ as described in the above pdf . You might not able to find it by searching the matlab folder. You can find the path by running the following command in the Matlab


The contents of the file could be see by type(fullfile(prefdir,’mexopts.bat’))

The C++ opencv code is following

// This is a simple, introductory OpenCV program. The program reads an
// image from a file, inverts it, and displays the result.
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>

#include "mex.h"

void justWork(IplImage *img){
int height,width,step,channels;
uchar *data;
int i,j,k;

// get the image data
height    = img->height;
width     = img->width;
step      = img->widthStep;
channels  = img->nChannels;
data      = (uchar *)img->imageData;
printf("Processing a %dx%d image with %d channels\n",height,width,channels);

// create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);

// invert the image
for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)

// show the image
cvShowImage("mainWin", img );

// wait for a key


void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){

if (nrhs != 0)
mexErrMsgTxt("One input required.");
else if (nlhs > 0)
mexErrMsgTxt("Too many output arguments");

IplImage* img = 0;

printf("Usage: main <image-file-name>\n\7");

char *name = "lena.jpg";
// load an image
printf("Could not load image file: %s\n",name);
// release the image
cvReleaseImage(&img );

Read more…

Categories: basic, matlab, OpenCv Tags: , , ,