Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;检测平方后运行命令的算法_C++_Opencv - Fatal编程技术网

C++ c++;检测平方后运行命令的算法

C++ c++;检测平方后运行命令的算法,c++,opencv,C++,Opencv,我有检测正方形的opencv代码。现在我想在detect square之后,代码运行另一个命令 代码如下: #include "cv.h" #include "cxcore.h" #include "highgui.h" #include "math.h" #include <iostream> #include <stdio.h> #include <string.h> #include <sstream> using namespace st

我有检测正方形的opencv代码。现在我想在detect square之后,代码运行另一个命令

代码如下:

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include "math.h"
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <sstream>

using namespace std;

double angle( CvPoint* pt1, CvPoint* pt2, CvPoint* pt0 )
{
    double dx1 = pt1->x - pt0->x;
    double dy1 = pt1->y - pt0->y;
    double dx2 = pt2->x - pt0->x;
    double dy2 = pt2->y - pt0->y;
    return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);
} // angle

IplImage* findSquares4(  IplImage* img,  CvMemStorage* storage )
{
    double s = 0,  t = 0;
    int sdetect =0, sqdetect = 0,sqt = 0;
    CvSeq* contours;
    CvSeq* result;
    CvSeq* squares  =  cvCreateSeq(  0,  sizeof( CvSeq),  sizeof( CvPoint),  storage );

    IplImage* cny = cvCreateImage(cvGetSize(img), 8, 1);

    cvCanny(img, cny, 5, 100, 3);

    cvNamedWindow("canny",CV_WINDOW_AUTOSIZE);
    cvShowImage("canny",cny);

    cvFindContours(  cny,  storage,  &contours,  sizeof( CvContour),  CV_RETR_LIST,  CV_CHAIN_APPROX_SIMPLE,  cvPoint( 0, 0) );

    while(  contours )
    {
        result  =  cvApproxPoly(    contours,
                                sizeof( CvContour),
                                storage,
                                CV_POLY_APPROX_DP,
                                cvContourPerimeter( contours)*0.02,  0 );

        if(  result->total  == 4 &&
             fabs( cvContourArea( result, CV_WHOLE_SEQ)) > 1000 &&
             cvCheckContourConvexity( result) )
        {
            s  =  0;
            for(  int i = 2; i < 5; i++ )
            {
                {
                    t  =  fabs( angle(
                                ( CvPoint*)cvGetSeqElem(  result,  i ),
                                ( CvPoint*)cvGetSeqElem(  result,  i-2 ),
                                ( CvPoint*)cvGetSeqElem(  result,  i-1 )));
                    s  =  s > t ? s : t;
                    cout << "s = " << s<< endl;
                    cout << "t = " << t<< endl;
                }
            } // for
            if(  s < 0.3 )
                for(  int i  =  0; i < 4; i++ )
                    cvSeqPush(  squares,
                          ( CvPoint*)cvGetSeqElem(  result,  i ));
        } // if

    contours  =  contours->h_next;

    } // while
    if ((squares->total/4) = 1)
    {
        sdetect = 1;
    } / /if
    else
    {
        sdetect = 2;
        sleep(0.5);
    } // else

    if (sqdetect != sdetect)
    {
        sqdetect=sdetect;
        switch(sqdetect)
        {
            case 0 : system(NULL) ; break;
            case 2 : cout<< "no "<< endl; break;
            case 1 : system("./ambil1.sh"); break;
        } // switch
    } // if
    sdetect = 0;

    cout<<"Persegi : "<< squares->total/4 <<endl;

    cvReleaseMemStorage(&storage);
    cvClearSeq(squares);

} // findSquares4

