Open and Save Image file with Python Language, Numpy and OpenCV Packages on PYCharm

in utopian-io •  7 years ago  (edited)

What Will I Learn?

  • You will learn Python
  • You will learn OpenCV
  • You will learn Pycharm

Requirements

  • Pycharm
  • Package Numpy
  • Package OpenCV

Difficulty

  • Basic

Tutorial Contents

Hello All of member Utopian, now I wanna make a tutorial how to make "Application Face Detection and Digital Imaging with Python," but first you must know, what is numpy and read my previous tutorials to understand in this tutorial.

Explanation OpenCV

OpenCV is the main module used to perform processing on the creation of "Application Face Detection and Digital Imaging with Python." OpenCV can perform many tasks, from reading image files, performing color editings, to detecting faces efficiently.

Add Numpy Package on PYCharm [linux].

1 . Open your Terminal. Write this command sudo pip install opencv-python

1.png

2 . Open your PYCharm. Click File > Settings > Project: facedetector > Project Interpreter > click +.

2.png

3 . search opencv-python > click install package.

3.png

4 . Test your OpenCV package. Click right on project facedetector > new > Python file > Set Name file with tes-opencv > write this code.

import cv2
print (cv2.__version__)

5 . Run it. if success, congratulation your OpenCV package already installed.

4.png

Add Numpy Package on PYCharm [Windows].
  1. open this link
  2. Select sourceforge on line Windows self-extracting archive and download it.
  3. Search the file you downloaded and extract the opencv file.
  4. Open folder opencv\build\python\2.7\x86 and then copy file cv2.
  5. Open folder C:\Python27\DLLs and paste file cv2.
  6. Open folder C:\Python27\Lib\site-packages and paste file cv2.
  7. Open your PYCharm and restart it.
  8. Test your OpenCV package. Click right on project name > new > Python file > Set Name file with tes-opencv > write this code.
import cv2
print (cv2.__version__)

9 . Run it. if success, congritulation your OpenCV package allready installed.

Open image file with python, OpenCV and NumPY packages on PYCharm

1 . copy an image file to project facedetector folder.
5.png

2 . Create New python file, set name with load-image.
3 . Write this code.

import numpy as np
import cv2 as cv

img = cv.imread('test.jpg',1)
cv.imshow('image',img)
cv.waitKey(0)
cv.destroyAllWindows()

4 . Run it, and see that result.
6.png

Explain Source Code.

This code to call numpy and opencv packages.

import numpy as np
import cv2 as cv

This code to make variable img and use opencv to read test.jpg image file and 1 to read image as full color, if 0 to read image as grayscale, if -1 will be opened as is.

img = cv.imread('test.jpg',1)

This code to show image on variable img.

cv.imshow('image',img)

This code to close the window after you click any button. 0 intends to close the window within 0 milliseconds.

cv.waitKey(0)

This code to close all open windows.

cv.destroyAllWindows()
Save image file with python, OpenCV and NumPY packages on PYCharm

1 . Create New fpython file one project facedetector, and set name save-image
2 . Write this code.

import numpy as np
import cv2 as cv

img = cv.imread('test.jpg',0)
cv.imshow('image',img)
cv.waitKey(0)
cv.imwrite('test2.jpg',img)
cv.destroyAllWindows()

3 . Run it, and see result.

result.gif

Explain Source Code.

This code to make variable img and use opencv to read test.jpg image file and 0 to read image as grayscale, if 1 to read image as full color, if -1 will be opened as is.

img = cv.imread('test.jpg',0)

This code to save a new image file with name test2.jpg after you click any button.

cv.imwrite('test2.jpg',img)

Okay all this tutorial to continue with another tutorial.

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Your contribution cannot be approved because it does not follow the Utopian Rules.

Hi, this is the reason your contribution was rejected

The tutorial is too trivial to be accepted and has nothing to do with the title of your tutorial. You only install numpy, pycharm and opencv created a file and saved it - this is much too little information and simply too trivial to be a valuable contribution.

You can contact us on Discord.
[utopian-moderator]

Hey @creon, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

Its PyCharm, not PYChram.

thanks dude
i was in a hurry