Ask Your Question

# Fail to divide circle into 8 equal parts

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 slices edit retag 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 ;-)

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

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,i),i,(0,255,0),2)

# draw the center of the circle

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

cv2.imwrite('detectedcircles',cimg)

cv2.waitKey(0)

cv2.destroyAllWindows()

2

## 1 answer

Sort by » oldest newest most voted 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;
}  more

Official site

GitHub

Wiki

Documentation

## Stats

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

Seen: 979 times

Last updated: Jul 31 '17