11 Replies - 2607 Views - Last Post: 03 July 2009 - 12:05 AM Rate Topic: -----

#1 alexax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 28-June 09

how to work with webcam?

Post icon  Posted 29 June 2009 - 02:51 AM

Hi all, i've been looking for codes that works with webcam using c++ and openCV.. I like to understand how to create an header file. Now my objective is to have the webcam to video left and right images..

Now my code is only capturing. How do i make it into video like talking to someone else and also can enlarge the images?

Something like an webcam which have the magnifier function.

This is my code.
#include <stdafx.h>
#include <iostream>
#include <cv.h>
#include <cvaux.h>
#include <highgui.h>
#include <cvcam.h>


using namespace std;

int main()

{
	
	cout << "Hello EveryOne!!!\n";		// print to screen


	//getchar();			// wait for a key to be pressed

	CvCapture* capture1 = cvCaptureFromCAM(0);
	CvCapture* capture2 = cvCaptureFromCAM(0);



	IplImage* img1 = 0;
	IplImage* img2 = 0; 
	if(!cvGrabFrame(capture1)){			  // capture a frame 
		printf("Could not grab a frame from camera 1\n\7");
		exit(0);
	}
	if(!cvGrabFrame(capture2)){			  // capture a frame 
		printf("Could not grab a frame from camera 2\n\7");
		exit(0);
	}

	img1=cvRetrieveFrame(capture1);		   // retrieve the captured frame
	img2=cvRetrieveFrame(capture2);

	
	// create a window
	cvNamedWindow("Left"); 
	cvMoveWindow("Left", 100, 300);

	cvNamedWindow("Right"); 
	cvMoveWindow("Right", 800, 300);

	// show the image
	cvShowImage("Left", img1 );
	cvShowImage("Right", img2 );

	// wait for a key
	cvWaitKey(0);

	//Release the image
	cvReleaseCapture(&capture1);
	cvReleaseCapture(&capture2);
	return 0;	// the main function returns zero

} 



Is This A Good Question/Topic? 0
  • +

Replies To: how to work with webcam?

#2 Guest_c.user*


Reputation:

Re: how to work with webcam?

Posted 29 June 2009 - 05:25 PM

	for (int i = 0; i < 100; i++) {
		img1 = cvRetrieveFrame(capture1);  // retrieve the frame
		img2 = cvRetrieveFrame(capture2);
   
		// create a window
		cvNamedWindow("Left");
		cvMoveWindow("Left", 100, 300);

		cvNamedWindow("Right");
		cvMoveWindow("Right", 800, 300);

		// show the image
		cvShowImage("Left", img1 );
		cvShowImage("Right", img2);
	}


try this

perhaps
		//Release the image
		cvReleaseCapture(&capture1);
		cvReleaseCapture(&capture2);


must be in the loop too
Was This Post Helpful? 0

#3 alexax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 28-June 09

Re: how to work with webcam?

Posted 29 June 2009 - 09:13 PM

hey what does the code(the one you provided) do? It seems like the same as mine. And is very slow when building it..

I want to make it into video(meaning can move around) rather than just capture images..

This post has been edited by alexax: 29 June 2009 - 09:23 PM

Was This Post Helpful? 0
  • +
  • -

#4 Guest_c.user*


Reputation:

Re: how to work with webcam?

Posted 30 June 2009 - 01:15 AM

try to capture few frames, then show them all in queue, then repeat (with release frames or without release)
and only for one window

This post has been edited by c.user: 30 June 2009 - 01:15 AM

Was This Post Helpful? 0

#5 alexax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 28-June 09

Re: how to work with webcam?

Posted 30 June 2009 - 02:00 AM

How do i show them all in queue?
Was This Post Helpful? 0
  • +
  • -

#6 nzrock95  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 25-June 09

Re: how to work with webcam?

Posted 30 June 2009 - 02:57 PM

Well let's think in plain English for a moment.
A video is just a bunch of pictures played back to represent motion, right? So what you want to do is get a picture, show it in a single window (not sure what you were planning on doing with two, but keep it if it's important), and repeat. The code he gave gets a picture, shows it in a window, and repeats that 100 times, making a "video". It may run too fast for you to see what is happening though, so some kind of wait would help. And you can just create your window once instead of 100 times in the loop.

Good luck!
Was This Post Helpful? 0
  • +
  • -

#7 Guest_c.user*


Reputation:

Re: how to work with webcam?

Posted 30 June 2009 - 05:51 PM

	CvCapture *capture;
	IplImage *img;

	capture = cvCaptureFromCAM(0);
	cvNamedWindow("main");
	for (int i = 0; i < 100; i++) {
		img = cvRetrieveFrame(capture);
		cvShowImage("main", img);
	}
	cvReleaseCapture(&capture); 


try this

This post has been edited by c.user: 30 June 2009 - 05:52 PM

Was This Post Helpful? 1

#8 Guest_c.user*


Reputation:

Re: how to work with webcam?

Posted 01 July 2009 - 11:57 PM

you have no 10 messages, hence

Quote

Is it possible to count number of very small fishes if i use webcam with openCV?

it needs capture every frame, make an image from it and process this image, I think
so it joins to camera just in the capture of a picture, all work will be with this picture even if it is something greater than small fishes
Was This Post Helpful? 0

#9 alexax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 28-June 09

Re: how to work with webcam?

Posted 02 July 2009 - 02:43 AM

hmm... I don't really get what you mean.. It needs to capture every frame and from there process it.
Was This Post Helpful? 0
  • +
  • -

#10 Guest_c.user*


Reputation:

Re: how to work with webcam?

Posted 02 July 2009 - 08:28 PM

you get the frame, then translate it to a picture, then processing this picture: get objects, compare them for concurrences, count percent and probability of equality
all your work with camera is only capture the frame
Was This Post Helpful? 0

#11 alexax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 28-June 09

Re: how to work with webcam?

Posted 02 July 2009 - 08:58 PM

How am i going to translate it to a picture and processing it?

This post has been edited by alexax: 02 July 2009 - 08:59 PM

Was This Post Helpful? 0
  • +
  • -

#12 Guest_c.user*


Reputation:

Re: how to work with webcam?

Posted 03 July 2009 - 12:05 AM

I think you should make a program for comparing two simple pictures, first picture has circle second has square and your program can compare them and return 1 if they are equal and 0 if they are not
try it, if you will have could then your fishes will be a groups of figures
Was This Post Helpful? 0

Page 1 of 1