Ask Your Question
-1

Fail to divide circle into 8 equal parts

asked 2017-07-31 11:30:14 -0500

Yash99 gravatar image

I was trying to write code which detects circle in a pizza and divide circles into 8 equal parts (i.e 8 equal slices angle of 45 degrees). I try using cv2.line() but it is not working.

Can anyone help me out in code to detect slicesimage description

edit retag flag offensive close merge delete

Comments

4

you need to detect a pizza and draw 8 slices or detect slices in a pizza ? in both cases please provide your code. and remember... cv2.line() can't cut your pizza ;-)

pklab gravatar imagepklab ( 2017-07-31 12:13:35 -0500 )edit

it seems like you have already post a question about this...

LBerger gravatar imageLBerger ( 2017-07-31 12:37:41 -0500 )edit

I can detect a pizza but unable to draw slices. Here is my code

import cv2 import cv2.cv as cv

import numpy as np

def main():

img = cv2.imread('testpizza.png',0)



#print(img)



img = cv2.medianBlur(img,5)

cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT, 1, 50)


circles = np.uint16(np.around(circles))

for i in circles[0,:]:

    # draw the outer circle

    cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)

    # draw the center of the circle

    cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)



cv2.imwrite('detectedcircles',cimg)

cv2.waitKey(0)

cv2.destroyAllWindows()
Yash99 gravatar imageYash99 ( 2017-07-31 13:06:00 -0500 )edit
2

the image contains 10 slices :)

sturkmen gravatar imagesturkmen ( 2017-07-31 13:29:44 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-07-31 18:25:02 -0500

i hope this will be helpful

#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>

using namespace cv;

int main()
{
    int lineType = LINE_AA; // change it to LINE_8 to see non-antialiased graphics

    Mat image = Mat::zeros(400, 400, CV_8UC3);

    for(int angle = 0; angle<360; )
    { 
        Point center(200, 200);
        Point perimeter;
        int radius = 150;

        Scalar randomColor((rand() & 255), (rand() & 255), (rand() & 255));
        ellipse( image, center, Size(radius, radius), angle, 45, 0, randomColor, 2, lineType);

        perimeter.x = (int)round(center.x + radius   * cos(angle * CV_PI / 180.0));
        perimeter.y = (int)round(center.y + radius  * sin(angle * CV_PI / 180.0));
        line(image, center, perimeter, randomColor, 2, lineType);

        angle = angle + 45;

        perimeter.x = (int)round(center.x + 150 * cos(angle * CV_PI / 180.0));
        perimeter.y = (int)round(center.y + 150 * sin(angle * CV_PI / 180.0));
        line(image, center, perimeter, randomColor, 2, lineType);

        imshow("slices", image);
        waitKey(0);
    }
    return 0;
}

image description

image description

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-07-31 11:30:14 -0500

Seen: 375 times

Last updated: Jul 31 '17