Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8285015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:19:19+00:00 2026-06-08T11:19:19+00:00

I have captured an image with my webcam using the following code: cv.NamedWindow(w1, cv.CV_WINDOW_AUTOSIZE)

  • 0

I have captured an image with my webcam using the following code:

cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
capture = cv.CaptureFromCAM(0)
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, 960)
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 544)

def record():
    frame = cv.QueryFrame(capture)
    cv.ShowImage("w1", frame)
    splitter(frame, 4)

I’m trying to crop it into smaller pieces with cv.GetSubRect:

def splitter(image, split):
    width, height = cv.GetSize(image)
    x = width/split
    y = height/split

    # Form the 4-tuples.
    img_parts = []
    for y_pos in range(split):
        for x_pos in range(split):
            xy_section = (x_pos*x, y_pos*y, (x_pos+1)*x, (y_pos+1)*y)
            # print xy_section
            img_parts.append(xy_section)

    # The cropping.
    cropped_parts = []
    for part in img_parts:
        # print "part "+str(part)
        cropped = cv.GetSubRect(image, part) # Error is thrown here
        cropped_parts.append(cropped)

But I keep getting the error message

OpenCV Error: Incorrect size of input array () in cvGetSubRect, file
/build/buildd/opencv-2.3.1/modules/core/src/array.cpp, line 1262

The captured image’s size is 960×544, and I am splitting it with a list of 4-tuples, of which here are the first four:

  • (0, 0, 240, 136)
  • (240, 0, 480, 136)
  • (480, 0, 720, 136)
  • (720, 0, 960, 136)

The rectangles are taken in that order, and the error is thrown when trying to get the rectangle of the third 4-tuple, (480, 0, 720, 136). The original image is bigger than that (960×544), so what’s going wrong? An identical approach worked in Python’s PIL using image.crop(), but opencv’s alternative seems to work a little bit differently, I just can’t figure out how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:19:21+00:00Added an answer on June 8, 2026 at 11:19 am

    Opencv’s .GetSubRect() works a little bit differently from PIL’s .crop(). Both take as an argument a 4-tuple but they describe the area to be cropped differently.

    PIL .crop():

    (pos_left, pos_top, pos_right, pos_bottom)
    

    For example in a 100×100 sized image (0, 50, 50, 100) crops exactly the bottom left corner of the image, resulting in a 50×50 sized image.

    Opencv .GetSubRect():

    (pos_left, pos_top, width, height)
    

    For a same sized image 100×100, (0, 50, 50, 100) would crop a 50×100 sized area starting from position (0, 50) of the original image. The original image size is exceeded this way and the error is thrown. To crop the bottom left corner, (0, 50, 50, 50) works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code to display an image in imagebox using EmgucV: Capture
I am using following code in WPF to display image in webcam usingEmguCv library
I have an Web-application in which I capture Image using EdgeCamShots Sample Application Saving
I want to be able to take an image that i have already captured
I'm using JMF to capture video stream (webcam) on my Java project. The camera
I have written enough code to preview the webcam video in Flash. Now, I
I have an app that captures image from webcam,I convert it to bitmap, now
I need to capture an image from a webcam (tethered camera, etc.) into a
I'm looking for a way to capture a still image from a webcam without
So I have captured the ID of an image in a jquery variable like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.