void drawSquares(IplImage *img, CvSeq* squares )
{
    CvFont font;
    cvInitFont( &font, CV_FONT_HERSHEY_SIMPLEX, 0.4f, 0.4f, 0,1, 8 );
    int i,j,sdetect,sqdetect = 0;
    CvSeqReader reader;
    cvStartReadSeq( squares, &reader, 0 );

    for( i = 0; i < squares->total; i += 4 )
    {
        j++;
        CvPoint pt[4], *rect = pt;
        int count = 4;

         // read 4 vertices
        memcpy( pt, reader.ptr, squares->elem_size );
        CV_NEXT_SEQ_ELEM( squares->elem_size, reader );
        memcpy( pt + 1, reader.ptr, squares->elem_size );
        CV_NEXT_SEQ_ELEM( squares->elem_size, reader );
        memcpy( pt + 2, reader.ptr, squares->elem_size );
        CV_NEXT_SEQ_ELEM( squares->elem_size, reader );
        memcpy( pt + 3, reader.ptr, squares->elem_size );
        CV_NEXT_SEQ_ELEM( squares->elem_size, reader );

        cvPutText( img, "SQUARE", pt[i], &font, CV_RGB(20,255,0));

        cvPolyLine( img, &rect, &count, 1, 1, CV_RGB(200,0,0), 4, CV_AA, 0 );
    } // for

cvClearSeq(squares);
}  // drawSquares
#包括“cv.h”
#包括“cxcore.h”
#包括“highgui.h”
#包括“math.h”
#包括
#包括
#包括
#包括
使用名称空间std;
双角度(CvPoint*pt1、CvPoint*pt2、CvPoint*pt0)
{
双dx1=pt1->x-pt0->x;
双dy1=pt1->y-pt0->y;
双dx2=pt2->x-pt0->x;
双dy2=pt2->y-pt0->y;
返回(dx1*dx2+dy1*dy2)/sqrt(dx1*dx1+dy1*dy1)*(dx2*dx2+dy2*dy2)+1e-10);
}//角度
IplImage*findSquares4(IplImage*img、CvMemStorage*存储)
{
双s=0,t=0;
int-sdetect=0,sqdetect=0,sqt=0;
CvSeq*等高线;
CvSeq*结果;
CvSeq*squares=cvCreateSeq(0,sizeof(CvSeq),sizeof(CvPoint),存储);
IplImage*cny=cvCreateImage(cvGetSize(img),8,1);
cvCanny(人民币元,万元,5100元,3元);
cvNamedWindow(“canny”,CV\u WINDOW\u AUTOSIZE);
cvShowImage(“canny”,人民币);
cvFindContours(人民币、仓库和等高线、sizeof(CvContour)、CV_RETR_列表、CV_CHAIN_近似值、cvPoint(0,0));
while(等高线)
{
结果=CVAPROXPOLY(轮廓,
sizeof(CvContour),
存储
CV_POLY_近似值_DP,
周长(等高线)*0.02,0;
如果(结果->总计==4&&
晶圆厂(CVA面积(结果,CV_整体顺序))>1000&&
CVV凸性(结果))
{
s=0;
对于(int i=2;i<5;i++)
{
{
t=fabs(角度(
(CvPoint*)cvGetSeqElem(结果,i),
(CvPoint*)cvGetSeqElem(结果,i-2),
(CvPoint*)CVGetSekelem(结果,i-1));
s=s>t?s:t;

cout程序等待下级命令完成。在此期间,它不会响应

如果这是您所需要的,
系统
就足够了

如果您想触发并忘记,可以使用
fork/exec
对,或者只使用shell
&
操作符在后台运行stuff


如果需要启动,请更改程序的行为,然后在从属命令完成时将其更改回来,您几乎必须使用
fork/exec/SIGCHLD/waitpid
组合。

程序将等待从属命令完成。在此期间,它不会响应

如果这是您所需要的,
系统
就足够了

如果您想触发并忘记,可以使用
fork/exec
对,或者只使用shell
&
操作符在后台运行stuff


如果需要启动,请更改程序的行为,然后在从属命令完成后将其更改回来,您几乎必须使用
fork/exec/SIGCHLD/waitpid
组合。

什么是“启动并忘记”呢?启动从属程序,让它与主程序并行运行,而不需要与主程序之间进行任何交互第二,你所说的“开火并忘记”是什么意思?启动从属程序,让它与主程序并行运行,两者之间没有任何交互。