Beginner Questions (C++)

asked 2018-09-22 18:54:45 -0500

DC13 gravatar image


Been working on some code for college today and at 6+ hours of nothing, I'm hoping some folks here could point me in the right directions. The class expects us to find everything about open CV online, so I have no course materials to use at all which is the source of my struggle.

I digress. The assignment is as follows: "Use OpenCV to create an 8-bit single-channel image of size 640x480 pixels. In this image, at random locations, place a square of size 100x100 pixels, a rectangle of size 200x160 pixels, and a circle of diameter 70 pixels. Your background should be black. For each object, the center pixel of the object will be black. Other pixels will be given a grayscale value as d where d is the distance of the pixel from the object center (maximized at 255). Make sure that you crop the objects at the borders. If two objects overlap, the object being drawn late takes precedence."

Creating the image and placing the shapes has been easy enough using the built in circle and rectangle functions. From here, however, I have trouble. I know that I need to utilize the central point and then change the value of the pixels around it within a certain range the get a gradient effect I need, though I'm not sure how to separate the shapes and actually do this. I have attempted some things with contours, though tutorials or examples seem to be somewhat slim on the web. The majority of my code is a frankenstein adaptation from the examples I did and is definately no where close to what I want. I assume this is a generally basic thing to do, but any starting point would be appreciated. Thanks!

(Here is the current status of my current work) image description

edit retag flag offensive close merge delete



please show the code, you have so far.

(hey, you're already at 60% !)

also: maths challenge:

where is the center of a rectangle, given x,y,w,h ?

berak gravatar imageberak ( 2018-09-24 05:20:32 -0500 )edit

Dont know if i get you both right - but i think berak already gave you a hint.

  • Get the bounding box of your object
  • Compute the center of the bounding box
  • Compute diff from center to border of bbox

Thats it?

holger gravatar imageholger ( 2018-09-24 06:12:01 -0500 )edit

i guess, the problem is finding the center, hehe. (that's actually vector maths ...)

berak gravatar imageberak ( 2018-09-24 06:14:43 -0500 )edit