Python open cv image download

I am new to python and open cv. I am trying to figure out how to upload an image to opencv using python. Can someone provide an example (with code) explaining how to upload an image and display it?

import sys
import cv
from opencv.cv import *
from opencv.highgui import *
ll="/home/pavan/Desktop/iff pics/out0291.tif"
img= cvLoadImage( ll );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
cvWaitKey(10);
cvDestroyWindow( "Example");
+3
source share
3 answers

In openCV2 been several changes:

import cv
ll = "/home/pavan/Desktop/iff pics/out0291.tif"
img = cv.LoadImage(ll)
cv.NamedWindow("Example", cv.CV_WINDOW_AUTOSIZE )
cv.ShowImage("Example", img )
cv.WaitKey(10000)
cv.DestroyWindow("Example")

This is a simpler, pretty clean syntax!

In addition, you do not need to pull ;à-la-matlab. Finally, be careful with the quotation marks that you use.

For the new OpenCV3 API, you should see a different answer to this question.

+7
source
import cv2
image_path = "/home/jay/Desktop/earth.jpg"
img = cv2.imread(image_path)  # For Reading The Image
cv2.imshow('image', img)      # For Showing The Image in a window with first parameter as it title
cv2.waitKey(0)   #waits for a key to be pressed on a window 
cv2.destroyAllWindows() # destroys the window when the key is pressed
0
source

:

  • argparse ():

    import cv2 import argparse ap = argparse.ArgumentParser() 

    ap.add_argument("-i", "--image", required = True,help = "Path to the image") args = vars(ap.parse_args()) 

    image = cv2.imread(args["image"])

, , ap imread()

.

python filename.py -i img.jpg

  1. Hardcoding :

    import cv2 img = cv2.imread("\File\Loca\img.jpg") cv2.imshow("ImageName",img) cv2.waitKey(0) cv2.destroyAllWindows()

Run it the same way, omitting the arguments.

0
source

Source: https://habr.com/ru/post/1763768/


All Articles