2014-01-20 44 views
0

我想了一会儿,现在使用从C#调用的C++ DLL 在openCV(2.4.6 - 现在2.4.8)中执行一些拼接。 似乎一切都正常,直到缝纫开始:(已解决)C++ CLI openCV拼接访问冲突

int _imageCount; 
Mat _images[40]; 

void OpenCvInterop::AddImage(cli::array<cli::array<unsigned char>^>^ pCBuf, cli::array<int>^ pArrCounters) 
{ 
    Stitcher stitcher = Stitcher::createDefault(false); 

    std::vector<Mat> imgs; 
    std::vector<IplImage*> imgsRead; 

    // assuming just 2 imgs for now 
    for(int i = 0; i<2; i++) 
    { 
     //size of the img 
     int arrCount = pArrCounters[i]; 

     //copy the arr to vector 
     array<unsigned char>^ myArr = pCBuf[i]; 
     std::vector<char> msg(arrCount, '\0'); 
     for(int xx = 0;xx<arrCount;xx++) 
     { 
      msg[xx] = (char)myArr[xx]; 
     } 

     //writing the vector back to file - success 
     //std::ofstream outfile ("new.jpg",std::ofstream::binary); 
     //outfile.write ((const char*)&msg[0], msg.size()); 

     //clone imgs 
     cv::Mat imgMat = Mat(cvCloneImage(&(IplImage)cv::imdecode(Mat(msg), CV_LOAD_IMAGE_UNCHANGED).clone())); 
     cv::Mat image = Mat(cvCloneImage(&(IplImage)imgMat.clone())); 

     //apply filter - success 
     cv::GaussianBlur(imgMat, image, cv::Size(0, 0), 3); 
     cv::addWeighted(imgMat, 1.5, image, -0.5, 0, image); 

     //copy again - success 
     IplImage* writeImage = cvCloneImage(&(IplImage)image); 
     //saving the image - success 
     cvSaveImage("readfirst.jpg", writeImage); 

     //copy again - success 
     Mat(writeImage).copyTo(_images[i]); 
     cvReleaseImage(&writeImage); 

     //add to array 
     imgs.push_back(_images[i].clone()); 
     _imageCount += 1; 
    } 

    Mat pano1; 
    //array imgs is filled properly 
    //gives access violation here: 
    stitcher.stitch(imgs, pano1); 

如果我读使用imread一切都好图像。 imshow也能很好地显示图像 - 即使应用了锐化滤镜。 由于提前, 蒂诺

+0

请按照此过程并编辑您的问题:http://msdn.microsoft.com/en-us/library/6decc55h.aspx – baci

+0

av是在opencv_core248 lib中指出有访问内存0x00000000 – user3216683

+0

get为了天堂的缘故,摆脱那iplimages! *从不*将C++与可怕的c-api混合在一起 – berak

回答

0

发现了解决由我自己:

我在一个新的文件夹中创建再解决方案,建造新的OpenCV和它的工作。