Opencv and image cropping (Bugfix #3210)

Added by Denis Gottardello about 4 years ago. Updated almost 4 years ago.

Status:Cancelled Start date:2013-08-12
Priority:Normal Due date:
Assignee:Alexander Smorkalov % Done:


Target version:Next Hackathon
Affected version:2.4.6 (latest release) Operating System:Linux
Difficulty:Easy HW Platform:x86
Pull request:


Opencv and image cropping

As you can see in the attached image (look at the red arrows) OpenCV fails on cropping image. At the left and at the top the image is not perfect.
This happens on Linux with bttv driver.
In the past I have solved by patching the OpenCV function

static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h)
in cap_libvl4.cpp

OpenCV_Bug.jpeg (40 kB) Denis Gottardello, 2013-08-12 11:35 am


Updated by Sergei Nosov about 4 years ago

Hi, Denis! Thx for reporting!

Maybe you could submit your fixes in a pull request?

  • Status changed from New to Incomplete

Updated by Kirill Kornyakov about 4 years ago

Denis, it is not clear what exactly you don't like. I don't understand what you're trying to highlight with the red arrows. And it is not clear what you mean by image cropping, OpenCV doesn't have such function. You also mentioned a patch, can you attach it here, so we can study it?

So, please do the following, otherwise this ticket will be rejected:
  1. Attach your OpenCV code, which behavior you don't like.
  2. Explain your exact issue, and why do you think this is an OpenCV issue. May be this is a camera driver issue, then you have to attach a good image from other software, and a bad OpenCV image, so we can see the difference.
  3. Propose your solution for the problem, since we know nothing about your environment and we don't have bttv driver. So, basically you're supposed to fix the issue yourself, and send a pull request. You should understand, that we don't even have a chance to help you with such an issue...


  • Assignee set to Denis Gottardello
  • Target version set to Next Hackathon

Updated by Denis Gottardello almost 5 years ago

Sorry but I'm not a good english speaker.
As you can see on the first attached image, with some capture adapters like the adapters that use bttv driver, OpenCV returns an image with a rectangle on the left with width 1 cm and another rectangle on the top with height 0.3 mm, look at the two red arrows.
The correct image should be as the image

I have patched the OpenCV version 2.4.3 by modifying the function
static int icvSetVideoSize( CvCaptureCAM_V4L* capture, int w, int h) {
located in cap_libv4l.cpp. The patch is only a comment of

capture->crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
capture->crop.c.left = 0;
capture-> = 0;
capture->crop.c.height = h*24;
capture->crop.c.width = w*24;

But remember: I have copied this piece of code from OpenCV 2.4.6, the 2.4.3 version is different.

  • Status changed from Incomplete to Open

Updated by Alexander Shishkov almost 4 years ago

  • Difficulty set to Easy
  • Assignee changed from Denis Gottardello to Alexander Smorkalov
  • Tracker changed from Bug to Bugfix
  • Category set to highgui-video

Updated by Alexander Shishkov almost 4 years ago

Hello Denis,
thanks for submitting this issue. Unfortunately we have limited resources at the moment. So if there is a chance if you have time to fix this problem that would be highly appreciated! (Please see for details).

Thank you in advance!

Updated by Alexander Smorkalov almost 4 years ago

Denis, thank you for your bug report, but it looks like your camera issue, but not OpenCV bug. We cannot remove force cropping setup, because it breaks some other camera support. I do not found any bttv driver related issues connected with cropping. The only thing I found is reset_crop kernel module parameter. I hope it helps you to solve issue. For more details see LinuxTV wiki:
I close the ticket.

  • Status changed from Open to Cancelled

Also available in: Atom PDF