convert to IplImage

Does anyone know how to convert an image from DirectShow to IplImage?

I tried the following but it does not work.

unsigned char * yourBuffer1 = new unsigned char[size];

IplImage * img= cvCreateImage(cvSize(width,height), IPL_DEPTH_8U, 3);

while(1)
{
if(VI.isFrameNew(device1)){
VI.getPixels(device1, buffer, false, false);
}
cvCopy(buffer, img);
cvNamedWindow(“in”,1);
cvShowImage(“in”,improc);
}

If you have your IplImage set to the right size you should just be able to do this:

  
IplImage * img= cvCreateImage(cvSize(width,height), IPL_DEPTH_8U, 3);   
  
while(1)   
{   
    if(VI.isFrameNew(device1)){   
       VI.getPixels(device1, (unsigned char *)img->imageData, false, false);  
       cvNamedWindow("in",1);   
       cvShowImage("in",improc);       
    }   
  
}  
  
  

cvShowImage looks funny though - what is improc?
shouldn’t it be img?

Also I think you need to call: cvWaitKey(1) after cvShowImage, it doesn’t make sense but it is the HighGui’s way of calling update.

To me this makes sense:

  
IplImage * img= cvCreateImage(cvSize(width,height), IPL_DEPTH_8U, 3);   
  
//no need to create the window in the while loop  
cvNamedWindow("in", CV_WINDOW_AUTOSIZE);   
  
while(1)   
{   
    if(VI.isFrameNew(device1)){   
       VI.getPixels(device1, (unsigned char *)img->imageData, false, false);  
       cvShowImage("in",img);       
       cvWaitKey(1);  
    }   
  
}  
  
cvDestroyWindow("in");  
  

hello Theo,

improc was meant to be img. I changed it to more meaningful name. Some typo errors though.

I managed to get only one screen capture and then it freezes.

According to your instructions, I have to uncheck power management.

I can see at least 5 USB root hub and no USB 2.0 visible.

So unchecked all power management.

The image freezes, but the while loop seems to be running when I add in trace messages.

It apeears that,
VI.getPixels(device1, (unsigned char *)img->imageData, false, false);
is not capturing fresh images.

Could you send me the current code you are using and I’ll test it out here?
Also try before VI.setup calling VI.setUseCallback(false);

I suspect it is more of a timing issue than a freeze issue.

Cheers,
Theo

Here you go Theo, still not working

  
  
#include <stdio.h>  
  
#include "videoInput.h"  
#include <cv.h>  
#include <cxcore.h>  
#include <highgui.h>  
  
int main()  
{  
	//create a videoInput object  
	videoInput VI;  
	  
	//Prints out a list of available devices and returns num of devices found  
	int numDevices = VI.listDevices();  
  
	int device1 = 0;  //this could be any deviceID that shows up in listDevices  
  
	  
	//setup the first device - there are a number of options:  
	VI.setUseCallback(false);  
	VI.setupDevice(device1); 						  //setup the first device with the default settings  
  
	//As requested width and height can not always be accomodated  
	//make sure to check the size once the device is setup  
  
	int width 	= VI.getWidth(device1);  
	int height 	= VI.getHeight(device1);  
	int size	= VI.getSize(device1);  
	IplImage * img = cvCreateImage(cvSize(width,height), IPL_DEPTH_8U, 3);  
	  
	cvNamedWindow("in",1);  
	while(1)  
	{  
		//to get the data from the device first check if the data is new  
		printf("Hello World\n");  
		if(VI.isFrameNew(device1)){  
			VI.getPixels(device1, (unsigned char *)img->imageData, false, false);   
		}  
		cvShowImage("in",img);  
		cvWaitKey(1);  
		Sleep(200);  
	}  
  
	//Shut down devices properly  
	VI.stopDevice(device1);  
	cvDestroyWindow("in");  
	  
	return 0;  
}  
  

Hey armage

the code tags for our forum are square brackets [] not <> brackets :slight_smile:

Just tested that code with a logitech webcam and it worked fine both with and without callback set.

Could you check that you are using the latest videoInput (0.1991) http://muonics.net/school/spring05/videoInput/

Did you try it without the isFrameNew?

Also could you send me the model of your camera / capture card.

Cheers!
Theo

  1. I am using Logitech webcam too. Ya, I remarked out the if statement earlier.

  2. Just another note, I notice that it takes longer to start the the program if using DirectShow. I am currently using HighGui cvCaptureFromCAM for my computer vision with no problems so far. Im using OpenCV downloaded from sourceforge. Sometimes I wonder why you guys still using the older one…must be for some reason?

  3. But I think I need to expore DirectShow due to WindowsXP phasing out.

  4. Does cvCaptureFromCAM work with Vista?

  5. Here are the program execution messages. Anything funny you see?

***** VIDEOINPUT LIBRARY - 0.1991 - TFW07 *****

VIDEOINPUT SPY MODE!

SETUP: Looking For Capture Devices
SETUP: 0) Logitech QuickCam IM/Connect
SETUP: 1 Device(s) found

SETUP: Setting up device 0
SETUP: Logitech QuickCam IM/Connect
SETUP: Couldn’t find preview pin using SmartTee
SETUP: Default Format is set to 320 by 240
SETUP: Device is setup and ready to capture.

Hello World
Hello World
Hello World

  1. I am using Logitech webcam too. Ya, I remarked out the if statement earlier.

Hmm - would you mind trying the openFrameworks movieGrabberExample (or ofxOpenCVExample ) with your camera?

If it freezes with those examples then I am pretty sure it is a videoInput bug.

  1. Just another note, I notice that it takes longer to start the the program if using DirectShow. I am currently using HighGui cvCaptureFromCAM for my computer vision with no problems so far. Im using OpenCV downloaded from sourceforge. Sometimes I wonder why you guys still using the older one…must be for some reason?

I think 005 release is using the newest ones? What release are you working with?
VideoInput takes longer because it is doing a lot of checks for size and video formats that cvCaptureFromCAM doesn’t - as a result I think it supports a lot more hardware than cvCaptureFromCAM (but it is slower to start).

  1. But I think I need to expore DirectShow due to WindowsXP phasing out.
  1. Does cvCaptureFromCAM work with Vista?

No idea - I refuse to install vista :smiley:

  1. Here are the program execution messages. Anything funny you see?

No that all looks normal.
Very strange as I have never heard of any issues with logitech cameras.

Let me know how the of video capture examples run (005 release) - I would be curious to hear how they run.

Cheers!
Theo

a) I tried movieGrabberExample and it is not working in 0.05
b) Im working with VIDEOINPUT LIBRARY - 0.1991
c) When use the older VideoInput Library - 0.199 it worked

The root cause of the problem is from 0.1991 of the library

Wow - that is really strange because 0.1991 fixed a lot of issues that 0.199 had with camera problems so it is really strange to see the opposite.

Good to know though.

Any chance you could tell me the exact model of your camera (model number?) I might try and pick one up and see if I can track down the bug.

Thanks for all the info!
Theo

Morning, Mr. Watson. Yawn… :lol:

Its Logitech QuickCam IM