11

I am writting code that uses opencv and i need to have access to PI (3.14...), I know that standard math.h has the efinition, but I found it not easy to uses it is not exposed by default.

Does OpenCV has any definition for PI?

mans
  • 15,766
  • 39
  • 153
  • 296
  • Note that the macro `M_PI` [is actually not standard](http://stackoverflow.com/a/5008376/256138). – rubenvb Jul 02 '15 at 11:38

3 Answers3

14

Yes. It defines CV_PI.

I think it's defined in the cv namespace.

Edit: At a closer look it seems that it's available in the global namespace.

Radu Diță
  • 10,795
  • 1
  • 23
  • 31
  • 1
    Nice. Also it appears to be in [opencv2/hal/defs.h](http://docs.opencv.org/master/d5/d64/defs_8h.html#a677b89fae9308b340ddaebf0dba8455f) – AndyG Jul 02 '15 at 11:49
  • typically `CV_` means global namespace but most/many of them were changed to `cv` namespace in opencv 3.0 and got `CV_` removed afaik. – Micka Jul 02 '15 at 11:55
  • Actually `CV_PI` still is the way to go in OpenCV 3.0. `cv::PI` doesn't work. – Maccesch Jan 08 '16 at 18:27
10

In OpenCV python, it seems CV_PI (or cv2.CV_PI) doesn't exist, use numpy.pi.

calocedrus
  • 2,180
  • 18
  • 24
1

Currently CV_PI seems to be in cvdef.h, line 193:

cvdef.h

cvdef.h line 193

#define CV_PI   3.1415926535897932384626433832795

I can confirm as others have mentioned that cv::PI does not seem to be available any longer (probably removed in the OpenCV 2 to OpenCV 3 change over when the OpenCV 1 legacy stuff was depreciated).

cdahms
  • 2,874
  • 7
  • 42
  • 65