Individual cropping values aded for all sides

Former-commit-id: 7e4013f745669bf38a9d2043731e0747d81241d5
This commit is contained in:
johan 2014-02-04 21:12:51 +01:00
parent 9dca67c3a3
commit bad5b34796
3 changed files with 58 additions and 16 deletions

View File

@ -36,7 +36,19 @@ static void yuv2rgb(uint8_t y, uint8_t u, uint8_t v, uint8_t & r, uint8_t & g, u
}
V4L2Grabber::V4L2Grabber(const std::string &device, int input, VideoStandard videoStandard, int width, int height, int cropHorizontal, int cropVertical, int frameDecimation, int pixelDecimation) :
V4L2Grabber::V4L2Grabber(
const std::string & device,
int input,
VideoStandard videoStandard,
int width,
int height,
int cropLeft,
int cropRight,
int cropTop,
int cropBottom,
int frameDecimation,
int horizontalPixelDecimation,
int verticalPixelDecimation) :
_deviceName(device),
_ioMethod(IO_METHOD_MMAP),
_fileDescriptor(-1),
@ -44,10 +56,13 @@ V4L2Grabber::V4L2Grabber(const std::string &device, int input, VideoStandard vid
_pixelFormat(0),
_width(width),
_height(height),
_cropWidth(cropHorizontal),
_cropHeight(cropVertical),
_cropLeft(cropLeft),
_cropRight(cropRight),
_cropTop(cropTop),
_cropBottom(cropBottom),
_frameDecimation(std::max(1, frameDecimation)),
_pixelDecimation(std::max(1, pixelDecimation)),
_horizontalPixelDecimation(std::max(1, horizontalPixelDecimation)),
_verticalPixelDecimation(std::max(1, verticalPixelDecimation)),
_currentFrame(0),
_callback(nullptr),
_callbackArg(nullptr)
@ -644,14 +659,14 @@ bool V4L2Grabber::process_image(const void *p, int size)
void V4L2Grabber::process_image(const uint8_t * data)
{
int width = (_width - 2 * _cropWidth + _pixelDecimation/2) / _pixelDecimation;
int height = (_height - 2 * _cropHeight + _pixelDecimation/2) / _pixelDecimation;
int width = (_width - _cropLeft - _cropRight + _horizontalPixelDecimation/2) / _horizontalPixelDecimation;
int height = (_height - _cropTop - _cropBottom + _verticalPixelDecimation/2) / _verticalPixelDecimation;
Image<ColorRgb> image(width, height);
for (int ySource = _cropHeight + _pixelDecimation/2, yDest = 0; ySource < _height - _cropHeight; ySource += _pixelDecimation, ++yDest)
for (int ySource = _cropTop + _verticalPixelDecimation/2, yDest = 0; ySource < _height - _cropBottom; ySource += _verticalPixelDecimation, ++yDest)
{
for (int xSource = _cropWidth + _pixelDecimation/2, xDest = 0; xSource < _width - _cropWidth; xSource += _pixelDecimation, ++xDest)
for (int xSource = _cropLeft + _horizontalPixelDecimation/2, xDest = 0; xSource < _width - _cropRight; xSource += _horizontalPixelDecimation, ++xDest)
{
int index = (_width * ySource + xSource) * 2;
uint8_t y = 0;

View File

@ -21,7 +21,19 @@ public:
};
public:
V4L2Grabber(const std::string & device, int input, VideoStandard videoStandard, int width, int height, int cropHorizontal, int cropVertical, int frameDecimation, int pixelDecimation);
V4L2Grabber(
const std::string & device,
int input,
VideoStandard videoStandard,
int width,
int height,
int cropLeft,
int cropRight,
int cropTop,
int cropBottom,
int frameDecimation,
int horizontalPixelDecimation,
int verticalPixelDecimation);
virtual ~V4L2Grabber();
void setCallback(ImageCallback callback, void * arg);
@ -84,10 +96,13 @@ private:
uint32_t _pixelFormat;
int _width;
int _height;
const int _cropWidth;
const int _cropHeight;
const int _cropLeft;
const int _cropRight;
const int _cropTop;
const int _cropBottom;
const int _frameDecimation;
const int _pixelDecimation;
const int _horizontalPixelDecimation;
const int _verticalPixelDecimation;
int _currentFrame;

View File

@ -44,8 +44,12 @@ int main(int argc, char** argv)
IntParameter & argInput = parameters.add<IntParameter> (0x0, "input", "Input channel (optional)");
IntParameter & argWidth = parameters.add<IntParameter> (0x0, "width", "Try to set the width of the video input (optional)");
IntParameter & argHeight = parameters.add<IntParameter> (0x0, "height", "Try to set the height of the video input (optional)");
IntParameter & argCropWidth = parameters.add<IntParameter> (0x0, "crop-width", "Number of pixels to crop from the left and right sides in the picture before decimation [default=0]");
IntParameter & argCropHeight = parameters.add<IntParameter> (0x0, "crop-height", "Number of pixels to crop from the top and the bottom in the picture before decimation [default=0]");
IntParameter & argCropWidth = parameters.add<IntParameter> (0x0, "crop-width", "Number of pixels to crop from the left and right sides of the picture before decimation [default=0]");
IntParameter & argCropHeight = parameters.add<IntParameter> (0x0, "crop-height", "Number of pixels to crop from the top and the bottom of the picture before decimation [default=0]");
IntParameter & argCropLeft = parameters.add<IntParameter> (0x0, "crop-left", "Number of pixels to crop from the left of the picture before decimation (overrides --crop-width)");
IntParameter & argCropRight = parameters.add<IntParameter> (0x0, "crop-right", "Number of pixels to crop from the right of the picture before decimation (overrides --crop-width)");
IntParameter & argCropTop = parameters.add<IntParameter> (0x0, "crop-top", "Number of pixels to crop from the top of the picture before decimation (overrides --crop-height)");
IntParameter & argCropBottom = parameters.add<IntParameter> (0x0, "crop-bottom", "Number of pixels to crop from the bottom of the picture before decimation (overrides --crop-height)");
IntParameter & argSizeDecimation = parameters.add<IntParameter> ('s', "size-decimator", "Decimation factor for the output size [default=1]");
IntParameter & argFrameDecimation = parameters.add<IntParameter> ('f', "frame-decimator", "Decimation factor for the video frames [default=1]");
SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit");
@ -79,15 +83,23 @@ int main(int argc, char** argv)
return 0;
}
if (!argCropLeft.isSet()) argCropLeft.setDefault(argCropWidth.getValue());
if (!argCropRight.isSet()) argCropRight.setDefault(argCropWidth.getValue());
if (!argCropTop.isSet()) argCropTop.setDefault(argCropHeight.getValue());
if (!argCropBottom.isSet()) argCropBottom.setDefault(argCropHeight.getValue());
V4L2Grabber grabber(
argDevice.getValue(),
argInput.getValue(),
argVideoStandard.getValue(),
argWidth.getValue(),
argHeight.getValue(),
std::max(0, argCropWidth.getValue()),
std::max(0, argCropHeight.getValue()),
std::max(0, argCropLeft.getValue()),
std::max(0, argCropRight.getValue()),
std::max(0, argCropTop.getValue()),
std::max(0, argCropBottom.getValue()),
std::max(1, argFrameDecimation.getValue()),
std::max(1, argSizeDecimation.getValue()),
std::max(1, argSizeDecimation.getValue()));
grabber.start();