Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 2088

How can I modify ROI and then add it to the original image using Python?

$
0
0
I am new to Python and OpenCV. My task is to perform some operations on the ROI of an image and then adding back that image to the original image. How could I achieve this? For example, I want to change the colour of the ROI image and then add it back. My code is given below: for (i,c) in enumerate(contours_from_left_to_right): cv2.drawContours(duplicate_img, [c], -1, (0,0,255), 3) cent_moment = cv2.moments(c) centroid_x = int(cent_moment['m10'] / cent_moment['m00']) centroid_y = int(cent_moment['m01'] / cent_moment['m00']) cv2.putText(duplicate_img, str(i+1), (centroid_x, centroid_y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2) cv2.imshow('Contours from Left to Right', duplicate_img) cv2.waitKey(0) (x, y, w, h) = cv2.boundingRect(c) print("Top-Left Corner=",(x,y), "width= ",w,"height =",h) ROI = roi_img[y:y+h, x:x+w] cv2.imwrite("ROI_{}.png".format(image_number), ROI) image_number += 1

Viewing all articles
Browse latest Browse all 2088

Trending Articles