thearn / webcam-pulse-detector

A python application that detects and highlights the heart-rate of an individual (using only their own webcam) in real-time.
Other
3.16k stars 596 forks source link

error: (-215) p.checkVector(2, CV_32S) >= 0 in function polylines #1

Closed Mononofu closed 11 years ago

Mononofu commented 11 years ago

Your project looks awesome and I'm dying to try it, but unfortunately it crashes for me when I press D to show the gathered data.

I get this stack trace:

OpenCV Error: Assertion failed (p.checkVector(2, CV_32S) >= 0) in polylines, file  build/buildd/opencv-2.3.1/modules/core/src/drawing.cpp, line 2064
Traceback (most recent call last):
  File "get_pulse.py", line 127, in <module>
    App.main_loop()
  File "get_pulse.py", line 122, in main_loop
    self.key_handler()
  File "get_pulse.py", line 94, in key_handler
    self.key_controls[key]()
  File "get_pulse.py", line 64, in toggle_display_plot
    self.make_bpm_plot()
  File "get_pulse.py", line 80, in make_bpm_plot
    bg = self.processor.grab_faces.slices[0])
  File "/home/mononofu/tmp/webcam-pulse-detector/lib/interface.py", line 113, in plotXY
    cv2.polylines(z, P, False, (255,255,255),1)
cv2.error: /build/buildd/opencv-2.3.1/modules/core/src/drawing.cpp:2064: error: (-215) p.checkVector(2, CV_32S) >= 0 in function polylines

