I was working on this project for real time face mask detection, but the i am facing an error cannot reshape array of size 2 into shape (1,100,100,1) - arrays

Please tell me so as to what should i do to solve this problem or what values should i put to solve this problem
while(True):
ret,img = source.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces=face_clsfr.detectMultiScale(gray,1.3,5)
for x,y,w,h in faces:
face_img = gray[y:y+w,x:x+w]
resized = cv2.resize(face_img,(100,100))
normalized=resized/255,0
reshaped = np.reshape(normalized, (1,100,100,1))
result=model.predict(reshaped)
label=np.argmax(result,axis=1)[0]
cv2.rectangle(img,(x,y),(x+w,y+h), colordict[label],2)
cv2.rectangle(img,(x,y-40),(x+w,y), colordict[label],-1)
cv2.putText(img,labels_dict[label], (x,y-10), cv2.FONT_HERSHEY_SIMPLEX,0.8,(255,255,255),2)
cv2.imshow('Frame',img)
key=cv2.waitKey(1)
if(key=='q'):
break
cv2.destroyAllWindows()
source.release

You change the array type of image to a tuple in:
normalized = resized/255,0
change to:
normalized = resized/255

Related

multiple matplotlib chart using loop

I need to draw multiple matploblib chart using a for loop.
I have a data from with multiple column of data points and a time series 'year'. I need to create chart for each column.
I have the following code:
df=pd.DataFrame({'Time':['2014','2015','2016','2017','2018','2019'],
'A':[1,8,3,10,5,6],
'B':[2,3,5,2,3,5],
'C':[7,4,12,11,8,1],
'D':[3,4,2,2,7,7]})
x_pos=range(len(df['Time']))
m,c = np.polyfit(x_pos,df['A'],1)
plt.scatter(x=x_pos,y='A',data=df)
plt.plot(x_pos,m*x_pos+c,'--r')
any help is appreciated
I was able to figure it out. I used the matplotlib.gridspec to achieve this.
Following is the solution:
df=pd.DataFrame({'Time':['2014','2015','2016','2017','2018','2019'],
'A':[1,8,3,10,5,6],
'B':[2,3,5,2,3,5],
'C':[7,4,12,11,8,1],
'D':[3,4,2,2,7,7]})
#import gridspec to fit subplots
import matplotlib.gridspec as gridspec
fig = plt.figure(figsize=(10,10))
# set grid size 2*2
ggpec = gridspec.GridSpec(2, 2)
getaxs = []
datacolumns = list(df[['A','B','C','D']])
for i,j in zip(datacolumns,range(1,len(datacolumns)+1)):
xpos=range(len(df['Time']))
getaxs.append(fig.add_subplot(ggpec[j - 1]))
m,c = np.polyfit(x_pos,df['A'],1)
getaxs[-1].scatter(x=xpos,y=i,data=df)
getaxs[-1].plot(x_pos,m*x_pos+c,'--r')
plt.show()
The final result will be something like following:

Getting black and white image when doing rotation?

I want to rotate my image by 45 degree. I have defined a function for the same. When I run it over my RGB images, it is getting saved as grayscale images?
def rotateImage(image, angle):
row,col = image.shape
center=tuple(np.array([row,col])/2)
rot_mat = cv2.getRotationMatrix2D(center,angle,1.0)
new_image = cv2.warpAffine(image, rot_mat, (col,row))
return new_image
rotate_img_path = '../data/rotate_45_img'
rotate_mask_path = '../data/rotate_45_mask'
real_img_path = '../data/img'
real_mask_path = '../data/mask'
for img in os.listdir(real_img_path):
edge_img = cv2.imread(os.path.join(real_img_path,img))
edges = rotateImage(edge_img, 45)
cv2.imwrite(os.path.join(rotate_img_path, img), edges)
print("Finished Copying images")
for img in os.listdir(real_mask_path):
edge_img = cv2.imread(os.path.join(real_mask_path,img))
edges = rotateImage(edge_img, 45)
cv2.imwrite(os.path.join(rotate_mask_path, img), edges)
# cv2.imwrite('edge_' + '.jpg', edges)
print("Finished Copying masks")
A clue here may be
row,col = image.shape
which would raise an error if image was three dimensional (i.e., in color with separate channels for B, G, and R) instead of two (i.e., grayscale). Unless you're reading RGB images with code not shown here, this suggests that your images are already grayscale.

