```
* Dump the `pixelate` model to disk.
```
-./bin/run_local.sh -d model_pix -f pixelate
+./bin/run_local.sh -d model_pix -f pixelate -i image.jpg -p predict.csv
```
* Evaluate the `detect` model from disk and a previously produced detect object
```
-./bin/run_local.sh -d model_detect -f detect -p output.csv -i web_demo/images/face_DiCaprio.jpg
+./bin/run_local.sh -d model_detect -p output.csv -i web_demo/images/face_DiCaprio.jpg
```
* Example for evaluating the `pixelate` model from disk and a previously produced detect object
```
-./bin/run_local.sh -d model_pix -f pixelate -i detect.csv -p output.jpg --csv_input
+./bin/run_local.sh -d model_pix -i detect.csv -p output.jpg --csv_input
```
* [DiCaprio celebrity face sample](web_demo/images/face_DiCaprio.jpg) [wikimedia source](https://en.wikipedia.org/wiki/Celebrity#/media/File:Leonardo_DiCaprio_visited_Goddard_Saturday_to_discuss_Earth_science_with_Piers_Sellers_(26105091624)_cropped.jpg)
* [Schwarzenegger celebrity face sample](web_demo/images/face_Schwarzenegger.jpg) [wikimedia source](https://upload.wikimedia.org/wikipedia/commons/thumb/0/0f/A._Schwarzenegger.jpg/220px-A._Schwarzenegger.jpg)
+* [Commercial example](web_demo/images/commercial.jpg) [youtube source](https://www.youtube.com/watch?v=34KfCNapnUg)
+
<table width='100%'>
<thead>
<tr><td width='49%'>before</td><td width='49%'>after</td></tr>
</thead>
<tbody>
-<tr style='max-height:100px;'>
+<tr >
<td><img src="web_demo/images/face_DiCaprio.jpg" alt="raw" height="100px;"/></td>
<td><img src="web_demo/images/face_DiCaprio_pixelate.jpg" alt="pixelate" height="100px;"/></td>
</tr>
+<tr >
+ <td><img src="web_demo/images/commercial.jpg" alt="raw" height="100px;"/></td>
+ <td><img src="web_demo/images/commercial_pixelate.jpg" alt="pixelate" height="100px;"/></td>
+</tr>
</tbody>
</table>
\ No newline at end of file
@staticmethod
def suppress_image(df):
keep_col = [FaceDetectTransform.COL_FACE_X, FaceDetectTransform.COL_FACE_Y,
+ FaceDetectTransform.COL_FACE_W, FaceDetectTransform.COL_FACE_H,
FaceDetectTransform.COL_FACE_W, FaceDetectTransform.COL_FACE_H,
FaceDetectTransform.COL_REGION_IDX, FaceDetectTransform.COL_IMAGE_IDX]
blank_cols = [col for col in df.columns if col not in keep_col]
df = pd.DataFrame() # start with empty DF for this image
if self.include_image: # create and append the image if that's requested
- dict_image = FaceDetectTransform.generate_out_dict(w=img.shape[0], h=img.shape[1], image=image_idx)
+ dict_image = FaceDetectTransform.generate_out_dict(w=img.shape[1], h=img.shape[0], image=image_idx)
dict_image[FaceDetectTransform.COL_IMAGE_MIME] = X[FaceDetectTransform.COL_IMAGE_MIME][image_idx]
dict_image[FaceDetectTransform.COL_IMAGE_DATA] = X[FaceDetectTransform.COL_IMAGE_DATA][image_idx]
df = pd.DataFrame([dict_image])
https://stackoverflow.com/a/43024993
"""
from ast import literal_eval
- if bytearray_string.startswith("b'"):
+ if type(bytearray_string)==str and bytearray_string.startswith("b'"):
return bytearray(literal_eval(bytearray_string))
return bytearray_string
#print(image_data)
img = image_data['data']
for r in image_data['regions']: # loop through regions
- x_max = min(r[0]+r[2], img.shape[0])
- y_max = min(r[1]+r[3], img.shape[1])
+ x_max = min(r[0]+r[2], img.shape[1])
+ y_max = min(r[1]+r[3], img.shape[0])
if self.transform_mode=="pixelate":
block_size = round(max(img.shape[0], img.shape[2])/15)
- img[r[0]:x_max, r[1]:y_max] = \
- RegionTransform.pixelate_image(img[r[0]:x_max, r[1]:y_max], block_size)
+ img[r[1]:y_max, r[0]:x_max] = \
+ RegionTransform.pixelate_image(img[r[1]:y_max, r[0]:x_max], block_size)
# for now, we hard code to jpg output; TODO: add more encoding output (or try to match source?)
img_binary = cv2.imencode(".jpg", img)[1].tostring()
# http://www.jeffreythompson.org/blog/2012/02/18/pixelate-and-posterize-in-processing/
@staticmethod
def pixelate_image(img, blockSize):
+ if not img.shape[0] or not img.shape[1]:
+ return img
ratio = (img.shape[1] / img.shape[0]) if img.shape[0] < img.shape[1] else (img.shape[0] / img.shape[1])
blockHeight = round(blockSize * ratio) # so that we cover all image
for x in range(0, img.shape[0], blockSize):