gpt4 book ai didi

opencv - 在单个窗口 OPENCV 中显示多个图像

转载 作者:太空宇宙 更新时间:2023-11-03 21:36:04 25 4
gpt4 key购买 nike

我在 Internet 上找到了这段代码,它似乎与其他人一起工作。但我总是得到这样的东西:examplexx.exe 中 0x012c1073 处的未处理异常:0xC0000005:访问冲突读取位置 0x00000028。

有人知道可能是什么问题吗?

#include <opencv2/imgproc/imgproc.hpp>  
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>


using namespace cv;
using namespace std;

int main()
{
//Image Reading
IplImage* img1 = cvLoadImage( "ball.jpg" );
IplImage* img2 = cvLoadImage( "ball.jpg" );
IplImage* img3 = cvLoadImage( "ball.jpg" );
IplImage* img4 = cvLoadImage( "ball.jpg" );

int dstWidth=img1->width+img1->width;
int dstHeight=img1->height+img1->height;

IplImage* dst=cvCreateImage(cvSize(dstWidth,dstHeight),IPL_DEPTH_8U,3);

// Copy first image to dst
cvSetImageROI(dst, cvRect(0, 0,img1->width,img1->height) );
cvCopy(img1,dst,NULL);
cvResetImageROI(dst);

// Copy second image to dst
cvSetImageROI(dst, cvRect(img2->width, 0,img2->width,img2->height) );
cvCopy(img2,dst,NULL);
cvResetImageROI(dst);

// Copy third image to dst
cvSetImageROI(dst, cvRect(0, img3->height,img3->width,img3->height) );
cvCopy(img3,dst,NULL);
cvResetImageROI(dst);

// Copy fourth image to dst
cvSetImageROI(dst, cvRect(img4->width, img4->height,img4->width,img4->height));
cvCopy(img4,dst,NULL);
cvResetImageROI(dst);

//show all in a single window
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", dst );
cvWaitKey(0);

}

最佳答案

这是 Opencv 2.4.10 的示例:

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

int main(int argc, char *argv[])
{
// read an image
cv::Mat image1= cv::imread("/home/user/im.png");
cv::Mat image2= cv::imread("/home/user/im.png");

int dstWidth = image1.cols;
int dstHeight = image1.rows * 2;

cv::Mat dst = cv::Mat(dstHeight, dstWidth, CV_8UC3, cv::Scalar(0,0,0));
cv::Rect roi(cv::Rect(0,0,image1.cols, image1.rows));
cv::Mat targetROI = dst(roi);
image1.copyTo(targetROI);
targetROI = dst(cv::Rect(0,image1.rows,image1.cols, image1.rows));
image2.copyTo(targetROI);

// create image window named "My Image"
cv::namedWindow("OpenCV Window");
// show the image on window
cv::imshow("OpenCV Window", dst);
// wait key for 5000 ms
cv::waitKey(5000);

return 0;
}

关于opencv - 在单个窗口 OPENCV 中显示多个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28521751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com