Error -27 Null Array Pointer Is Passed In Function Cvgetmat
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up OpenCV Error: Null pointer with canny up vote 0 down vote favorite I'm trying to learn C and OpenCV. I'm using the following code, inspired from O'Reilly Learning OpenCV, but I get an error and the image doesn't show as expected. Is there something wrong with this code? # include "cv.h" # include "highgui.h" IplImage * doCanny(IplImage *in, double lowThresh, double highThresh, int aperture) { if(1 != in->nChannels){ return 0; } IplImage *out = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1); cvCanny(in, out, lowThresh, highThresh, aperture); return out; } /* This layout works with other functions like cvPyrdown, but for some reason it doesn't work with cvCanny */ int main() { double lowThresh = 50; double highThresh = 150; int aperture = 3; IplImage *img = cvLoadImage("/tmp/lena.jpg", CV_LOAD_IMAGE_UNCHANGED); IplImage *out = doCanny(img, lowThresh, highThresh, aperture); cvNamedWindow("Example2-6", CV_LOAD_IMAGE_UNCHANGED); cvShowImage("Example2-6", out); cvWaitKey(0); cvReleaseImage(&img); cvReleaseImage(&out); cvDestroyWindow("Example2-6"); return 0; } The output I get on Mac OS X Yosemite is: OpenCV Error: Null pointer (NULL array pointer is passed) in cvGetMat, file /opt/local/var/macports/build/.../opencv-2.4.11/.../array.cpp, line 2382 c opencv share|improve this question edited Jul 26 '15 at 13:50 honk 3,177102544 asked Jul 26 '15 at 10:37 ling 1,35611418 please, use opencv's c++ api, not the outdated, and no more maintained c-api –berak Jul 26 '15 at 13:45 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted Your jpg image is most likely a three-channel image. You pass this image as in into your doCanny() function. The following code will cause the doCanny() function to return 0: if(1 != in->nChannels){ return 0; } Then you don't check if the return value of your doCanny() function is valid. Therefore you pass a null pointer to the following function which might cause your null pointer error: cvShowImage("Example2-6", out); In order to make your code working
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Getting error in capturing image through a program in Python up vote 0 down vote favorite I am new to the http://stackoverflow.com/questions/31635986/opencv-error-null-pointer-with-canny Python opencv. Can anybody please help me to sort out the error import cv cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE) camera_index = 1 capture = cv.CaptureFromCAM(camera_index) def repeat(): global capture #declare as globals since we are assigning to them now global camera_index frame = cv.QueryFrame(capture) cv.ShowImage("w1", frame) c = cv.WaitKey(100) if(c=="n"): #in "n" key is pressed while the popup window is in focus camera_index += 1 #try the next camera index capture = cv.CaptureFromCAM(camera_index) if not capture: #if http://stackoverflow.com/questions/14094153/getting-error-in-capturing-image-through-a-program-in-python the next camera index didn't work, reset to 0. camera_index =1 capture = cv.CaptureFromCAM(camera_index) while True: repeat() this is the error what I am getting - OpenCV Error: Null pointer (NULL array pointer is passed) in cvGetMat, file /home/paraste/OpenCV-2.3.1/modules/core/src/array.cpp, line 2382 Traceback (most recent call last): File "dualcamara.py", line 10, in
12:20 AMHi, I'm experimenting with making a python script which handles webcam input. I've found this (http://www.jperla.com/blog/2007/09/26/capturing-frames-from-a-webcam-on-linux/) one that uses OpenCV to capture images. Sadly, it doesn't seem to work for me. https://ubuntuforums.org/archive/index.php/t-1199249.html Running it gives antimatter15@antimatter15-desktop:~/Desktop/mirrortouch$ python webcam2.pyTraceback (most recent call last): File "webcam2.py", line 29, in