opencv2.4.8 vs2013内存越界问题

ASK YOUR QUESTION
0
frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" tabindex="0" vspace="0" width="100%" id="I0_1419927285512" name="I0_1419927285512" src="https://apis.google.com/se/0/_/+1/fastbutton?usegapi=1&size=small&count=false&origin=http%3A%2F%2Fanswers.opencv.org&url=http%3A%2F%2Fanswers.opencv.org%2Fquestion%2F18135%2Fopencv-error-assertion-failed-sizewidth0-sizeheight0-in-unknown-function%2F&gsrc=3p&ic=1&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.zh_CN.KsXgXubUsnc.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Ft%3Dzcms%2Frs%3DAGLTcCNbkQdscperceYpLcNOLc6Wj2fVqg#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh&id=I0_1419927285512&parent=http%3A%2F%2Fanswers.opencv.org&pfname=&rpctoken=16621806" data-gapiattached="true" title="+1" style="border-style: none; margin: 0px; position: static; top: 0px; width: 24px; left: 0px; visibility: visible; height: 15px;">

OpenCV Error: Assertion Failed (size.width>0 && size.height>0) in unknown function

asked Aug 4 '13

Gil gravatar image

I am new to OpenCV and I followed the first example in <<opencv 2="" computer="" vision="" application="" programming="" cookbook="">> with OpenCV 2.4.6.0, below is its code:

#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>

int main() {

    //read an image
    cv::Mat image = cv::imread("img.jpg");

    //create image window named "My Image"
    cv::namedWindow("My Image");

    //show the image on window
    cv::imshow("My Image", image);

    //wait key for 5000ms
    cv::waitKey(5000);

    return 1;
}

The code could be compiled successfully and could be run by clicking the executable file in debug folder. But if I press the "F5" key to debug the project, it shows me this error in command windows when the code line runs to 'cv::imshow("My Image", image);' :

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in unknown function, file C:\opencv\modules\highgui\src\window.cpp, line 261

Finally I found if I change

cv::Mat image = cv::imread("img.jpg");

to

cv::Mat image = cv::imread("E:\\OpenCV\\OpenCVProjects\\myFirstOpenCVConsoleApp\\Debug\\img.jpg");

, no error exists. It seems it's a matter with the path of the image file, but I don't want to use absolute path here, could any one tell me what the wrong is with the path? Where could place the img.jpg would be right? Thanks in advance!

1 answer

Sort by » oldest newest most voted
2

answered Aug 4 '13

vinayverma gravatar image

updated Aug 4 '13

I believe you are using Visual Studio. You need to put the file in your project directory (i.e. $(ProjectDir)).

Note that this is different from solution directory. In simple words, it is the directory where your project code files are added by default (When you click Add->New Item).

Hope this helps.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值