SolidColourBrush in Silverlight

r= byte.Parse(colours[0]); = 255
g= byte.Parse(colours[1]); = 0
b = byte.Parse(colours[2]); = 0
I have the RGB values as shown above.When i try to use the variables and retrieve the color I am not getting any color in my HMI but when i pass the same values directly i am able to get the color in my silverlight HMI
zoneColour.Color = Color.FromArgb(255,r,g,b); - DOES NOT WORK
zoneColour.Color = Color.FromArgb(255,255,0,0); -WORKS
May this helps you:
//r,g and b must be in integer data type
zoneColor.Color = new SolidColorBrush(Color.FromArgb(r, g, b));
Another method is here.

How to avoid x axis changed when add marks?

I have a problem to consult,when I use the Line of the Point style and show the marks, the x axis would have a problem.When annotate the code (lineSeries5.Add(5, 1,"ghgh");),the x axis shows normally like number 1,2.....,but when I use this code (lineSeries5.Add(5, 1,"ghgh"); ), the x axis becomes 'ghgh',I wonder if how to solve this problem. My purpose is showing the contents which I want to shows in the marks,but the x axis should not be changed. Waiting for your help, thank you very much!
private Steema.TeeChart.WPF.Styles.Points lineSeries5;
this.lineSeries5 = new Steema.TeeChart.WPF.Styles.Points();
this.tChart1.Series.Add(this.lineSeries5);
lineSeries5.Marks.Visible = true;
lineSeries5.Marks.Transparent = true;
lineSeries5.Pointer.Style = Steema.TeeChart.WPF.Styles.PointerStyles.Nothing;
**lineSeries5.Add(5, 1,"ghgh");**
lineSeries5.Add(9, 3);
If you want in your axis labels are values instead of labelsText, you must change the Axis labels style as I do in next line:
tChart1.Axes.Bottom.Labels.Style = AxisLabelStyle.Value;
Could you tell us if previous code solve your problem?
Thanks,

Rotating CGPoints; CIVector CGAffineTransform?

I have 4 CGPoints that form an irregular figure. How can I rotate that figure 90-degrees and get the new CGPoints?
FWIW, I was able to "fake" this when the figure is a CGRect by swapping origin.x and origin.y, and width and height. Will I need to do something similar (calculating distance/direction between points) or is there a AffineTransform I can apply to a CIVector?
Hints and/or pointers to tutorials/guides welcome.
Skippable Project Background:
Users will take pictures of documents and the app will OCR them. Since users have a great deal of trouble getting a non-skewed image, I allow them to create a 4-point figure around the text body and the app skews that back to a rectangle. The camera images coming in are CIImages and so have their origin already in lower-left, so the 4-point figure must be rotated from the UIView to match...
For the record, I used CGAffineTransforms to rotate the points:
CGAffineTransform t1 = CGAffineTransformMakeTranslation(0, cropView.frame.size.height);
CGAffineTransform s = CGAffineTransformMakeScale(1, -1);
CGAffineTransform r = CGAffineTransformMakeRotation(90 * M_PI/180);
CGAffineTransform t2 = CGAffineTransformMakeTranslation(0, -cropView.frame.size.height);
CGPoint a = CGPointMake(70, 23);
a = CGPointApplyAffineTransform(a, t1);
a = CGPointApplyAffineTransform(a, s);
a = CGPointApplyAffineTransform(a, r);
a = CGPointApplyAffineTransform(a, t2);
&c. for the other points.

Resources