Skip to content
← Back to Community
I have some problem with CV using python
Profile icon

I am trying computer vision in repl,
if any one of you could give an example code with explanation, that would be great.

Profile icon
Profile icon

Here is a good example:

import cv2 import sys theimage = cv2.imread(cv.samples.findFile("test.png")) if theimage is None: sys.exit("That image doesn't exist!!!") cv2.imshow("The Image", theimage)

That will display an image in a openCV window. This is a really good starting point, considering that openCV is a really cool but compicated topic. The openCV documentation has some better examples that can also help. Those can be found at

The program above uses the openCV functions to display the image (assuming you have an image called test.png)

Profile icon


This code adds images, and displays them:

import cv2 # Read in the two images image_1 = cv2.imread('bike.jpg') image_2 = cv2.imread('car.jpg') # Sum the two image arrays for all channels result = cv2.add(image_1, image_2) cv2.imshow('result', result) cv2.waitKey(0) cv2.destroyAllWindows()

check this link for more information on opencv.