{"id":15020365,"url":"https://github.com/hityzy1122/opencv_transforms_torchvision","last_synced_at":"2026-03-15T23:06:34.642Z","repository":{"id":34934463,"uuid":"153127131","full_name":"hityzy1122/opencv_transforms_torchvision","owner":"hityzy1122","description":"opencv reimplement for transforms in torchvision","archived":false,"fork":false,"pushed_at":"2023-10-03T22:35:52.000Z","size":198,"stargazers_count":194,"open_issues_count":8,"forks_count":29,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T01:15:13.903Z","etag":null,"topics":["opencv","pillow","pytorch","torchvision"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hityzy1122.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-15T14:23:25.000Z","updated_at":"2024-12-23T03:16:52.000Z","dependencies_parsed_at":"2025-02-25T04:10:55.591Z","dependency_job_id":"6f543b78-c2ba-487e-9a3a-087a1313b7d5","html_url":"https://github.com/hityzy1122/opencv_transforms_torchvision","commit_stats":null,"previous_names":["yu-zhiyang/opencv_transforms_torchvision"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hityzy1122%2Fopencv_transforms_torchvision","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hityzy1122%2Fopencv_transforms_torchvision/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hityzy1122%2Fopencv_transforms_torchvision/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hityzy1122%2Fopencv_transforms_torchvision/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hityzy1122","download_url":"https://codeload.github.com/hityzy1122/opencv_transforms_torchvision/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137891,"owners_count":21053775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["opencv","pillow","pytorch","torchvision"],"created_at":"2024-09-24T19:54:58.298Z","updated_at":"2026-03-15T23:06:29.622Z","avatar_url":"https://github.com/hityzy1122.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# opencv_torchvision_transform\n1) This is a \"transforms\" in [torchvision](https://github.com/pytorch/vision/tree/master/torchvision/transforms) based on opencv. \n\n2) All functions depend on only cv2 and pytorch (PIL-free). As the [article](https://www.kaggle.com/vfdev5/pil-vs-opencv) says, cv2 is three times faster than PIL.\n\n3) Most functions in transforms are reimplemented, except that:\n\n   1) ToPILImage (opencv we used :)), Scale and RandomSizedCrop which are deprecated in the original version are\n    ignored.\n   \n   2) The affine transform in the original one only has 5 degrees of freedom, I implement an Affine transform with 6\n    degress of freedom called `RandomAffine6` (can be found in [cvtransforms.py](cvtorchvision/cvtransforms/cvtransforms.py)). The\n     original method `RandomAffine` is still retained and reimplemented with opencv.\n   3) My rotate function is clockwise, however the original one is  anticlockwise.\n   4) Adding some new methods which can be found in **Support** (the bolded ones).\n   4) **All the outputs of the opencv version are almost the same as the original one's (test in [cvfunctional.py](/cvtorchvision/cvtransforms/cvfunctional.py#L892-L906))**.\n## Support:\n* `Compose`, `ToTensor`, `ToCVImage`, `Normalize`\n\n* `Resize`, `CenterCrop`, `Pad`\n\n* `Lambda` (doesn't work well in multiprocess in Windows)\n\n* `RandomApply`, `RandomOrder`, `RandomChoice`, `RandomCrop`,\n\n* `RandomHorizontalFlip`, `RandomVerticalFlip`, `RandomResizedCrop`,\n\n* `FiveCrop`, `TenCrop`, `LinearTransformation`, `ColorJitter`,\n\n* `RandomRotation`, `RandomAffine`, `*RandomAffine6`, `*RandomPerspective`\n\n* `*RandomGaussianNoise`, `*RandomPoissonNoise`, `*RandomSPNoise`\n\n* `Grayscale`, `RandomGrayscale`\n# How to use:\n1) git clone https://github.com/YU-Zhiyang/opencv_torchvision_transforms.git .\n\n2) Add `cvtorchvision` to your python path.\n\n3) Add `from cvtorchvision import cvtransforms` in your python file.\n\n4) You can use all functions as the original version, for example:\n\n       transform = cvtransforms.Compose([\n        \n                cvtransforms.RandomAffine(degrees=10, translate=(0.1, 0.1), scale=(0.9, 1.1), shear=(-10, 0),\n        \n                cvtransforms.Resize(size=(350, 350), interpolation='BILINEAR'),\n        \n                cvtransforms.ToTensor(),\n        \n                cvtransforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),\n                ])\n\nmore details can be found in the examples of official [tutorials](https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html).\n\n# Good News:\nYou can install this package via `pip install opencv-torchvision-transforms-yuzhiyang` (Old version only)\n \n# Attention: \nThe multiprocessing used in dataloader of pytorch is not friendly with lambda function in Windows as lambda function can't be pickled (https://docs.python.org/3/library/pickle.html#what-can-be-pickled-and-unpickled).\n\nSo the Lambda in [cvtransforms.py](cvtorchvision/cvtransforms/cvtransforms.py) may not work properly in Windows.\n\n# Requirements\npython \u003e=3.5.2\n\nnumpy \u003e=1.10 ('@' operator may not be overloaded before this version)\n\npytorch\u003e=0.4.1\n\ntorchvision\u003e=0.2.1\n\nopencv-contrib-python-3.4.2 (test with this version, but any version of opencv3 is ok, I think)\n\n# Postscript\nWelcome to point out and help fixing bugs!\n\nThanks [HongChu](https://github.com/hongchu098) who helps a lot.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhityzy1122%2Fopencv_transforms_torchvision","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhityzy1122%2Fopencv_transforms_torchvision","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhityzy1122%2Fopencv_transforms_torchvision/lists"}