Skip to content

Commit

Permalink
opencv scaling
Browse files Browse the repository at this point in the history
svn path=/trunk/yarp2/; revision=4590
  • Loading branch information
paulfitz committed Jan 8, 2007
1 parent b659492 commit 5e0e4f3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Carlos Beltran (sound code via YARP1)
Jonas Ruesch (video4linux support in ffmpeg_grabber)
Assif Mirza (dimax_u2c driver, helped debug cmake library finding issues)
Hatice Kose-Bagci (updated FindPortAudio script for Windows)
Jose Gaspar (helped modify example/external/nameclient.cpp example for windows)
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
2007-01-08 Paul Fitzpatrick <[email protected]>

* src/libYARP_dev/src/opencv_grabber: Made driver pay attention
to width, height.

* src/libYARP_OS/src/ffmpeg: Added FfmpegWriter as basic
interface to ffmpeg's media writing capability.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ class yarp::dev::OpenCVGrabber : public IFrameGrabberImage, public DeviceDriver
/** Whether to loop or not */
bool m_loop;

bool m_saidSize;
bool m_saidResize;

/* reading from file or camera */
bool fromFile;

/** Opaque OpenCV structure for image capture. */
void * m_capture;

Expand Down
44 changes: 41 additions & 3 deletions src/libYARP_dev/src/opencv_grabber/default/yarp/OpenCVGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ using namespace yarp::sig;
using namespace yarp::dev;


#define DBG if (0)

bool OpenCVGrabber::open(Searchable & config) {
// Release any previously allocated resources, just in case
close();

m_saidSize = false;
m_saidResize = false;

// Are we capturing from a file or a camera ?
ConstString file = config.check("movie", Value(""),
"if present, read from specified file rather than camera").asString();
bool fromFile = (file!="");
fromFile = (file!="");
if (fromFile) {

// Try to open a capture object for the file
Expand Down Expand Up @@ -111,13 +115,21 @@ bool OpenCVGrabber::open(Searchable & config) {
// present, otherwise query the capture device
if (config.check("width","if present, specifies desired image width")) {
m_w = config.check("width", Value(-1)).asInt();
if (!fromFile && m_w>0) {
cvSetCaptureProperty((CvCapture*)m_capture,
CV_CAP_PROP_FRAME_WIDTH, m_w);
}
} else {
m_w = (int)cvGetCaptureProperty((CvCapture*)m_capture,
CV_CAP_PROP_FRAME_WIDTH);
}

if (config.check("height","if present, specifies desired image height")) {
m_h = config.check("height", Value(-1)).asInt();
if (!fromFile && m_h>0) {
cvSetCaptureProperty((CvCapture*)m_capture,
CV_CAP_PROP_FRAME_HEIGHT, m_h);
}
} else {
m_h = (int)cvGetCaptureProperty((CvCapture*)m_capture,
CV_CAP_PROP_FRAME_HEIGHT);
Expand Down Expand Up @@ -198,6 +210,12 @@ bool OpenCVGrabber::getImage(ImageOf<PixelRgb> & image) {
// memory allocation if the image is already the correct size
image.resize(iplFrame->width, iplFrame->height);

if (!m_saidSize) {
printf("Received image of size %dx%d\n",
image.width(), image.height());
m_saidSize = true;
}

// Get an IplImage, the Yarp Image owns the memory pointed to
IplImage * iplImage = (IplImage*)image.getIplImage();

Expand All @@ -212,8 +230,28 @@ bool OpenCVGrabber::getImage(ImageOf<PixelRgb> & image) {
cvCvtColor(iplImage, iplImage, CV_BGR2RGB);
}

printf("%d by %d %s image\n", image.width(), image.height(),
iplFrame->channelSeq);
if (m_w<=0) {
m_w = image.width();
}
if (m_h<=0) {
m_h = image.height();
}
if (fromFile) {
if (m_w>0&&m_h>0) {
if (image.width()!=m_w || image.height()!=m_h) {
if (!m_saidResize) {
printf("Software scaling from %dx%d to %dx%d\n",
image.width(), image.height(),
m_w, m_h);
m_saidResize = true;
}
image.copy(image,m_w,m_h);
}
}
}

DBG printf("%d by %d %s image\n", image.width(), image.height(),
iplFrame->channelSeq);
// That's it
return true;

Expand Down
9 changes: 8 additions & 1 deletion src/libYARP_sig/src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,8 @@ bool Image::copy(const Image& alt) {
int myCode = getPixelCode();
if (myCode==0) {
setPixelCode(alt.getPixelCode());
setPixelSize(alt.getPixelSize());
setQuantum(alt.getQuantum());
}
resize(alt.width(),alt.height());
int q1 = alt.getQuantum();
Expand Down Expand Up @@ -952,9 +954,14 @@ void Image::setExternal(void *data, int imgWidth, int imgHeight) {


bool Image::copy(const Image& alt, int w, int h) {
if (getPixelCode()==0) {
setPixelCode(alt.getPixelCode());
setPixelSize(alt.getPixelSize());
setQuantum(alt.getQuantum());
}
if (&alt==this) {
FlexImage img;
img.copy(*this);
img.copy(alt);
return copy(img,w,h);
}

Expand Down

0 comments on commit 5e0e4f3

Please sign in to comment.