The parameter P passed to polylines looks like this when the crash happens: (I assume z, the image, can't have any effect)

[array([[ 10,  11],
       [ 18,  12],
       [ 23,  15],
       [ 29,  10],
       [ 35,  41],
       [ 40,  28],
       [ 46,  15],
       [ 52,  22],
       [ 57,  22],
       [ 63,  26],
       [ 68,  31],
       [ 74,  30],
       [ 80,  34],
       [ 85,  33],
       [ 91,  31],
       [ 97,  33],
       [103,  32],
       [108,  33],
       [114,  30],
       [119,  29],
       [125,  28],
       [131,  27],
       [137,  31],
       [142,  33],
       [148,  48],
       [154,  52],
       [160,  55],
       [165,  64],
       [171,  64],
       [177,  70],
       [183,  68],
       [189,  65],
       [194,  59],
       [200,  57],
       [205,  54],
       [211,  48],
       [217,  47],
       [222,  42],
       [228,  44],
       [234,  44],
       [240,  46],
       [245,  48],
       [251,  49],
       [257,  53],
       [263,  53],
       [268,  48],
       [274,  48],
       [280,  43],
       [286,  43],
       [291,  39],
       [297,  37],
       [303,  33],
       [308,  31],
       [314,  34],
       [320,  29],
       [325,  28],
       [331,  25],
       [336,  29],
       [342,  35],
       [347,  32],
       [353,  34],
       [358,  33],
       [364,  33],
       [370,  32],
       [375,  32],
       [381,  33],
       [386,  30],
       [392,  33],
       [397,  29],
       [403,  32],
       [409,  32],
       [415,  28],
       [420,  30],
       [426,  27],
       [432,  29],
       [437,  27],
       [443,  24],
       [448,  24],
       [454,  23],
       [460,  24],
       [465,  20],
       [471,  21],
       [476,  29],
       [482,  31],
       [488,  32],
       [494,  30],
       [499,  32],
       [505,  29],
       [510,  32],
       [516,  35],
       [521,  32],
       [527,  31],
       [533,  32],
       [538,  29],
       [544,  35],
       [550,  37],
       [555,  38],
       [561,  48],
       [567,  48],
       [573,  52],
       [578,  49],
       [584,  50],
       [590,  49],
       [595,  51],
       [601,  55],
       [607,  58],
       [612,  62],
       [618,  60],
       [624,  63],
       [630,  60]]), array([[ 10, 105],
       [ 16, 127],
       [ 22, 142],
       [ 28, 149],
       [ 34, 150],
       [ 40, 146],
       [ 46, 141],
       [ 52, 137],
       [ 59, 136],
       [ 65, 135],
       [ 71, 134],
       [ 77, 131],
       [ 83, 125],
       [ 89, 117],
       [ 95, 107],
       [102,  98],
       [108,  92],
       [114,  90],
       [120,  91],
       [126,  98],
       [132, 106],
       [138, 117],
       [145, 127],
       [151, 135],
       [157, 141],
       [163, 143],
       [169, 142],
       [175, 138],
       [181, 132],
       [188, 124],
       [194, 115],
       [200, 107],
       [206, 101],
       [212,  98],
       [218,  99],
       [224, 102],
       [230, 107],
       [237, 114],
       [243, 120],
       [249, 126],
       [255, 129],
       [261, 130],
       [267, 130],
       [273, 128],
       [280, 126],
       [286, 123],
       [292, 120],
       [298, 118],
       [304, 115],
       [310, 113],
       [316, 112],
       [323, 111],
       [329, 111],
       [335, 113],
       [341, 115],
       [347, 118],
       [353, 120],
       [359, 122],
       [366, 122],
       [372, 122],
       [378, 121],
       [384, 120],
       [390, 119],
       [396, 119],
       [402, 119],
       [409, 119],
       [415, 120],
       [421, 120],
       [427, 120],
       [433, 119],
       [439, 118],
       [445, 117],
       [451, 115],
       [458, 114],
       [464, 113],
       [470, 113],
       [476, 114],
       [482, 116],
       [488, 119],
       [494, 122],
       [501, 125],
       [507, 127],
       [513, 128],
       [519, 126],
       [525, 122],
       [531, 117],
       [537, 112],
       [544, 107],
       [550, 106],
       [556, 106],
       [562, 110],
       [568, 114],
       [574, 119],
       [580, 123],
       [587, 126],
       [593, 128],
       [599, 131],
       [605, 134],
       [611, 139],
       [617, 144],
       [623, 146],
       [630, 143]]), array([[ 10, 208],
       [ 87, 170],
       [164, 197],
       [242, 200],
       [319, 225],
       [397, 219],
       [475, 229],
       [552, 226],
       [630, 230]])]```

Unfortunately I don't know enough about OpenCV to figure out the problem.
amrali commented 11 years ago

Same exact problem here. Also OpenMDAO is such a chore to install and uses quirky ways to install itself. I strongly recommend that you consider an alternative to it.

Mononofu commented 11 years ago

Actualy, OpenMDAO was pretty easy to install for me on Ubuntu 12.10 x64 - what are you using?

One apt-get install for the dependencies, python go-openmdao.py and I was done.

amrali commented 11 years ago

Well... you are right, it's not exactly a chore. It's just the way it installs itself is particularly weird and bloated. Self contained, but non-modular. I would've expected for example (given that it is such a large framework) that it would make itself available through PyPi so all it takes is pip install openmdao or pip install -U openmdao to update it.

mnorkin commented 11 years ago

Lack of comments may be the other reason, why it is hard to fix the code.

Also, consider using PEP8.

davidbstein commented 11 years ago

did you guys run apt-get install python-opencv to get cv2? Looks like this project uses opencv2.3+ versions of polylines and moveWindow (apt-get installs 2.1)

i googled up some instructions:P http://stackoverflow.com/questions/7664803/setup-opencv-2-3-w-python-bindings-in-ubuntu

thearn commented 11 years ago

That's probably it, The installed version (for openCV and the cv2 bindings) on my Ubuntu box is 2.4.4

If someone wants to write a more reliable real-time plotter (using matplotlib or something) and issue a pull request, I'd be all for it.

Mononofu commented 11 years ago

Ah, that makes sense. However, now it apparently doesn't recognize my webcam anymore and just crashes when I run get_pulse.py

I'm not yet sure why that is - do I need a specific video I/O plugin for OpenCV?

thearn commented 11 years ago

Latest push should fix this bug

Mononofu commented 11 years ago

test_webcam.py still crashes for me:

OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /home/mononofu/Downloads/opencv-2.4.5/modules/core/src/array.cpp, line 2482
Traceback (most recent call last):
  File "test_webcam.py", line 23, in <module>
    cv2.imshow("Camera", img)
cv2.error: /home/mononofu/Downloads/opencv-2.4.5/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat