Skip to content

Instantly share code, notes, and snippets.

import random
import glob
import os
import shutil
def copyfiles(fil, root_dir):
basename = os.path.basename(fil)
filename = os.path.splitext(basename)[0]
from PIL import Image, ImageDraw
def yolo_to_xml_bbox(bbox, w, h):
# x_center, y_center width heigth
w_half_len = (bbox[2] * w) / 2
h_half_len = (bbox[3] * h) / 2
xmin = int((bbox[0] * w) - w_half_len)
ymin = int((bbox[1] * h) - h_half_len)
xmax = int((bbox[0] * w) + w_half_len)
import xml.etree.ElementTree as ET
import glob
import os
import json
def xml_to_yolo_bbox(bbox, w, h):
# xmin, ymin, xmax, ymax
x_center = ((bbox[2] + bbox[0]) / 2) / w
y_center = ((bbox[3] + bbox[1]) / 2) / h
@atultiwari
atultiwari / convert_voc_to_yolo.md
Created May 1, 2022 18:52 — forked from Amir22010/convert_voc_to_yolo.md
convert pascal voc dataset to yolo format

Convert PascalVOC Annotations to YOLO

This script reads PascalVOC xml files, and converts them to YOLO txt files.

Note: This script was written and tested on Ubuntu. YMMV on other OS's.

Disclaimer: This code is a modified version of Joseph Redmon's voc_label.py

Instructions:

  1. Place the convert_voc_to_yolo.py file into your data folder.
@atultiwari
atultiwari / center_crop_scale.py
Created January 31, 2022 21:48 — forked from Nannigalaxy/center_crop_scale.py
Center Crop and Image Scaling functions in OpenCV using Python
# Center Crop and Image Scaling functions in OpenCV
# Date: 11/10/2020
# Written by Nandan M
import cv2
def center_crop(img, dim):
"""Returns center cropped image
Args:
<?php
/**
* Check the orderby param for the particular REST API for hte custom post type.
* If it is set to a particular meta_ket, then set the orderby and meta_key query args/
* @link https://www.timrosswebdevelopment.com/wordpress-rest-api-order-by-meta_value/
*/
function filter_rest_accommodation_query($query_vars, $request) {
$orderby = $request->get_param('orderby');
if (isset($orderby) && $orderby === 'number_of_beds') {
$query_vars["orderby"] = "meta_value_num";
<?php
// Register the meta field for the rest api
// https://stackoverflow.com/questions/56460557/how-to-include-meta-fields-in-wordpress-api-post#answer-56508996
add_action( 'rest_api_init', 'register_postviews_meta_fields');
function register_postviews_meta_fields(){
register_meta( 'post', 'wpb_post_views_count', array(
'type' => 'integer',
'description' => 'Post views',
'single' => true,
<?php
/**
* Function created by - Dr. Atul
* Adapted from Anspress by Rahul Aryan
**/
function AddQuestionToAnsPress($question_title, $question_content, $answer_content, $anspress_category_id, $anspress_tags_id) {
require('../wp-load.php');
<?php
/**
* Function orignally created by Rahul Aryan,
* Modified by - Dr. Atul
**/
function at_submit_answer_form( $manual = false, $question_post_id) {
$editing = false;
$question_id = $question_post_id;
@$form = anspress()->get_form( 'answer' );
/**
<?php
/**
* Process custom question form submission.
* Original work by - Rahul Aryan
* Modified by - Dr. Atul
* @return void
* @since 4.1.0
*/
function at_submit_question_form() {