Skip to content

Commit

Permalink
opencv programs
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshlinux committed Feb 3, 2021
2 parents 52734e1 + 99b44d3 commit a27ee07
Show file tree
Hide file tree
Showing 21 changed files with 129 additions and 84 deletions.
39 changes: 18 additions & 21 deletions DataStructure/binary_search.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
def binary_search(x, first, last, data):
if(first > last):
return 0
else:
mid = (first+last)//2
if(x[mid] == data):
return 1
if(x[mid] < data):
return binary_search(x, mid+1, last, data)
if(x[mid] > data):
return binary_search(x, first, mid-1, data)


x = [1, 2, 3, 5, 7, 8, 9, 10, 12, 14, 15, 18, 20, 22]
data = 10
data = 15
first = 0
last = 13

# bad way to find data in tuple
''' found =0
first=0
last =13
while (first<=last and found ==0):
mid = int((first+last)/2)
# print(mid)
if(x[mid]==data):
found =1
if(x[mid]<data):
first=mid+1
if(x[mid]>data):
last = mid-1
if(found ==0):
result = binary_search(x, first, last, data)
if(result == 0):
print("Data not found")
else:
print("Data found")
'''
if data in x:
print("Data found")
else:
print("Not found")
22 changes: 9 additions & 13 deletions DataStructure/linear_search.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@

#wrong way to find data
x =[1,2,3,5,7,89,3,62,34,13,5,7,9]
# wrong way to find data
x = [1, 2, 3, 5, 7, 89, 3, 62, 34, 13, 5, 7, 9]
data = 89
''' found =0
found = 0

for i in x:
if i ==data:
found =1
if(found ==0):
print("Data not found")
else:
print("Data found") '''
if i == data:
found = 1

# good way to search data in python
if data in x:
print('found')
if(found == 0):
print("Data not found")
else:
print('not found')
print("Data found")
1 change: 1 addition & 0 deletions DataStructure/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11
4 changes: 4 additions & 0 deletions database/12CS/dflsdjfhjas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def (n=20, o=30):
a = n*o
return a
print(a)
2 changes: 1 addition & 1 deletion database/12CS/insert_row.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MySQLdb
db = MySQLdb.connect('localhost', 'root', '', 'davschool')
cursor = db.cursor()
cursor.execute('insert into games values (6,"Python fun")')
cursor.execute('insert into games values (7,"fun with class xii")')
db.close()
print('Record added successfully')
2 changes: 1 addition & 1 deletion database/12CS/select_single_word.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MySQLdb
db = MySQLdb.connect('localhost', 'root', '', 'davschool')
cursor = db.cursor()
cursor.execute('select gname from games where id=6')
cursor.execute('select gname from games where id=5')
game_name = cursor.fetchone()
print('Your Game is :', game_name)
db.close()
10 changes: 1 addition & 9 deletions database/12CS/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
import MySQLdb
db = MySQLdb.connect('localhost', 'root', '', 'davschool')
cursor = db.cursor()
cursor.execute('select id,gname from games where id=6')
game_name = cursor.fetchone()
print('Your Game is :', game_name)
print('Game Id :', game_name[0])
print('Game name :', game_name[1])
db.close()
game_name
2 changes: 1 addition & 1 deletion database/12CS/update_record.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MySQLdb
db = MySQLdb.connect('localhost', 'root', '', 'davschool')
cursor = db.cursor()
cursor.execute('update games set gname ="fun with python " where id=6')
cursor.execute('update games set gname ="fun with rakesh " where id=5')
db.close()
print('Record updated successfully')
2 changes: 1 addition & 1 deletion fileHandling/Bulk_Image_Resizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def small(source,target,original):
dest = target + '\\' +original
with open(original, 'r+b') as f:
with Image.open(f) as image:
cover = resizeimage.resize_cover(image, [800, 600], validate=False)
cover = resizeimage.resize_cover(image, [300, 200], validate=False)
cover.save(dest, image.format)

def deleteFiles():
Expand Down
12 changes: 6 additions & 6 deletions functions/recursion/fibonacci.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# program to find out nth fibonacci number using recursion
# made by : rakesh kumar
# last compiled : 20-12-2018
# last compiled : 20-12-2018


def fibonacci(n):
if(n==1):
if(n == 1):
return 0
elif(n==2):
elif(n == 2):
return 1
else:
return fibonacci(n-1)+fibonacci(n-2)

if __name__ == "__main__":
for x in range(1,21):
print(fibonacci(x),end=" ")

result = fibonacci(30)
print(result)
6 changes: 5 additions & 1 deletion functions/recursion/natutal_no.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# recursive function to print first 100 natural number
# made by : rakesh kumar


def natural(n):
if n == 100:
print(100, end=" ")
Expand All @@ -8,4 +12,4 @@ def natural(n):


# function call to print 100 natural no
natural(1)
natural(10) #
16 changes: 16 additions & 0 deletions functions/recursion/power.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<<<<<<< HEAD

def xpower(x, y):
if y == 1:
return x
else:
return (x*xpower(x, y-1))


x = int(input("Enter x : "))
y = int(input("Enter y : "))
result = xpower(x, y)

