Understanding region of interest in openCV 2.4

Solution 1:

cv::Mat imageROI;
imageROI= image(cv::Rect(385,270,logo.cols,logo.rows));

The cv::Mat constructor wich takes a rectangle as a parameter:

Mat::Mat(const Mat& m, const Rect& roi)

returns a matrix that is pointing to the ROI of the original image, located at the place specified by the rectangle. so imageROI is really the Region of Interest (or subimage/submatrix) of the original image "image". If you modify imageROI it will consequently modify the original, larger matrix.

As for your example, the problem is that you are calling the constructor from an object which does not exists (image). You should replace:

imageROI= image(Rect(385,270,logo.cols,logo.rows));

by:

imageROI= src1(Rect(385,270,logo.cols,logo.rows));

assuming that src1 is your "big image" that you want to insert the logo into (the logo being car1.jpg). You should not forget to first read your big image, by the way!