-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eea61fc
commit 7dc6ea5
Showing
18 changed files
with
180 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import numpy as np | ||
import cv2 as cv | ||
|
||
|
||
def draw_circle(event, x, y, flags, param): | ||
if event == cv.EVENT_LBUTTONDBLCLK: # çift tıklamada çizer | ||
cv.circle(img, (x, y), 100, (200, 110, 200), -1) | ||
|
||
|
||
img = np.zeros((515, 1000, 3), np.uint8) # pencere boyutları | ||
cv.namedWindow('img') | ||
cv.setMouseCallback('img', draw_circle) | ||
while True: | ||
cv.imshow('img', img) | ||
if cv.waitKey(20) & 0xFF == 27: # esc ye basınca çıkış | ||
break | ||
cv.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import numpy as np | ||
import cv2 as cv | ||
|
||
|
||
def nothing(x): | ||
pass | ||
|
||
|
||
img = np.zeros((300, 512, 3), np.uint8) | ||
cv.namedWindow('image') | ||
|
||
cv.createTrackbar('R', 'image', 0, 255, nothing) | ||
cv.createTrackbar('G', 'image', 0, 255, nothing) | ||
cv.createTrackbar('B', 'image', 0, 255, nothing) | ||
|
||
switch = '0 : OFF \n1 : ON' | ||
cv.createTrackbar(switch, 'image', 0, 1, nothing) | ||
while True: | ||
cv.imshow('image', img) | ||
k = cv.waitKey(1) & 0xFF | ||
if k == 27: # ESC | ||
break | ||
|
||
r = cv.getTrackbarPos('R', 'image') | ||
g = cv.getTrackbarPos('G', 'image') | ||
b = cv.getTrackbarPos('B', 'image') | ||
s = cv.getTrackbarPos(switch, 'image') | ||
if s == 0: | ||
img[:] = 0 | ||
else: | ||
img[:] = [b, g, r] | ||
cv.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import cv2 as cv | ||
|
||
cap = cv.VideoCapture(0) # 1'de ikinci kamerayı açar | ||
if not cap.isOpened(): | ||
print("Cant open the camera") | ||
exit() | ||
while True: | ||
ret, frame = cap.read() # frameleri döner | ||
if not ret: | ||
print("Cant receive frame") | ||
break | ||
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) | ||
cv.imshow('frame', gray) | ||
if cv.waitKey() == ord('s'): | ||
break | ||
cap.release() | ||
cv.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import cv2 as cv | ||
|
||
cap = cv.VideoCapture('output.avi') | ||
while cap.isOpened(): | ||
ret, frame = cap.read() | ||
if not ret: | ||
print("Can't receive the frame") | ||
break | ||
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) | ||
cv.imshow('frame', gray) | ||
if cv.waitKey(1) == ord('q'): | ||
break | ||
cap.release() | ||
cv.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import cv2 as cv | ||
|
||
cap = cv.VideoCapture(0) | ||
fourcc = cv.VideoWriter_fourcc(*'DIVX') | ||
out = cv.VideoWriter('output.avi', fourcc, 20.0, (640, 480)) | ||
while cap.isOpened(): | ||
ret, frame = cap.read() | ||
if not ret: | ||
print("Can't receive the frame") | ||
break | ||
frame = cv.flip(frame, 0) | ||
out.write(frame) | ||
cv.imshow('frame', frame) | ||
if cv.waitKey(1) == ord('q'): | ||
break | ||
cap.release() | ||
out.release() | ||
cv.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import cv2 as cv | ||
import numpy as np | ||
import argparse | ||
|
||
# konsoldan çalıştırmak için: | ||
# python Hough-Ex1.py -i ../input_pictures/soda.png | ||
|
||
# minDist çok küçük olursa daire olmayan yerlerde bile daire algılayabiliriz. | ||
# minDist çok büyük olursa bazı daireleri algılayamayabiliriz | ||
ap = argparse.ArgumentParser() | ||
ap.add_argument("-i", "--image", required=True, help="Path of image") | ||
args = vars(ap.parse_args()) | ||
|
||
img = cv.imread(args["image"]) | ||
img2 = img.copy() # bu işlemi yaptığım yere göre outputun size'ı(kB) değişiyor. | ||
|
||
img = cv.GaussianBlur(img, (7, 7), 1.5) | ||
|
||
|
||
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY) | ||
|
||
circles = cv.HoughCircles(img, cv.HOUGH_GRADIENT, 1.3, 30, param1=60, param2=70) | ||
|
||
# param2 küçükse yanlış daireler de algılıyor | ||
circles = np.uint16(np.around(circles)) | ||
|
||
for c in circles[0, :]: | ||
cv.circle(img2, (c[0], c[1]), c[2], (0, 255, 0), 2) | ||
cv.circle(img2, (c[0], c[1]), 1, (0, 0, 255), 3) | ||
|
||
cv.imshow("img", img2) | ||
# cv.imshow("img", np.hstack([img, img2])) | ||
cv.waitKey(0) | ||
cv.imwrite("houghcircle-ex1.png", img2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import cv2 as cv | ||
import numpy as np | ||
import argparse | ||
|
||
# konsoldan çalıştırmak için: | ||
# python Hough-Ex2.py -i ../input_pictures/input_bobin.png | ||
|
||
ap = argparse.ArgumentParser() | ||
ap.add_argument("-i", "--image", required=True, help="Path of image") | ||
args = vars(ap.parse_args()) | ||
|
||
img = cv.imread(args["image"]) | ||
img2 = img.copy() | ||
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY) | ||
img = cv.GaussianBlur(img, (7, 7), 1.5) | ||
img = cv.Canny(img, 50, 120) | ||
|
||
cv.imshow("image with blur and grayscale", img) | ||
circles = cv.HoughCircles(img, cv.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0) | ||
|
||
# param1 : Upper threshold for the internal Canny edge detector. | ||
# param2 : Threshold for center detection. | ||
|
||
|
||
# dp 0 ile 2 arasında double sayılar olmalı | ||
# param2 küçükse yanlış daireler de algılıyor | ||
circles = np.uint16(np.around(circles)) | ||
|
||
for c in circles[0, :]: | ||
print(c) # x, y, r | ||
cv.circle(img2, (c[0], c[1]), c[2], (0, 255, 0), 2) | ||
cv.circle(img2, (c[0], c[1]), 1, (0, 0, 255), 3) | ||
|
||
cv.imshow(" output img", img2) | ||
# cv.imshow("img", np.hstack([img, img2])) | ||
cv.waitKey(0) | ||
cv.imwrite("houghcircle-ex2.png", img2) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import cv2 as cv | ||
import numpy as np | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.