print("\n\n {} power {} is {} ".format(x, y, result))
=======
>>>>>>> 62b05352fd92e1d91afddb64866852dd99f18c9a
18 changes: 18 additions & 0 deletions functions/recursion/recursive_linear_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def Linear_Search(l, start, n, value):
if start < n:
if l[start] == value:
return 1
else:
return Linear_Search(l, start+1, n, value)
else:
return 0


l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
data = int(input('Enter number to search :'))
n = len(l)-1
result = Linear_Search(l, 0, n, data)
if(result == 1):
print('data found')
else:
print('Data not not found')
15 changes: 10 additions & 5 deletions functions/recursion/sum_digit.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
def sum(n):
if n ==0:
# recursive function to find out sum of digits
# made by : rakesh kumar


def summ(n):
if n == 0:
return 0
else:
return(n%10+sum(n//10))
return(n % 10+summ(n//10)) # 5 + 2 + 1+0


n = int(input("Enter x : "))
result = sum(n)
print("Sum of digits : ",result)
result = summ(n)
print("Sum of digits : ", result)
10 changes: 1 addition & 9 deletions functions/recursion/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
def sum(n):
if n ==0:
return 0
else:
return(n%10+sum(n//10))

n = int(input("Enter x : "))
result = sum(n)
print("Sum of digits : ",result)
l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
3 changes: 3 additions & 0 deletions matplotlib/frequency_polygon.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import matplotlib.pyplot as plt
<<<<<<< HEAD
=======
from numpy import linspace,pi,sin,cos,tan

#multiple figures
Expand All @@ -17,3 +19,4 @@
plt.hist(data,bins=[0,10,20,30,40,50,60],color="green")
plt.scatter(frequency,x)
plt.show()
>>>>>>> da25a2a32ac30d0980ed6d1d3ad58008d8ff0b21
8 changes: 4 additions & 4 deletions matplotlib/pie_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import matplotlib.pyplot as plt
import numpy as np
x = ['Delhi','Banglore','Chennai','Pune','Ghaziabad','Udupi']
y = [250,300,260,400,599,320]
plt.pie(y,labels=x,autopct='%.2f',)
plt.show()
x = ['Delhi', 'Banglore', 'Chennai', 'Pune', 'Ghaziabad', 'Udupi']
y = [250, 300, 260, 400, 599, 320]
plt.pie(y, labels=x, autopct='%.2f',)
plt.show()
7 changes: 6 additions & 1 deletion matplotlib/simpleplt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import matplotlib.pyplot as plt
<<<<<<< HEAD
plt
plt.show()
=======
import numpy as np
x = np.linspace(0,2.0*np.pi,101)
# print(x)
y = np.sin(x)
plt.plot(x,y,color="red",linestyle="--",linewidth="5")
plt.show()
plt.show()
>>>>>>> da25a2a32ac30d0980ed6d1d3ad58008d8ff0b21
2 changes: 1 addition & 1 deletion opencv_project/manipulating_pixel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import cv2

image =cv2.imread('walter.jpg',1)
print(image)
print(image)
24 changes: 14 additions & 10 deletions pdf_spilter.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
#-------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# Name: pdf spiller
# Purpose: split pdf in to single pages
# Author: acer
## Created: 13-04-2018
# Created: 13-04-2018
# Copyright: (c) acer 2018
# Licence: <your licence>
#-------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
import os
import sys # module for terminating
import glob #
import sys # module for terminating
import glob #
import tkinter as tk
from tkinter import filedialog
from PyPDF2 import PdfFileReader, PdfFileWriter
def pdf_splitter(path,dest):


def pdf_splitter(path, dest):
fname = os.path.splitext(os.path.basename(path))[0]
pdf = PdfFileReader(path)
for page in range(pdf.getNumPages()):
pdf_writer = PdfFileWriter()
pdf_writer.addPage(pdf.getPage(page))
output_filename = os.path.join(dest,'{}_page_{}.pdf'.format(fname, page+1))
#print(output_filename)
output_filename = os.path.join(
dest, '{}_page_{}.pdf'.format(fname, page+1))
# print(output_filename)
with open(output_filename, 'wb') as out:
pdf_writer.write(out)
print('Created: {}'.format(output_filename))


if __name__ == '__main__':
#path = "Computer_Science.pdf"
root = tk.Tk()
root.withdraw()
path = filedialog.askopenfilename() #source file name
path = filedialog.askopenfilename() # source file name
dest = filedialog.askdirectory() # destination folder
pdf_splitter(path,dest)
pdf_splitter(path, dest)
8 changes: 8 additions & 0 deletions webscraper/youtubeDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@
# import shutil
ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
<<<<<<< HEAD
ydl.download(['https://www.youtube.com/watch?v=WfGMYdalClU'])
=======
<<<<<<< HEAD
ydl.download(['https://youtu.be/GkMnqTnjImk'])
=======
ydl.download(['https://www.youtube.com/watch?v=QaeXCar-NaM&t=2740s'])
>>>>>>> 99b44d3436e1335d5f1c119dc0467b27bfa0bd2b

>>>>>>> 62b05352fd92e1d91afddb64866852dd99f18c9a

0 comments on commit a27ee07

Please sign in to comment.