Edward Lance Lorilla |
- 【JAVASCRIPT】 dynamically table addition and deletion operations
- 【GAMEMAKER】Multiple Location
- 【VISUAL VB.NET】Custom List View
- 【PYTHON OPENCV】Detecting facial landmarks using dlib
【JAVASCRIPT】 dynamically table addition and deletion operations Posted: 21 Apr 2021 09:09 PM PDT |
Posted: 21 Apr 2021 09:27 AM PDT Information about object: obj_player Sprite: spr_idle_down Solid: false Visible: true Depth: 0 Persistent: false Parent: Children: Mask: No Physics Object Create Event: execute code: Step Event: execute code: execute code: execute code: Collision Event with object obj_church_enter: execute code: Collision Event with object obj_church_leave: execute code: Collision Event with object obj_chest: execute code: Draw Event: execute code: Information about object: obj_church_enter |
【VISUAL VB.NET】Custom List View Posted: 21 Apr 2021 10:24 AM PDT Public Class Form1 Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) End SubEnd ClassPublic Class CustomDrawListBox Inherits ListBox Public Sub New() Me.DrawMode = DrawMode.OwnerDrawVariable ' We're using custom drawing. ' Set the item height to 40. Me.ItemHeight = 40 End Sub Protected Overrides Sub OnDrawItem(e As DrawItemEventArgs) ' Make sure we're not trying to draw something that isn't there. If e.Index >= Me.Items.Count OrElse e.Index <= -1 Then Return End If ' Get the item object. Dim item As Object = Me.Items(e.Index) If item Is Nothing Then Return End If ' Draw the background color depending on ' if the item is selected or not. If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then ' The item is selected. ' We want a blue background color. e.Graphics.FillRectangle(New SolidBrush(Color.Blue), e.Bounds) Else ' The item is NOT selected. ' We want a white background color. e.Graphics.FillRectangle(New SolidBrush(Color.White), e.Bounds) End If ' Draw the item. Dim text As String = item.ToString() Dim stringSize As SizeF = e.Graphics.MeasureString(text, Me.Font) e.Graphics.DrawString(text, Me.Font, New SolidBrush(Color.White), New PointF(5, e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2)) End SubEnd Class |
【PYTHON OPENCV】Detecting facial landmarks using dlib Posted: 21 Apr 2021 09:16 AM PDT """ Detecting facial landmarks using dlib """ # Import required packages:import cv2import dlibimport numpy as np # Define what landmarks you want:JAWLINE_POINTS = list(range(0, 17))RIGHT_EYEBROW_POINTS = list(range(17, 22))LEFT_EYEBROW_POINTS = list(range(22, 27))NOSE_BRIDGE_POINTS = list(range(27, 31))LOWER_NOSE_POINTS = list(range(31, 36))RIGHT_EYE_POINTS = list(range(36, 42))LEFT_EYE_POINTS = list(range(42, 48))MOUTH_OUTLINE_POINTS = list(range(48, 61))MOUTH_INNER_POINTS = list(range(61, 68))ALL_POINTS = list(range(0, 68)) def draw_shape_lines_all(np_shape, image): """Draws the shape using lines to connect between different parts of the face(e.g. nose, eyes, ...)""" draw_shape_lines_range(np_shape, image, JAWLINE_POINTS) draw_shape_lines_range(np_shape, image, RIGHT_EYEBROW_POINTS) draw_shape_lines_range(np_shape, image, LEFT_EYEBROW_POINTS) draw_shape_lines_range(np_shape, image, NOSE_BRIDGE_POINTS) draw_shape_lines_range(np_shape, image, LOWER_NOSE_POINTS) draw_shape_lines_range(np_shape, image, RIGHT_EYE_POINTS, True) draw_shape_lines_range(np_shape, image, LEFT_EYE_POINTS, True) draw_shape_lines_range(np_shape, image, MOUTH_OUTLINE_POINTS, True) draw_shape_lines_range(np_shape, image, MOUTH_INNER_POINTS, True) def draw_shape_lines_range(np_shape, image, range_points, is_closed=False): """Draws the shape using lines to connect the different points""" np_shape_display = np_shape[range_points] points = np.array(np_shape_display, dtype=np.int32) cv2.polylines(image, [points], is_closed, (255, 255, 0), thickness=1, lineType=cv2.LINE_8) def draw_shape_points_pos_range(np_shape, image, points): """Draws the shape using points and position for every landmark filtering by points parameter""" np_shape_display = np_shape[points] draw_shape_points_pos(np_shape_display, image) def draw_shape_points_pos(np_shape, image): """Draws the shape using points and position for every landmark""" for idx, (x, y) in enumerate(np_shape): # Draw the positions for every detected landmark: cv2.putText(image, str(idx + 1), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.4, (0, 0, 255)) # Draw a point on every landmark position: cv2.circle(image, (x, y), 2, (0, 255, 0), -1) def draw_shape_points_range(np_shape, image, points): """Draws the shape using points for every landmark filtering by points parameter""" np_shape_display = np_shape[points] draw_shape_points(np_shape_display, image) def draw_shape_points(np_shape, image): """Draws the shape using points for every landmark""" # Draw a point on every landmark position: for (x, y) in np_shape: cv2.circle(image, (x, y), 2, (0, 255, 0), -1) def shape_to_np(dlib_shape, dtype="int"): """Converts dlib shape object to numpy array""" # Initialize the list of (x,y) coordinates coordinates = np.zeros((dlib_shape.num_parts, 2), dtype=dtype) # Loop over all facial landmarks and convert them to a tuple with (x,y) coordinates: for i in range(0, dlib_shape.num_parts): coordinates[i] = (dlib_shape.part(i).x, dlib_shape.part(i).y) # Return the list of (x,y) coordinates: return coordinates # Name of the two shape predictors:p = "shape_predictor_68_face_landmarks.dat"# p = "shape_predictor_5_face_landmarks.dat" # Initialize frontal face detector and shape predictor:detector = dlib.get_frontal_face_detector()predictor = dlib.shape_predictor(p) # Create VideoCapture object to get images from the webcam:video_capture = cv2.VideoCapture("istockphoto-1131308747-640_adpp_is.mp4") # You can use a test image for debugging purposes:test_face = cv2.imread("face_test.png") while True: # Capture frame from the VideoCapture object: ret, frame = video_capture.read() # Just for debugging purposes: # frame = test_face.copy() # Convert frame to grayscale: gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Detect faces: rects = detector(gray, 0) # For each detected face, find the landmark. for (i, rect) in enumerate(rects): # Draw a box around the face: cv2.rectangle(frame, (rect.left(), rect.top()), (rect.right(), rect.bottom()), (0, 255, 0), 1) # Get the shape using the predictor: shape = predictor(gray, rect) # Convert the shape to numpy array: shape = shape_to_np(shape) # Draw all lines connecting the different face parts: # draw_shape_lines_all(shape, frame) # Draw jaw line: # draw_shape_lines_range(shape, frame, JAWLINE_POINTS) # Draw all points and their position: # draw_shape_points_pos(shape, frame) # You can also use: # draw_shape_points_pos_range(shape, frame, ALL_POINTS) # Draw all shape points: draw_shape_points(shape, frame) # Draw left eye, right eye and bridge shape points and positions# draw_shape_points_pos_range(shape, frame, LEFT_EYE_POINTS + RIGHT_EYE_POINTS + NOSE_BRIDGE_POINTS) # Display the resulting frame cv2.imshow("Landmarks detection using dlib", frame) # Press 'q' key to exit if cv2.waitKey(1) & 0xFF == ord('q'): break # Release everything:video_capture.release()cv2.destroyAllWindows() |
You are subscribed to email updates from Edward Lance Lorilla. To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google, 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States |
No comments:
Post a Comment