DEV Community

Cover image for 2 Python Project Ideas for Beginners
Ochwada Linda
Ochwada Linda

Posted on

2 Python Project Ideas for Beginners

1. Text Detection and Extraction using OpenCV and OCR.

OpenCV (Open source computer vision) is a library mainly aimed at real-time computer vision, in python it helps to process an image and apply various functions e.g. pixel manipulations, object detection, etc. For this project using contours to detect the text in an image and save it to a text file.

Requirements

conda install -c conda-forge opencv
conda install -c conda-forge pytesseract
Enter fullscreen mode Exit fullscreen mode
Coding

I will use the following sample image:

Sample image for text detection

import cv2
import numpy as np
import pytesseract as pyt

image = cv2.imread('The_Zen_of_Python.jpeg')

# image convertion to grey scale
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image_gray, binary_image = cv2.threshold(image_gray, 128,255, cv2.THRESH_BINARY)
image_gray =cv2.bitwise_not(binary_image)

kernel = np.ones((2,1), np.uint8)
image = cv2.erode(image_gray, kernel,iterations = 1)
image = cv2.dilate(image_gray, kernel,iterations = 1)
Enter fullscreen mode Exit fullscreen mode

The next code will convert the image into a string and print the string as text.

# image conversion into string
image_text = pyt.image_to_string(image)

print(image_text)
Enter fullscreen mode Exit fullscreen mode

Check out the video of the project above -Project video

2. Stock Price Visualisation using Yahoo's yfinance .

yfinance is an open source library developed by Ran Aroussi as a means to access the financial data available on Yahoo Finance.

Yahoo Finance offers a wide range of market data on stocks, bonds, currencies and cryptocurrencies. In addition it offers market news, reports and analysis and fundamentals data- setting it apart from some of it’s competitors.

Requirements

pip install yfinance
conda install -c conda-forge pandas
pip install plotly-express
Enter fullscreen mode Exit fullscreen mode
Coding
import yfinance as yf
import pandas as pd
import datetime 
from datetime import date, timedelta

today = date.today()

date1 = today.strftime("%Y-%m-%d")
end_date = date1

date2 = date.today() -timedelta(days = 365)
date2 = date2.strftime("%Y-%m-%d")
start_date = date2 

data = yf.download ( 'AAPL', 
    start = start_date, 
    end = end_date,
    progress = False)
print(data[:10])
Enter fullscreen mode Exit fullscreen mode

Visualise your Stock price data using Plotly Express. This visualisation will prompt a new window to open in your browser with up todate data.

import plotly.express as px 
fig = px.line(data, x = data.index, 
                y = "Close", 
                title = "Stock Price data")
fig.show()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)