Tensorflow와 OpenCV를 사용하여 웹캠에 비춘 손글씨 숫자를 인식시켜보았습니다.
최초 작성 2019. 10. 1
관련 최근 포스트
[Machine Learning & Deep Learning/Tensorflow 강좌] - Keras와 OpenCV를 사용하여 손글씨 숫자 인식하기
CNN을 사용하여 인식 정확도가 좋아졌습니다.
01.py
손글씨 숫자를 인식을 위해 뉴럴 네트워크를 학습시키는 코드입니다.
실행결과 가중치를 파일로 저장합니다.
02.py
학습된 뉴럴 네트워크를 사용하여 웹캠에 비춘 손글씨 숫자를 인식하는 코드입니다.
'Machine Learning & Deep Learning > Tensorflow 강좌' 카테고리의 다른 글
Tensorflow 2.0에서 Tensorflow 1.x 코드 실행하기 (4) | 2019.11.09 |
---|---|
텐서플로우 2.0 강좌 - 케라스를 사용하여 손글씨 숫자 분류를 위한 신경망 만들기 (0) | 2019.10.29 |
Android를 위한 TensorFlow Lite 예제 (MNIST 손글씨 숫자 인식) (28) | 2019.10.16 |
TensorFlow와 OpenCV를 사용하여 웹캠에 비춘 손글씨 숫자 인식하기 (26) | 2019.10.01 |
텐서플로우 2.0 강좌입니다. (4) | 2019.09.01 |
텐서 플로우 2.0 강좌 1 - 텐서플로우 설치 (6) | 2019.07.14 |
텐서플로우 기초 강좌 - 1. 간단한 수식 계산 (0) | 2019.02.04 |
Tensorflow 강좌 - Tensorboard 간단한 사용방법 (5) | 2019.01.22 |
포스트 작성시에는 문제 없었지만 이후 문제가 생길 수 있습니다.
질문을 남겨주면 가능한 빨리 답변드립니다.
여러분의 응원으로 좋은 컨텐츠가 만들어집니다.
지금 본 내용이 도움이 되었다면 유튜브 구독 부탁드립니다.
감사합니다 ~~
유튜브 구독하기
제가 쓴 책도 한번 검토해보세요 ^^
-
-
1234 2020.02.20 14:15
Mac에서 돌려보니... 모델에서는 잘 되는데 실제로 동작할때 이미지 인식이 좋지 않네요
모델이
Epoch 1/5
60000/60000 [==============================] - 2s 37us/sample - loss: 0.2692 - accuracy: 0.9180
Epoch 2/5
60000/60000 [==============================] - 2s 33us/sample - loss: 0.1256 - accuracy: 0.9617
Epoch 3/5
60000/60000 [==============================] - 2s 33us/sample - loss: 0.0937 - accuracy: 0.9708
Epoch 4/5
60000/60000 [==============================] - 2s 34us/sample - loss: 0.0745 - accuracy: 0.9766
Epoch 5/5
60000/60000 [==============================] - 2s 33us/sample - loss: 0.0626 - accuracy: 0.9800
10000/10000 [==============================] - 0s 25us/sample - loss: 0.0974 - accuracy: 0.9702
요정도인데 .. -
daehakseng 2020.03.18 19:33
웹카메라나 앱카메라에서 가운데 부분에 정사각형의 윤곽선을 만들고 그 사이에 사진을 찍게 하고 싶은데 어떻게 해야할지를 모르겠습니다. 어떤 코드가 영상에서의 빨간 윤곽선 형태인지 가르쳐주세요ㅠ
-
JO 2020.04.13 15:46
h,w = img_binary.shape
ratio = 100/h
new_h = 100
new_w = w * ratio
img_empty = np.zeros((110,110), dtype=img_binary.dtype)
img_binary = cv2.resize(img_binary, (int(new_w), int(new_h)), interpolation=cv2.INTER_AREA)
img_empty[:img_binary.shape[0], :img_binary.shape[1]] = img_binary
img_binary = img_empty
cnts = cv2.findContours(img_binary.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
이부분 이해가 가지않습니다 ㅠ MNIST로 처리하기위해 (28, 28) 로 resize후 img_empty (110, 110,)를 사용해서 무슨 작업을 하는지 감이 오지 않습니디 ㅠ -
7484 2020.05.13 10:10
if ret == False:
break;
img_input = img_color.copy()
cv2.rectangle(img_color, (250, 150), (width-250, height-150), (0, 0, 255), 3)
cv2.imshow('bgr', img_color)
img_roi = img_input[150:height-150, 250:width-250]
key = cv2.waitKey(1)
if key == 27:
break
elif key == 32:
flatten = process(img_roi)
predictions = model.predict(flatten[np.newaxis,:])
with tf.compat.v1.Session() as sess:
print(tf.argmax(predictions, 1).eval())
cv2.imshow('img_roi', img_roi)
cv2.waitKey(0)
cap.release()
cv2.destroyAllWindows()
이 부분이 무엇을 나타내는지 알려주실 수 있나요?ㅠㅠ-
# 원본 이미지에서 숫자를 인식할 ROI를 지정합니다.
img_roi = img_input[150:height-150, 250:width-250]
key = cv2.waitKey(1)
if key == 27:
break
elif key == 32: # 스페이스바를 누르면
flatten = process(img_roi) # ROI를 입력으로 전처리를 합니다. 인식이 잘되도록 하기 위해서입니다.
predictions = model.predict(flatten[np.newaxis,:]) # 전처리된 이미지를 입력으로 예측을 합니다.
# 예측 결과로부터 숫자를 추출합니다.
with tf.compat.v1.Session() as sess:
print(tf.argmax(predictions, 1).eval())
-
-
-
-
-
서윤 2020.05.19 15:21
>>> def process(img_input):
...
File "<stdin>", line 2
^
IndentationError: expected an indented block
>>> gray = cv2.cvtColor(img_input, cv2.COLOR_BGR2GRAY)
File "<stdin>", line 1
gray = cv2.cvtColor(img_input, cv2.COLOR_BGR2GRAY)
^
IndentationError: unexpected indent
>>>
>>> gray = cv2.resize(gray, (28, 28), interpolation=cv2.INTER_AREA)
이렇게 떠서
인터넷에 검색하니까 들여쓰기 오류라는데 어떻게 해결해야할지 모르겠어요 ㅠㅠ -
1111 2020.06.20 16:54
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(512, activation=tf.nn.relu),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])
이부분에서 자꾸 ValueError: The first layer in a Sequential model must get an `input_shape` argument. 이러한 에러가 발생하여서
저부분 없애고
model = load_model('model.h5')
이렇게 불러서 사용하려 했는데요
계속해서 이부분에서
predictions = model.predict(flatten[np.newaxis,:])
다음과 같은 에러가 발생하는데..
ValueError: Error when checking : expected conv2d_1_input to have 4 dimensions, but got array with shape (1, 784)
이유 알 수 있을까요...?
-
1111 2020.06.21 16:27
빈 여백이나 배경을 비출때 쓰레기 값 숫자를 인식하는 것은 어쩔 수 없는건가요..?
아니면 혹시 학습이 부족해서 그런건가요?