Spaces:
Runtime error
Runtime error
Commit
·
6cd4037
1
Parent(s):
94ec257
fir
Browse files- __pycache__/data_func.cpython-310.pyc +0 -0
- __pycache__/functions.cpython-310.pyc +0 -0
- __pycache__/reader.cpython-310.pyc +0 -0
- __pycache__/screen.cpython-310.pyc +0 -0
- app.py +25 -0
- data +1 -0
- data_func.py +48 -0
- functions.py +224 -0
- reader.py +111 -0
- screen.py +131 -0
__pycache__/data_func.cpython-310.pyc
ADDED
|
Binary file (1.42 kB). View file
|
|
|
__pycache__/functions.cpython-310.pyc
ADDED
|
Binary file (5.08 kB). View file
|
|
|
__pycache__/reader.cpython-310.pyc
ADDED
|
Binary file (2.3 kB). View file
|
|
|
__pycache__/screen.cpython-310.pyc
ADDED
|
Binary file (3.64 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from screen import screen_scan_main
|
| 3 |
+
|
| 4 |
+
st.markdown("""
|
| 5 |
+
<style>
|
| 6 |
+
.block-container {
|
| 7 |
+
padding-top: 0rem;
|
| 8 |
+
padding-bottom: 0rem;
|
| 9 |
+
padding-left: 1rem;
|
| 10 |
+
padding-right: 1rem;
|
| 11 |
+
}
|
| 12 |
+
</style>
|
| 13 |
+
""", unsafe_allow_html=True)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def main():
|
| 17 |
+
|
| 18 |
+
screen_scan_main()
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
main()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
data
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Subproject commit 4cde9e2675d9a91b0dc66510a8978808d267cfb1
|
data_func.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from huggingface_hub import Repository
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
DATASET_REPO_URL = "https://huggingface.co/datasets/mertbozkurt/school_data"
|
| 6 |
+
DATA_FILENAME = "untitled.csv"
|
| 7 |
+
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
| 8 |
+
HF_TOKEN = "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"
|
| 9 |
+
|
| 10 |
+
def pull_read():
|
| 11 |
+
|
| 12 |
+
repo = Repository(
|
| 13 |
+
local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
with open(DATA_FILE) as csvfile:
|
| 17 |
+
df = pd.read_csv(csvfile)
|
| 18 |
+
df = pd.DataFrame(df)
|
| 19 |
+
|
| 20 |
+
return repo, df
|
| 21 |
+
|
| 22 |
+
#sinav_kodu,ogrenci_no,notu1,yanlis_sorulari1,notu2,yanlis_sorulari2,notu3,yanlis_sorulari3
|
| 23 |
+
def make_new_data(sinav_kodu,ogrenci_no,notu1,yanlis_sorulari1,notu2,yanlis_sorulari2,notu3,yanlis_sorulari3):
|
| 24 |
+
yeni_satir = {"sinav_kodu": sinav_kodu,
|
| 25 |
+
"ogrenci_no": ogrenci_no,
|
| 26 |
+
"notu1": notu1,
|
| 27 |
+
"yanlis_sorulari1": yanlis_sorulari1,
|
| 28 |
+
"notu2": notu2,
|
| 29 |
+
"yanlis_sorulari2": yanlis_sorulari2,
|
| 30 |
+
"notu3": notu3,
|
| 31 |
+
"yanlis_sorulari3": yanlis_sorulari3,
|
| 32 |
+
}
|
| 33 |
+
new_data = pd.DataFrame([yeni_satir])
|
| 34 |
+
return new_data
|
| 35 |
+
|
| 36 |
+
def update(new_data, ex_df):
|
| 37 |
+
updated_df = pd.concat([ex_df, new_data])
|
| 38 |
+
return updated_df
|
| 39 |
+
|
| 40 |
+
def save_and_push(dataFrame,repo,fileName):
|
| 41 |
+
dataFrame.to_csv(fileName,index=False)
|
| 42 |
+
commit_url = repo.push_to_hub()
|
| 43 |
+
return commit_url
|
| 44 |
+
|
| 45 |
+
"""repo, repo_df = pull_read()
|
| 46 |
+
new_data = make_new_data(12,151718,56,80,"2,3,5")
|
| 47 |
+
updated_df = update(new_data,repo_df)
|
| 48 |
+
save_and_push(updated_df,repo)"""
|
functions.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import numpy as np
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
def rectContour(contours):
|
| 6 |
+
rectCon = []
|
| 7 |
+
max_area = 0
|
| 8 |
+
for i in contours:
|
| 9 |
+
area = cv2.contourArea(i) #alan hesabi
|
| 10 |
+
#piksel alani 50den byukse gecerlidir
|
| 11 |
+
if area > 30:
|
| 12 |
+
peri = cv2.arcLength(i, True)
|
| 13 |
+
approx = cv2.approxPolyDP(i, 0.02 * peri, True) #kac tane koseye sahip oldugu
|
| 14 |
+
if len(approx) == 4: #4 ise dortgendir
|
| 15 |
+
rectCon.append(i)
|
| 16 |
+
rectCon = sorted(rectCon, key=cv2.contourArea,reverse=True) #alanlari hesaplicak ve siralicak ki ona gore alanlari belirleyelim
|
| 17 |
+
#print(len(rectCon))
|
| 18 |
+
return rectCon
|
| 19 |
+
|
| 20 |
+
def getCornerPoints(cont):
|
| 21 |
+
peri = cv2.arcLength(cont, True)
|
| 22 |
+
approx = cv2.approxPolyDP(cont, 0.02 * peri, True) #kose degerleri
|
| 23 |
+
return approx
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def reorder(myPoints):
|
| 27 |
+
|
| 28 |
+
myPoints = myPoints.reshape((4, 2)) #fazla koseliyi kaldiralim
|
| 29 |
+
#print(myPoints)
|
| 30 |
+
myPointsNew = np.zeros((4, 1, 2), np.int32)
|
| 31 |
+
add = myPoints.sum(1)
|
| 32 |
+
#print(add)
|
| 33 |
+
#print(np.argmax(add))
|
| 34 |
+
myPointsNew[0] = myPoints[np.argmin(add)] #[0,0]
|
| 35 |
+
myPointsNew[3] =myPoints[np.argmax(add)] #[w,h]
|
| 36 |
+
diff = np.diff(myPoints, axis=1)
|
| 37 |
+
myPointsNew[1] =myPoints[np.argmin(diff)] #[w,0]
|
| 38 |
+
myPointsNew[2] = myPoints[np.argmax(diff)] #[h,0]
|
| 39 |
+
|
| 40 |
+
return myPointsNew
|
| 41 |
+
|
| 42 |
+
#siklari bolmek icin 20 tane soru vertical/ 5 tane isaret alani +1 tane soru sayisi yazan yer
|
| 43 |
+
#6 horizatanl bolmek
|
| 44 |
+
def splitBoxes(img):
|
| 45 |
+
rows = np.vsplit(img,20) #vertical
|
| 46 |
+
boxes=[]
|
| 47 |
+
for r in rows:
|
| 48 |
+
cols= np.hsplit(r,6) #horizantal
|
| 49 |
+
for box in cols:
|
| 50 |
+
boxes.append(box)
|
| 51 |
+
return boxes
|
| 52 |
+
|
| 53 |
+
#ogrenci numarasi alani icin ayni fonksiyonu kullandik
|
| 54 |
+
#yuakrdakisini silip sadece bu da kullanilabilir dogru degerler ile
|
| 55 |
+
#ogrenci numarasi alani 0-9 arasi sayilardan 10 tane isaretleme yeri iceriyor
|
| 56 |
+
#10x10seklinde boleriz
|
| 57 |
+
def split_num(img,vertical, horizantal):
|
| 58 |
+
rows = np.vsplit(img,vertical) #vertical
|
| 59 |
+
boxes=[]
|
| 60 |
+
for r in rows:
|
| 61 |
+
cols= np.hsplit(r,horizantal) #horizantal
|
| 62 |
+
for box in cols:
|
| 63 |
+
boxes.append(box)
|
| 64 |
+
return boxes
|
| 65 |
+
|
| 66 |
+
#yan yana 3 tane birlesik ders alani oldugu icin onlari 3 ayri
|
| 67 |
+
#sekle getiriyor
|
| 68 |
+
def splitColumn(img):
|
| 69 |
+
column = np.hsplit(img,3)
|
| 70 |
+
|
| 71 |
+
return column
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
#puan hesaplama alani
|
| 75 |
+
#soru sayisi dogru cevaplari ve ogrenci cevaplarini aliyor
|
| 76 |
+
#bunlari karsilastirip yeni bir listeye 1/0 seklinde kodluyor
|
| 77 |
+
#1ler toplanip puan hesaplanmis oluyor
|
| 78 |
+
def grading(answers,num_questions,myAnswers):
|
| 79 |
+
grading=[]
|
| 80 |
+
wrong_ans = []
|
| 81 |
+
empty = []
|
| 82 |
+
|
| 83 |
+
for x in range(0,num_questions):
|
| 84 |
+
if answers[x] == myAnswers[x]:
|
| 85 |
+
grading.append(1)
|
| 86 |
+
|
| 87 |
+
elif myAnswers[x] == -1:
|
| 88 |
+
grading.append(0)
|
| 89 |
+
wrong_ans.append(x+1)
|
| 90 |
+
|
| 91 |
+
elif myAnswers[x] == 0:
|
| 92 |
+
empty.append(x+1)
|
| 93 |
+
|
| 94 |
+
else:
|
| 95 |
+
grading.append(0)
|
| 96 |
+
wrong_ans.append(x+1)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
score = (sum(grading)/num_questions)*100
|
| 100 |
+
return score ,wrong_ans,empty
|
| 101 |
+
|
| 102 |
+
#piksel degerlerinde kullanici cevaplarini
|
| 103 |
+
#okuyupu index seklinde listeye kaydediyor
|
| 104 |
+
def user_answers(num_questions,myPixelVal):
|
| 105 |
+
myIndex=[]
|
| 106 |
+
|
| 107 |
+
for x in range (0,num_questions):
|
| 108 |
+
arr = myPixelVal[x]
|
| 109 |
+
t =150
|
| 110 |
+
#empty answers
|
| 111 |
+
if arr[1] < 150.0 and arr[2] < 150.0 and arr[3] < 150.0 and arr[4] < 150.0 and arr[5] < 150.0:
|
| 112 |
+
|
| 113 |
+
myIndex.append(0)
|
| 114 |
+
|
| 115 |
+
#2 or more answers
|
| 116 |
+
elif (arr[1]>t and arr[2]>t) or ( arr[1]>t and arr[3]>t) or (arr[1]>t and arr[4]>t) or (arr[1]>t and arr[5]> t) or (arr[2]>t and arr[3]> t) or (arr[2]>t and arr[4]> t) or (arr[2]>t and arr[5]> t) or (arr[3]>t and arr[4]> t) or (arr[3]>t and arr[5]> t) or (arr[4]>t and arr[5]>t) :
|
| 117 |
+
myIndex.append(-1)
|
| 118 |
+
|
| 119 |
+
else :
|
| 120 |
+
myIndexVal = np.where(arr == np.amax(arr))
|
| 121 |
+
myIndex.append(myIndexVal[0][0])
|
| 122 |
+
print(myIndex)
|
| 123 |
+
return myIndex
|
| 124 |
+
|
| 125 |
+
#student id kismi yukardan asagiya dogru karsilastirma yaparak
|
| 126 |
+
#isretli alan tespit edilecegi icin satir ve sutunlari tekrar duzenlemiz gerekti
|
| 127 |
+
#[[1,2,3],[4,5,6],[7,8,9]] ----> [[1,4,7],[2,5,8],[3,6,9]]
|
| 128 |
+
def id_reorder(myPixelVal):
|
| 129 |
+
duz_liste = []
|
| 130 |
+
for sutun in range(len(myPixelVal[0])):
|
| 131 |
+
for satir in range(len(myPixelVal)):
|
| 132 |
+
duz_liste.append(myPixelVal[satir][sutun])
|
| 133 |
+
yeni_liste = []
|
| 134 |
+
satir = []
|
| 135 |
+
for eleman in duz_liste:
|
| 136 |
+
satir.append(eleman)
|
| 137 |
+
if len(satir) == len(myPixelVal):
|
| 138 |
+
yeni_liste.append(satir)
|
| 139 |
+
satir = []
|
| 140 |
+
return yeni_liste
|
| 141 |
+
|
| 142 |
+
#ogrenci numarasi kisminin piksel degerine gore hangisinin iseretli
|
| 143 |
+
#oldugunun tespiti
|
| 144 |
+
def id_answers(vertical_num,myPixelVal):
|
| 145 |
+
myIndex=[]
|
| 146 |
+
for x in range (0,vertical_num):
|
| 147 |
+
arr = myPixelVal[x]
|
| 148 |
+
myIndexVal = np.where(arr == np.amax(arr))
|
| 149 |
+
myIndex.append(myIndexVal[0][0])
|
| 150 |
+
return myIndex
|
| 151 |
+
|
| 152 |
+
def pixelVal(num_questions,choices,box):
|
| 153 |
+
countR=0 #rows
|
| 154 |
+
countC=0 #column
|
| 155 |
+
myPixelVal = np.zeros((num_questions,choices))
|
| 156 |
+
for image in box:
|
| 157 |
+
totalPixels = cv2.countNonZero(image)
|
| 158 |
+
myPixelVal[countR][countC]= totalPixels
|
| 159 |
+
countC += 1
|
| 160 |
+
if (countC==choices):countC=0;countR +=1
|
| 161 |
+
return myPixelVal
|
| 162 |
+
|
| 163 |
+
#dosyadan cevap anahtarinin okunmasi
|
| 164 |
+
def read_answers(dosya_adi):
|
| 165 |
+
with open(dosya_adi, 'r') as f:
|
| 166 |
+
satirlar = f.readlines()
|
| 167 |
+
|
| 168 |
+
okunan_veriler = []
|
| 169 |
+
for satir in satirlar:
|
| 170 |
+
sutunlar = satir.split()
|
| 171 |
+
okunan_veriler.append(sutunlar[1])
|
| 172 |
+
|
| 173 |
+
return okunan_veriler
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
#dosyadan okunan cevaplarin numerik hale getirilmesi
|
| 177 |
+
def answers2numbers(answers):
|
| 178 |
+
num_answers = []
|
| 179 |
+
for i in answers:
|
| 180 |
+
if i == "a":
|
| 181 |
+
num_answers.append(1)
|
| 182 |
+
elif i == "b":
|
| 183 |
+
num_answers.append(2)
|
| 184 |
+
elif i == "c":
|
| 185 |
+
num_answers.append(3)
|
| 186 |
+
elif i == "d":
|
| 187 |
+
num_answers.append(4)
|
| 188 |
+
elif i == "e":
|
| 189 |
+
num_answers.append(5)
|
| 190 |
+
else:
|
| 191 |
+
print("Oppss Check Txt file")
|
| 192 |
+
return num_answers
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def image_show(images):
|
| 196 |
+
col1, col2, col3 = st.columns(3)
|
| 197 |
+
with col1:
|
| 198 |
+
st.header("0")
|
| 199 |
+
st.image(images[0],width=200)
|
| 200 |
+
with col2:
|
| 201 |
+
st.header("1")
|
| 202 |
+
st.image(images[1],width=200)
|
| 203 |
+
with col3:
|
| 204 |
+
st.header("2")
|
| 205 |
+
st.image(images[2],width=200)
|
| 206 |
+
|
| 207 |
+
col4, col5= st.columns(2)
|
| 208 |
+
|
| 209 |
+
with col4:
|
| 210 |
+
st.header("3")
|
| 211 |
+
st.image(images[4],width=200)
|
| 212 |
+
with col5:
|
| 213 |
+
st.header("4")
|
| 214 |
+
st.image(images[5],width=200)
|
| 215 |
+
col6, col7= st.columns(2)
|
| 216 |
+
with col6:
|
| 217 |
+
st.header("5")
|
| 218 |
+
st.image(images[6],width=150)
|
| 219 |
+
|
| 220 |
+
with col7:
|
| 221 |
+
st.header("6")
|
| 222 |
+
st.image(images[7],width=150)
|
| 223 |
+
|
| 224 |
+
|
reader.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import numpy as np
|
| 3 |
+
import functions
|
| 4 |
+
|
| 5 |
+
#fotograf ozellikleri
|
| 6 |
+
heightImg = 300*4
|
| 7 |
+
widthImg = 210*4
|
| 8 |
+
#pathImage = "denemeler/100luk_numarali.jpg"
|
| 9 |
+
questions=20
|
| 10 |
+
choices=6
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def reader(pathImage, save_images= True):
|
| 15 |
+
#cevap anahtarini dosyadan okuma ve sayiya cevirme
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
#perspektif islemleri icin cozunurluk
|
| 19 |
+
wrap_h = 18*20
|
| 20 |
+
wrap_v = 18*20
|
| 21 |
+
img = pathImage #eger girdi dogrudan np arrayse
|
| 22 |
+
#fotonun okunmasi ------------------------------------------------------------------------------------------------
|
| 23 |
+
#img = cv2.imread(pathImage)
|
| 24 |
+
img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
|
| 25 |
+
img = cv2.resize(img, (widthImg, heightImg)) # RESIZE IMAGE
|
| 26 |
+
imgBiggestContour = img.copy()
|
| 27 |
+
imgFinal = img.copy()
|
| 28 |
+
imgContours = img.copy()
|
| 29 |
+
imgBlank = np.zeros((heightImg,widthImg, 3), np.uint8)
|
| 30 |
+
|
| 31 |
+
#donusumler---------------------------------------------------------------------------------
|
| 32 |
+
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # CONVERT IMAGE TO GRAY SCALE
|
| 33 |
+
imgBlur = cv2.GaussianBlur(imgGray, (5, 5), 1) # ADD GAUSSIAN BLUR
|
| 34 |
+
imgCanny = cv2.Canny(imgBlur,10,70) # APPLY CANNY
|
| 35 |
+
|
| 36 |
+
#CONTOURS-------------------------------------------------------
|
| 37 |
+
contours, hierarchy = cv2.findContours(imgCanny, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
|
| 38 |
+
cv2.drawContours(imgContours, contours, -1, (0, 255, 0), 10) # DRAW ALL DETECTED CONTOURS
|
| 39 |
+
|
| 40 |
+
#dortgen bulma--------------------------------------------------
|
| 41 |
+
rectCon = functions.rectContour(contours)
|
| 42 |
+
biggestContour = functions.getCornerPoints(rectCon[0])
|
| 43 |
+
secondContour = functions.getCornerPoints(rectCon[1])
|
| 44 |
+
thirdContour = functions.getCornerPoints(rectCon[2])
|
| 45 |
+
#fourthContour = functions.getCornerPoints(rectCon[3])
|
| 46 |
+
|
| 47 |
+
#main
|
| 48 |
+
if biggestContour.size != 0 and secondContour.size != 0:
|
| 49 |
+
|
| 50 |
+
cv2.drawContours(imgBiggestContour, biggestContour,-1,(0,255,0),20)
|
| 51 |
+
cv2.drawContours(imgBiggestContour, secondContour,-1,(255,0,0),20) #sondk' kalinlik ortada renk
|
| 52 |
+
cv2.drawContours(imgBiggestContour, thirdContour,-1,(0,0,255),20) #sondk' kalinlik ortada renk
|
| 53 |
+
#cv2.drawContours(imgBiggestContour, fourthContour,-1,(0,0,20),20) #sondk' kalinlik ortada renk
|
| 54 |
+
|
| 55 |
+
biggestContour=functions.reorder(biggestContour)
|
| 56 |
+
#cevap siklari icin -************************************************************
|
| 57 |
+
pts1 = np.float32(biggestContour)
|
| 58 |
+
pts2 = np.float32([[0, 0],[wrap_v, 0], [0, wrap_h],[wrap_v, wrap_h]])
|
| 59 |
+
matrix = cv2.getPerspectiveTransform(pts1, pts2)
|
| 60 |
+
|
| 61 |
+
imgWarpColored_1 = cv2.warpPerspective(img, matrix, (wrap_v, wrap_h))
|
| 62 |
+
imgWarpGray_1 = cv2.cvtColor(imgWarpColored_1,cv2.COLOR_BGR2GRAY)
|
| 63 |
+
imgThresh_1 = cv2.threshold(imgWarpGray_1,0,255,cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
|
| 64 |
+
|
| 65 |
+
#second buyuk icin perspektif
|
| 66 |
+
secondContour=functions.reorder(secondContour)
|
| 67 |
+
pts1_2 = np.float32(secondContour)
|
| 68 |
+
pts2_2 = np.float32([[0, 0],[wrap_v, 0], [0, wrap_h],[wrap_v, wrap_h]])
|
| 69 |
+
matrix_2 = cv2.getPerspectiveTransform(pts1_2, pts2_2)
|
| 70 |
+
imgWarpColored_2 = cv2.warpPerspective(img, matrix_2, (wrap_v, wrap_h))
|
| 71 |
+
imgWarpGray_2 = cv2.cvtColor(imgWarpColored_2,cv2.COLOR_BGR2GRAY)
|
| 72 |
+
#imgThresh_2 = cv2.threshold(imgWarpGray_2, 170, 255,cv2.THRESH_BINARY_INV )[1]
|
| 73 |
+
imgThresh_2 = cv2.threshold(imgWarpGray_2,0,255,cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
|
| 74 |
+
|
| 75 |
+
#student id
|
| 76 |
+
bubbles = functions.split_num(imgThresh_2, 10, 10)
|
| 77 |
+
myPixelVal_2 = functions.pixelVal(10,10,bubbles)
|
| 78 |
+
myPixelVal_2 = functions.id_reorder(myPixelVal_2)
|
| 79 |
+
student_id = functions.id_answers(10,myPixelVal_2)
|
| 80 |
+
#print(student_id)
|
| 81 |
+
|
| 82 |
+
#soru kisimi
|
| 83 |
+
column_3 = functions.splitColumn(imgThresh_1)
|
| 84 |
+
boxes_1 = functions.splitBoxes(column_3[0])
|
| 85 |
+
boxes_2 = functions.splitBoxes(column_3[1])
|
| 86 |
+
boxes_3 = functions.splitBoxes(column_3[2])
|
| 87 |
+
#boxes_1
|
| 88 |
+
myPixelVal_1 = functions.pixelVal(questions,choices,boxes_1)
|
| 89 |
+
myIndex_1 = functions.user_answers(questions,myPixelVal_1)
|
| 90 |
+
|
| 91 |
+
#boxes_2
|
| 92 |
+
myPixelVal_2 = functions.pixelVal(questions,choices,boxes_2)
|
| 93 |
+
myIndex_2 = functions.user_answers(questions,myPixelVal_2)
|
| 94 |
+
|
| 95 |
+
#boxes_3
|
| 96 |
+
myPixelVal_3 = functions.pixelVal(questions,choices,boxes_3)
|
| 97 |
+
myIndex_3 = functions.user_answers(questions,myPixelVal_3)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
student_idFix = ""
|
| 102 |
+
for number in student_id:
|
| 103 |
+
student_idFix += str(number)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
myIndexs = [myIndex_1,myIndex_2,myIndex_3]
|
| 108 |
+
return student_idFix, myIndexs
|
| 109 |
+
|
| 110 |
+
#sonuc = optic1(ans_txt="cevapanahtari.txt",pathImage= "denemeler/100luk_numarali.jpg")
|
| 111 |
+
#print(sonuc)
|
screen.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import csv
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import numpy as np
|
| 4 |
+
import cv2
|
| 5 |
+
from PIL import Image
|
| 6 |
+
from functions import image_show
|
| 7 |
+
import pandas as pd
|
| 8 |
+
from data_func import make_new_data,update,save_and_push
|
| 9 |
+
import os
|
| 10 |
+
from huggingface_hub import Repository
|
| 11 |
+
import reader
|
| 12 |
+
|
| 13 |
+
st.markdown("""
|
| 14 |
+
<style>
|
| 15 |
+
.block-container {
|
| 16 |
+
padding-top: 1rem;
|
| 17 |
+
padding-bottom: 0rem;
|
| 18 |
+
padding-left: 1rem;
|
| 19 |
+
padding-right: 1rem;
|
| 20 |
+
}
|
| 21 |
+
</style>
|
| 22 |
+
""", unsafe_allow_html=True)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def pull_read(DATASET_REPO_URL,HF_TOKEN,DATA_FILE):
|
| 27 |
+
|
| 28 |
+
repo = Repository(
|
| 29 |
+
local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
with open(DATA_FILE) as csvfile:
|
| 33 |
+
df = pd.read_csv(csvfile)
|
| 34 |
+
df = pd.DataFrame(df)
|
| 35 |
+
|
| 36 |
+
return repo, df
|
| 37 |
+
|
| 38 |
+
@st.cache
|
| 39 |
+
def convert_df_to_csv(df):
|
| 40 |
+
# IMPORTANT: Cache the conversion to prevent computation on every rerun
|
| 41 |
+
return df.to_csv().encode('utf-8')
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def screen_scan_main():
|
| 45 |
+
teacher_code = st.text_input("Ogretmen kodu:",key=12)
|
| 46 |
+
password = st.text_input("Sıfre:",key=17,type="password")
|
| 47 |
+
|
| 48 |
+
teacher_code = str(teacher_code)
|
| 49 |
+
password = str(password)
|
| 50 |
+
|
| 51 |
+
DATA_FILENAME = f"{teacher_code}.csv"
|
| 52 |
+
DATA_FILENAME = str(DATA_FILENAME)
|
| 53 |
+
|
| 54 |
+
image_file = st.file_uploader(
|
| 55 |
+
"Tarama Yapmak Icin Optigi Yukleyin", type=['jpeg', 'png', 'jpg', 'webp'])
|
| 56 |
+
if image_file != None:
|
| 57 |
+
repo, repo_df = pull_read(DATASET_REPO_URL = "https://huggingface.co/datasets/mertbozkurt/school_data",
|
| 58 |
+
DATA_FILE = os.path.join("data", DATA_FILENAME),
|
| 59 |
+
HF_TOKEN = "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")
|
| 60 |
+
repo.git_pull()
|
| 61 |
+
|
| 62 |
+
if str(repo_df["ogrenci_no"][0]) == password:
|
| 63 |
+
st.write("Giriş başarılı")
|
| 64 |
+
answer_code = st.radio(
|
| 65 |
+
"Cevap Anahtari Kodu",
|
| 66 |
+
('1', '2', '3',"4","5"))
|
| 67 |
+
answer_code = int(answer_code)
|
| 68 |
+
global myIndexs
|
| 69 |
+
|
| 70 |
+
image = Image.open(image_file)
|
| 71 |
+
image = np.array(image.convert('RGB'))
|
| 72 |
+
#(ans_txt,pathImage, save_images= True)
|
| 73 |
+
resim_list,myIndexs =reader.reader(pathImage=image,save_images=False)
|
| 74 |
+
|
| 75 |
+
#myIndex1_str =", ".join(map(str, myIndexs[0]))
|
| 76 |
+
st.write("Ders 1 icin cevap anahtari")
|
| 77 |
+
df = pd.DataFrame(
|
| 78 |
+
[
|
| 79 |
+
{"Sorular": "Soru1 ", "Cevap": myIndexs[0][0],"Sorular2": "Soru11 ", "Cevap6": myIndexs[0][10]},
|
| 80 |
+
{"Sorular": "Soru2", "Cevap": myIndexs[0][1],"Sorular2": "Soru12 ", "Cevap6": myIndexs[0][11]},
|
| 81 |
+
{"Sorular": "Soru3", "Cevap": myIndexs[0][2],"Sorular2": "Soru13 ", "Cevap6": myIndexs[0][12]},
|
| 82 |
+
{"Sorular": "Soru4 ", "Cevap": myIndexs[0][3],"Sorular2": "Soru14 ", "Cevap6": myIndexs[0][13]},
|
| 83 |
+
{"Sorular": "Soru5", "Cevap": myIndexs[0][4],"Sorular2": "Soru15 ", "Cevap6": myIndexs[0][14]},
|
| 84 |
+
{"Sorular": "Soru6 ", "Cevap": myIndexs[0][5],"Sorular2": "Soru16 ", "Cevap6": myIndexs[0][15]},
|
| 85 |
+
{"Sorular": "Soru7", "Cevap": myIndexs[0][6],"Sorular2": "Soru17 ", "Cevap6": myIndexs[0][16]},
|
| 86 |
+
{"Sorular": "Soru8", "Cevap": myIndexs[0][7],"Sorular2": "Soru18 ", "Cevap6": myIndexs[0][17]},
|
| 87 |
+
{"Sorular": "Soru9 ", "Cevap": myIndexs[0][8],"Sorular2": "Soru19 ", "Cevap6": myIndexs[0][18]},
|
| 88 |
+
{"Sorular": "Soru10", "Cevap": myIndexs[0][9],"Sorular2": "Soru20 ", "Cevap6": myIndexs[0][19]}
|
| 89 |
+
]
|
| 90 |
+
)
|
| 91 |
+
edited_df = st.experimental_data_editor(df,use_container_width=True,height=400)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
if st.button("Kaydet"):
|
| 96 |
+
repo, repo_df = pull_read(DATASET_REPO_URL = "https://huggingface.co/datasets/mertbozkurt/school_data",
|
| 97 |
+
DATA_FILE = os.path.join("data", DATA_FILENAME),
|
| 98 |
+
HF_TOKEN = "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")
|
| 99 |
+
repo.git_pull()
|
| 100 |
+
|
| 101 |
+
image = Image.open(image_file)
|
| 102 |
+
image = np.array(image.convert('RGB'))
|
| 103 |
+
#(ans_txt,pathImage, save_images= True)
|
| 104 |
+
|
| 105 |
+
myIndex1_str =", ".join(map(str, edited_df["Cevap"]))
|
| 106 |
+
myIndex2_str =", ".join(map(str, myIndexs[1]))
|
| 107 |
+
myIndex3_str =", ".join(map(str, myIndexs[2]))
|
| 108 |
+
#new_data1 = pd.DataFrame(data, index, columns)
|
| 109 |
+
data = [[1,answer_code,80,myIndex1_str,90,myIndex2_str,10,myIndex3_str]]
|
| 110 |
+
|
| 111 |
+
# Create the pandas DataFrame
|
| 112 |
+
new_data = pd.DataFrame(data, columns=['sinav_kodu', 'ogrenci_no',
|
| 113 |
+
"notu1","yanlis_sorulari1",
|
| 114 |
+
"notu2","yanlis_sorulari2",
|
| 115 |
+
"notu3","yanlis_sorulari3"])
|
| 116 |
+
|
| 117 |
+
repo_df = repo_df[repo_df['ogrenci_no'] != answer_code]
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
updated = update(new_data=new_data,ex_df=repo_df)
|
| 121 |
+
#st.dataframe(updated,use_container_width=True)
|
| 122 |
+
save_and_push(dataFrame=updated,repo=repo,fileName=f"data/{DATA_FILENAME}")
|
| 123 |
+
|
| 124 |
+
#st.download_button(label="Tum verileri indirmek icin tiklayin",data=convert_df_to_csv(updated),
|
| 125 |
+
# file_name=f'{teacher_code}.csv',mime='text/csv',)
|
| 126 |
+
else:
|
| 127 |
+
st.write("Giris basarisiz kontrol ediniz.")
|
| 128 |
+
|
| 129 |
+
#python -m streamlit run app.py
|
| 130 |
+
if __name__ == '__main__':
|
| 131 |
+
screen_scan_main()
|