- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
您好 stackoverflow 社区!我使用的是 MacBook Pro OS X 10.8.5。我从源代码下载了一个内置的 opencv,并用一个简单的例子对其进行了测试。它似乎工作正常。我尽量不使用 IDE。相反,我只是在文本编辑器中编写代码并从终端编译。我用g++ Follow_Ball.cpp -o Follow_Ball pkg-config --cflags --libs opencv
当我这样做时,我没有收到任何错误,但是当我尝试运行可执行文件“./Follow_Ball”时它给了我以下错误。
OpenCV 错误:断言失败(src1.size == dst.size && dst.type() == CV_8U)在 cvInRangeS,文件/opt/local/var/macports/build/_opt_mports_dports_graphics_opencv/opencv/work/opencv- 2.4.7/modules/core/src/arithm.cpp,第 2972 行libc++abi.dylib:终止调用抛出异常中止陷阱:6
附加信息,即可能相关的信息...我正在尝试使用 MacBook Pro 中内置的网络摄像头 http://www.apple.com/macbook-pro/我设置“CvSize size640x480 = cvSize(640,480);”我不确定那是否是我电脑的像素。也许这可能是导致问题的原因?我还注释掉了第 117 行,因为我无法让它工作,而且我认为我不需要它,因为我只在球周围画了一条红线。我对如何调试它有点困惑。
有人可以帮助我吗?我是 opencv 的新手,没有太多关于如何调试它的知识或经验。感谢你们!
("顺便说一句,我正在学习教程 http://www.lirtex.com/robotics/fast-object-tracking-robot-computer-vision/ ")这是代码...
#include <opencv/cvaux.h>
#include <opencv/highgui.h>
#include <opencv/cxcore.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
int main(int argc, char* argv[]){
// Default capture size - 640x480
CvSize size640x480 = cvSize(640,480);
// Open capture device. 0 is /dev/video0, 1 is /dev/video1, etc.
// Web cam video stream is assinged to this
CvCapture *p_capWebCam;
//pointer to an image structure.
//this will be the imput image from webcam
IplImage *p_imgOriginal;
//Pointer to an immage structure
//this will be the processed black and white immage
/* Ipl is short for Intel Immage processing library. This is the standard
structure in opencv to work with immages. */
IplImage *p_imgProcessed;
//Necessary storage variable to pass into cvHoughCircles()
CvMemStorage *p_strStorage;
//pointer to an opencv sequence, will be returned by cvHough Circles() and will contain all circles
// calling cvGetSeqElem(p_seqCircles, i) willreturn 3 element array of i'th circle (see next variable)
CvSeq *p_seqCircles;
//pointer to a 3 element of array of floats
//[0] => x position of detected object
//[1] => y position of detected object
//[2] => Radius of detected object
float *p_fltXYRadius; //pointer to a 3 element array of floats
int i; //loop counter
char charCheckForEscKey; //get char to escape
p_capWebCam = cvCaptureFromCAM(0); //If you have multiple webcams you might not want to use 0
//However, since i have only one i pass the parameter 0
//check if the webcam works
if( p_capWebCam == NULL ){
printf("ERROR: capture is NULL"); //If web cam wasnt plugged in for example we'd exit the program
getchar(); //pause so that user sees the message
return(-1); //exit the program
}
//declare the two windows
cvNamedWindow("Original", CV_WINDOW_AUTOSIZE ); // Origina image from webcam
cvNamedWindow("Processed", CV_WINDOW_AUTOSIZE); // Processed image we will use for detecting circles
p_imgProcessed = cvCreateImage(size640x480, //creates the immage for the Processed window
IPL_DEPTH_8U, 1); //8U is short for 8 bits unsigned //we use 1 for greyscale if collow we use 3
//this is a greyscale immage so each pixel can go from 0->255 greyscale
//it this was color "Red Green Blue" would be a value for each color: well call this
//the depth
// Infinate while loop where fram is grabbed from cam and processed
while(1){ //for each frame...
p_imgOriginal = cvQueryFrame(p_capWebCam); //get frame from webcam
//check to see if the frame capture was sucessfull
if(p_imgOriginal == NULL){ //if frame was not capture sucessfully
printf("ERROR: frame is NULL \n" );
getchar();
break;
}
// 44:46 http://www.youtube.com/watch?v=2i2bt-YSlYQ&list=PLbqNFa0YhiNBHuQOwalaP5jNGExrmsGOO
cvInRangeS(p_imgOriginal, //function input //color
CV_RGB(175, 0 , 0), //this is a macro, we want to capture a red ball at atleast 175 inclusive
CV_RGB(255, 100, 100), //we allow a bit of green and blue: Redis max 256 not inclusive
p_imgProcessed ); //function output //black and white
//alocate storage variable
p_strStorage = cvCreateMemStorage(0); //alocate necessary storage variable to pass int cvHoughCirlces()
//now we apply agousian smoothing to the processed image. this will make it easyer for next func to pic circles
cvSmooth(p_imgProcessed, //function input
p_imgProcessed, //function output
CV_GAUSSIAN, //Use Gaussian filter (averages nearby pixels, with closses having more wheight)
9, //Smothing filter window width
9); //Smoothing filter window height
//imigin a 9x9 box in the input immage it does stuff smooths out the output
//fills a sequential structure with all circles in a processed immgage
p_seqCircles = cvHoughCircles( p_imgProcessed, //input: hast to be greyscale "no color"
p_strStorage, //Needs this we need not know why. passing this makes func ret pointer
CV_HOUGH_GRADIENT , //Only option for this, two pass algorithim for detecting circles
2, // size of this image/ (this value) = accumulator immage
p_imgProcessed->height/4, //min distance in pixels between centers of detected circles
100, //high threshold of Cany edge detector, called by cvHoughCircles
50, //low threshold of Cany edge detector, called by cvHoughCircles
10, //Minimub circle radius
400); //max circle radius
for(i = 0; i < p_seqCircles->total; i++){ //for each element in sequential circles structure( i.e. for each object detected)
p_fltXYRadius = (float*)cvGetSeqElem(p_seqCircles, i); //from the sequential struct, read the i'th value into a pointer to a float
printf("ball position x = %f, y = %f, r = %f \n", p_fltXYRadius[0], //x position at center of circle
p_fltXYRadius[1], //y position at center of circle
p_fltXYRadius[2]); //radius of circle
//draw a small green circle at center of detected object
cvCircle(p_imgOriginal, //draw on the original image
cvPoint(cvRound(p_fltXYRadius[0]), cvRound(p_fltXYRadius[1])), // center point of circle
3, //3 pixel radius of circle
CV_RGB(0, 255, 0), //draw pure green
CV_FILLED); //thickness, fill in the circle
/* this draws a circle around second ball but i dont need it
//draw a red circle around a detected object
cvCircle(p_imgOriginal, //draw on the original image
cvPoint(cvRound(p_fltXYRadius[0]), cvRound(p_fltXYRadius[1])), // center point of circle
cvRound(p_fltXYRadius[2], //radius of the circle in pixels
CV_RGB(255, 0, 0), //draw pure red
3); //thickness of circle in pixels
*/
}// end of for loop
//now we just need to show the images that we already generated
cvShowImage("Original", p_imgOriginal); //original circle with detectec ball overlay
cvShowImage("Processed", p_imgProcessed); //image after processing
cvReleaseMemStorage(&p_strStorage); //release what we alocated earlyer
charCheckForEscKey = cvWaitKey(10); //delay in ms, and get key press, if any
if( charCheckForEscKey == 27) break; // if ascii 27 was pressed jump out of while loop
}// end of while
cvReleaseCapture(&p_capWebCam);
cvDestroyWindow("Original");
cvDestroyWindow("Processed");
return(0);
}// end of program
最佳答案
谢谢,我能够修复原来是像素的错误。我插入了以下代码来动态查找像素大小
CvCapture * camera = cvCreateCameraCapture (CV_CAP_ANY);
IplImage * current_frame = cvQueryFrame (camera);
CvSize size640x480 = cvSize(current_frame->width, current_frame->height); //tried 640, 480 : 600,500 : 500,600
关于c++ - OpenCV 错误 : Assertion failed (src1. size == dst.size && dst.type() == CV_8U) in cvInRangeS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20004724/
测试返回类型为 bool 的方法时。 你应该: expected = true; Assert.AreEqual(expected, actual); 或 Assert.IsTrue(actual);
我最近在编写新的 NUnit 测试时尝试使用 Assert.Equals() 方法。执行此方法时会抛出一个 AssertionException ,说明Assert.Equals 不应该用于断言。 乍
在 Chai 断言库中,当我们已经有了“assert.deepEqual()”时,“assert.equal()”有什么用"和 "assert.strictEqual()"用于严格和深度相等断言?还提
有没有办法断言 puppet 中的变量(或更具体地说,事实)具有特定值,如果没有则中止安装? 对于背景,情况如下: 在大多数情况下,我可以引用主机名,但有时我需要使用 IP 地址。例如,我们的日志收集
喜欢什么: Assert.That(obj.Foo, Is.EqualTo(true)) 或 Assert.True(obj.Foo) 对我来说,这两个断言是等价的,那么应该首选哪个? 最佳答案 在这
如何在 xUnit 中找到多个断言或软断言?我发现 Nunit 有以下能力,试图在 xUnit 中找到类似的选项。 Assert.Multiple(() => { Assert.AreEqua
有什么区别: Assert.Equals和 Assert.AreEqual Assert.NotNull和 Assert.IsNotNull ... ? 最佳答案 Assert.Equals 是一个对
我想写一个像这样工作的断言函数: //the following expression outputs "assertion failed" to std::err and then terminat
有人可以指出差异吗? 以上确实是我的问题,但是如果您也可以与他们分享您的经验以及您为什么使用其中一个。 最佳答案 它们只是两个不同的库,因此只需查看功能,尤其是报告功能,然后选择即可。 因为我是 的作
我无法找到断言 1 失败但断言 2 通过的原因: var a = Test.test1; var b = Test.test1; a.Should().BeSameAs(b); //1 Assert.
我正在为每个步骤使用 NUnit 断言运行自动化 BDD 步骤,即 Then And 我的 UI 测试。 NUnit 断言仅限于每个方法。这意味着如果方法中的断言失败,则不会运行其他步骤。 我正在考虑
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我只是在寻找一些示例,说明何时适合使用 Assert.Catch 或 Assert.Throws 断言单元测试中抛出的任何异常。我知道我也可以使用 ExpectedException,但我特别想知道“
Assert.AreEqual 和 Assert.AreSame 有什么区别? 最佳答案 这意味着 AreSame() 检查它们是否是完全相同的对象 - 如果引用指示内存中的相同对象。 AreEqua
在C#中,有什么区别 Assert.AreNotEqual 和 Assert.AreNotSame 最佳答案 这里给出的几乎所有答案都是正确的,但可能值得举个例子: public static str
我曾经在 NUnit 中使用过它们,它们非常有用。知道如何做类似的事情吗? 编辑,代码示例: bool condition = false;//would be nice not to have th
关于Arrange-Act-Assert的经典测试模式,我经常发现自己在 Act 之前添加了反断言。这样我就知道传递的断言确实是作为操作的结果传递的。 我认为它类似于红绿重构中的红色,只有当我在测试过
每当我创建断言时,Eclipse 都会建议我从这两个包之一导入它。 例如,当我尝试使用 assertArrayEquals() 比较数组时Eclipse 建议从其中之一导入它 org.junit.As
每当我创建断言时,Eclipse 都会建议我从这两个包之一导入它。 例如,当我尝试使用 assertArrayEquals() 比较数组时Eclipse 建议从其中之一导入它 org.junit.As
我是一名优秀的程序员,十分优秀!