CN114511713A - Image-based prediction method and device and server - Google Patents
Image-based prediction method and device and server Download PDFInfo
- Publication number
- CN114511713A CN114511713A CN202210412967.5A CN202210412967A CN114511713A CN 114511713 A CN114511713 A CN 114511713A CN 202210412967 A CN202210412967 A CN 202210412967A CN 114511713 A CN114511713 A CN 114511713A
- Authority
- CN
- China
- Prior art keywords
- matrix
- image
- sub
- similarity
- expression
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 52
- 239000011159 matrix material Substances 0.000 claims abstract description 303
- 238000006243 chemical reaction Methods 0.000 claims abstract description 31
- 238000004364 calculation method Methods 0.000 claims abstract description 21
- 238000012545 processing Methods 0.000 claims abstract description 20
- 238000004422 calculation algorithm Methods 0.000 claims description 34
- 238000012216 screening Methods 0.000 claims description 8
- 230000008569 process Effects 0.000 description 6
- 238000004891 communication Methods 0.000 description 5
- 238000004590 computer program Methods 0.000 description 5
- 230000009471 action Effects 0.000 description 3
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 238000010586 diagram Methods 0.000 description 3
- 230000008451 emotion Effects 0.000 description 3
- 239000000284 extract Substances 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000005540 biological transmission Effects 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 235000012054 meals Nutrition 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 239000007787 solid Substances 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/22—Matching criteria, e.g. proximity measures
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L51/00—User-to-user messaging in packet-switching networks, transmitted according to store-and-forward or real-time protocols, e.g. e-mail
- H04L51/04—Real-time or near real-time messaging, e.g. instant messaging [IM]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L51/00—User-to-user messaging in packet-switching networks, transmitted according to store-and-forward or real-time protocols, e.g. e-mail
- H04L51/07—User-to-user messaging in packet-switching networks, transmitted according to store-and-forward or real-time protocols, e.g. e-mail characterised by the inclusion of specific contents
- H04L51/10—Multimedia information
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Signal Processing (AREA)
- Computer Networks & Wireless Communication (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Evolutionary Biology (AREA)
- Evolutionary Computation (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Bioinformatics & Computational Biology (AREA)
- Multimedia (AREA)
- Artificial Intelligence (AREA)
- Life Sciences & Earth Sciences (AREA)
- Compression Or Coding Systems Of Tv Signals (AREA)
Abstract
The invention provides a prediction method, a prediction device and a server based on an image, belonging to the field of image processing and comprising the following steps: obtaining an expression image sent by a chat object in a chat frame of social software; performing gray level conversion on the expression image to generate a gray level image; cutting the gray level image to form M-N sub-images, and encoding each sub-image based on Hash encoding to generate a target matrix; wherein M and N are both positive integers; similarity calculation is carried out on the target matrix and a first matrix in a first database, and a second matrix with similarity exceeding a preset threshold value with the target matrix is determined in the first matrix; and finding out the expression images corresponding to the second matrix from the first database, and displaying the expression images corresponding to the second matrix to the user according to the sequence of similarity from high to low. By the method, the user using the social software can quickly reply through the predicted expression image liked by the chat object.
Description
Technical Field
The invention relates to the field of image processing, in particular to a prediction method and device based on an image and a server.
Background
Today, with the rapid development of social networks, chat interactions of network users are not away from increasingly rich social software. Because many network users do not leave real information on the social network platform at present, the network users can only guess corresponding emotions according to characters and expression images of chat objects, and the use experience of the users is seriously influenced.
Disclosure of Invention
The embodiment of the invention aims to provide a prediction method, a prediction device and a server based on an image so as to improve the use experience of a user on social software.
The invention is realized by the following steps:
in a first aspect, an embodiment of the present invention provides an image-based prediction method, including: obtaining an expression image sent by a chat object in a chat frame of social software; performing gray level conversion on the expression image to generate a gray level image; cutting the gray level image to form M-N sub-images, and encoding each sub-image based on Hash encoding to generate a target matrix; wherein M and N are both positive integers; similarity calculation is carried out on the target matrix and a first matrix in a first database, and a second matrix, the similarity of which with the target matrix exceeds a preset threshold value, is determined in the first matrix; the first matrix is generated by performing gray level conversion, image cutting and hash coding on the expression images stored in the first database; finding out expression images corresponding to the second matrix from the first database, and displaying the expression images corresponding to the second matrix to a user according to the sequence of similarity from high to low; and the expression image corresponding to the second matrix is the predicted expression image liked by the chat object.
In the embodiment of the invention, a server acquires the expression image sent by a chat object in a chat frame of social software; then, carrying out gray level conversion on the expression image to generate a gray level image; cutting the gray level image to form M-N sub-images, and encoding each sub-image based on Hash encoding to generate a target matrix; then, similarity calculation is carried out on the target matrix and a first matrix in a first database, and a second matrix with similarity exceeding a preset threshold value with the target matrix is determined in the first matrix; and finally, finding out the expression image corresponding to the second matrix from the first database, and displaying the expression images corresponding to the second matrix to the user according to the sequence of similarity from high to low. By the method, the user using the social software can quickly reply through the predicted expression image liked by the chat object, namely, the prediction method can accurately predict the expression image liked by the chat object, and further improves the use experience of the user in chatting by adopting the chat software.
With reference to the technical solution provided by the first aspect, in some possible implementation manners, the performing gray-scale conversion on the expression image to generate a gray-scale image includes: performing gray level conversion on the expression image by adopting a weighting algorithm to generate a gray level image; wherein the expression of the weighting algorithm is:;representing the gray values of the pixels of the gray scale image,representing the pixel value of a red channel of a pixel point;representing the pixel value of a green channel of a pixel point;expressing the pixel value of a blue channel of a pixel point, or performing gray level conversion on the expression image by adopting an average algorithm to generate the gray level image; wherein, the expression of the mean algorithm is as follows:;representing the gray values of the pixels of the gray scale image,representing the pixel value of a red channel of a pixel point;representing the pixel value of a green channel of a pixel point;and expressing the pixel value of the blue channel of the pixel point.
In the embodiment of the invention, the expression image is subjected to gray level conversion through a weighting algorithm or an average algorithm, so that the image can be effectively subjected to gray level processing, and the subsequent Hash coding processing can be conveniently carried out on the gray level image.
With reference to the technical solution provided by the first aspect, in some possible implementation manners, the encoding each sub-image based on hash coding to generate a target matrix includes: calculating the pixel mean value of each sub-image and the pixel mean value of the gray level image; comparing the pixel mean value of each sub-image with the pixel mean value of the gray level image respectively; generating the target matrix based on the numerical comparison result; if the pixel mean value of the sub-image is greater than the pixel mean value of the gray-scale image, the sub-image is marked as 1, if the pixel mean value of the sub-image is not greater than the pixel mean value of the gray-scale image, the sub-image is marked as 0, or if the pixel mean value of the sub-image is greater than the pixel mean value of the gray-scale image, the sub-image is marked as 0, and if the pixel mean value of the sub-image is not greater than the pixel mean value of the gray-scale image, the sub-image is marked as 1.
In the embodiment of the invention, the pixel mean value of each sub-image is obtained, and the pixel mean value of the gray level image is obtained; then, the pixel mean value of each sub-image is compared with the pixel mean value of the gray level image in numerical value; and finally, generating a target matrix based on the comparison result. The target matrix formed by the method is composed of different numerical values, so that the similarity between the first matrix and the target matrix can be calculated conveniently according to the numerical values, and the method can improve the reasonability and reliability of the similarity calculation between the images.
With reference to the technical solution provided by the first aspect, in some possible implementation manners, the calculating a pixel mean value of each of the sub-images and a pixel mean value of the grayscale image includes: acquiring the gray value of each pixel point in each sub-image; calculating the average value of the gray values of all pixel points in each sub-image to obtain the pixel average value of each sub-image; and calculating the average value of the pixel mean values of all the sub-images in the gray level image to obtain the pixel mean value of the gray level image.
In the embodiment of the invention, the gray value of each pixel point in each sub-image is obtained; then calculating the average value of the gray values of all pixel points in each sub-image to obtain the pixel mean value of each sub-image; and finally, calculating the average value of the pixel mean values of all the sub-images in the gray level image so as to obtain the reasonable and reliable pixel mean value of the gray level image.
With reference to the technical solution provided by the first aspect, in some possible implementation manners, the calculating a similarity between the target matrix and a first matrix in a first database, and determining a second matrix in the first matrix, where the similarity with the target matrix exceeds a preset threshold, includes: calculating the similarity between the target matrix and each first matrix in the first database based on a Hamming distance algorithm, and determining a third matrix; and screening out the second matrix with the similarity exceeding a preset threshold value with the target matrix from the third matrix.
In the embodiment of the invention, the similarity between the target matrix and the first matrix can be accurately calculated by a Hamming distance algorithm.
With reference to the technical solution provided by the first aspect, in some possible implementation manners, the calculating a similarity between the target matrix and a first matrix in a first database, and determining a second matrix in the first matrix, where the similarity with the target matrix exceeds a preset threshold, includes: calculating the similarity between the target matrix and a first matrix in a first database by a cosine similarity algorithm to determine a third matrix; wherein, the formula of the cosine similarity algorithm is as follows:
(ii) a Wherein,representing cosine similarity of the target matrix and the first matrix; a represents the target matrix; b represents the first matrix;representing the ith value in the target matrix;representing the ith value in the first matrix; and screening out the second matrix with the similarity exceeding a preset threshold value with the target matrix from the third matrix.
In the embodiment of the invention, the similarity between the target matrix and the first matrix can be more accurately and reasonably calculated by a cosine similarity calculation method.
With reference to the technical solution provided by the first aspect, in some possible implementation manners, the expression images in the first database are divided into different matrix groups according to types; each matrix group comprises a plurality of first matrices, the similarity calculation of the target matrix and the first matrices in the first database is carried out, and a second matrix with the similarity exceeding a preset threshold value with the target matrix is determined in the first matrices, and the method comprises the following steps: calculating the similarity of the target matrix and a first matrix in each matrix group; acquiring a preset number of fourth matrixes with highest similarity in each matrix group; calculating the average value of the similarity of the fourth matrix and the first matrix in each matrix group; and determining a matrix with the similarity exceeding a preset threshold in the fourth matrix with the maximum average value as the second matrix.
In the embodiment of the present invention, the specific process of calculating the similarity is as follows: calculating the similarity of the target matrix and the first matrix in each matrix group; acquiring a preset number of fourth matrixes with highest similarity in each matrix group; calculating the average value of the similarity of the fourth matrix and the first matrix in each matrix group; and determining a matrix with the similarity exceeding a preset threshold in the fourth matrix with the maximum average value as the second matrix. In this way, the influence of the same expression image on the prediction result when the same expression image appears in different groups can be reduced.
With reference to the technical solution provided by the first aspect, in some possible implementations, the method further includes: extracting characters in the expression image; acquiring a reply language book corresponding to the characters from a second database; finding out an expression image containing the reply language record from a third database; and the expression image containing the reply language book is the predicted expression image used for replying the chat object.
In the embodiment of the invention, the server extracts the characters in the expression image; acquiring a reply language book corresponding to the characters from a second database; the emotion images containing the reply language records are searched out from the third database, so that the user can reply the chat object in an emotion image mode, the chat efficiency is improved, and the user experience is also improved.
In a second aspect, an embodiment of the present invention further provides an age prediction apparatus based on a user avatar, including: the obtaining module is used for obtaining the expression image sent by the chat object in the chat frame of the social software; the processing module is used for carrying out gray level conversion on the expression image to generate a gray level image; cutting the gray level image to form M-N sub-images, and encoding each sub-image based on Hash encoding to generate a target matrix; wherein M and N are both positive integers; similarity calculation is carried out on the target matrix and a first matrix in a first database, and a second matrix, the similarity of which with the target matrix exceeds a preset threshold value, is determined in the first matrix; the first matrix is generated by performing gray level conversion, image cutting and hash coding on the expression images stored in the first database; the prediction module is used for searching the expression image corresponding to the second matrix from the first database and displaying the expression image corresponding to the second matrix to a user according to the sequence of similarity from high to low; and the expression image corresponding to the second matrix is the predicted expression image liked by the chat object.
In a third aspect, an embodiment of the present invention provides a server, including: a processor and a memory, the processor and the memory connected; the memory is used for storing programs; the processor is configured to invoke a program stored in the memory to perform a method as provided in the above-described first aspect embodiment and/or in combination with some possible implementations of the above-described first aspect embodiment.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, performs the method as described in the first aspect embodiment above and/or in combination with some possible implementations of the first aspect embodiment above.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the embodiments of the present invention will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained according to the drawings without inventive efforts.
Fig. 1 is a block diagram of a server according to an embodiment of the present invention.
Fig. 2 is a flowchart illustrating steps of an image-based prediction method according to an embodiment of the present invention.
Fig. 3 is a block diagram of an image-based prediction apparatus according to an embodiment of the present invention.
Icon: 100-a server; 110-a processor; 120-a memory; 200-image based prediction means; 210-an obtaining module; 220-a processing module; 230-prediction module.
Detailed Description
The technical solutions in the embodiments of the present invention will be described below with reference to the drawings in the embodiments of the present invention.
Referring to fig. 1, a schematic block diagram of a server 100 applying a prediction method and apparatus based on images according to an embodiment of the present invention is shown. In the embodiment of the present invention, the server 100 may be, but is not limited to, a web server, a first database server, a cloud server, or a server assembly composed of multiple sub servers. Of course, the above-mentioned devices are only used to facilitate understanding of the embodiments of the present invention, and should not be taken as limiting the embodiments.
Structurally, the server 100 may include a processor 110 and a memory 120.
The processor 110 and the memory 120 are electrically connected directly or indirectly to enable data transmission or interaction, for example, the components may be electrically connected to each other via one or more communication buses or signal lines. The image-based prediction apparatus 200 includes at least one software module that may be stored in the memory 120 in the form of software or Firmware (Firmware) or solidified in an Operating System (OS) of the server 100. The processor 110 is configured to execute executable modules stored in the memory 120, such as software functional modules and computer programs included in the image-based prediction apparatus 200, so as to implement the image-based prediction method. The processor 110 may execute the computer program upon receiving the execution instruction.
The processor 110 may be an integrated circuit chip having signal processing capabilities. The Processor 110 may also be a general-purpose Processor, for example, a Central Processing Unit (CPU), a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a discrete gate or transistor logic device, or a discrete hardware component, which may implement or execute the methods, steps, and logic blocks disclosed in the embodiments of the present invention. Further, a general purpose processor may be a microprocessor or any conventional processor or the like.
The Memory 120 may be, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), and an electrically Erasable Programmable Read-Only Memory (EEPROM). The memory 120 is used for storing a program, and the processor 110 executes the program after receiving the execution instruction.
It should be noted that the structure shown in fig. 1 is only an illustration, and the server 100 provided in the embodiment of the present invention may have fewer or more components than those shown in fig. 1, or may have a different configuration from that shown in fig. 1. Further, the components shown in fig. 1 may be implemented by software, hardware, or a combination thereof.
In addition, the server may be a server of the social software itself, or may be a third-party server, and after the user logs in the social software, the third-party server executes the image-based prediction method provided by the embodiment of the present invention.
Referring to fig. 2, fig. 2 is a flowchart illustrating steps of a prediction method based on images according to an embodiment of the present invention, which is applied to the server 100 shown in fig. 1. It should be noted that, the image-based prediction method provided by the embodiment of the present invention is not limited by the order shown in fig. 2 and the following, and the method includes: step S101-step S105.
Step S101: and acquiring the expression image sent by the chat object in the chat frame of the social software.
During the use of social software, chat objects often use expression images instead of text communications. The expression image can be a special expression of the social software, can also be an expression package, and can also be different network images, such as an animation image, a landscape image, a building image and the like.
During the chat process of the chat object, the server can actively acquire the emoticons sent by the chat object in the chat frame of the social software.
Step S102: and carrying out gray level conversion on the expression image to generate a gray level image.
And after receiving the expression image, the server performs gray level conversion on the expression image. Since the image may be a black-and-white image or a color image, all the expression images are uniformly converted into grayscale images for accurate prediction.
As an embodiment, step S102: the expression image is subjected to gray level conversion, and the generating of the gray level image specifically comprises the following steps:
performing gray level conversion on the expression image by adopting a weighting algorithm to generate a gray level image; wherein the expression of the weighting algorithm is:;representing the gray values of the pixels of the gray scale image,representing the pixel value of a red channel of a pixel point;representing the pixel value of a green channel of a pixel point;and expressing the pixel value of the blue channel of the pixel point.
As still another embodiment, step S102: the expression image is subjected to gray level conversion, and the generating of the gray level image specifically comprises the following steps:
carrying out gray level conversion on the expression image by adopting a mean algorithm to generate a gray level image; wherein, the expression of the mean algorithm is as follows:;representing the gray values of the pixels of the gray scale image,representing the pixel value of a red channel of a pixel point;representing the pixel value of a green channel of a pixel point;and expressing the pixel value of the blue channel of the pixel point.
Therefore, in the embodiment of the invention, the expression image is subjected to gray level conversion through the weighting algorithm or the mean value algorithm, so that the image can be effectively subjected to gray level processing, and the subsequent Hash coding processing can be conveniently carried out on the gray image.
Step S103: cutting the gray level image to form M-N sub-images, and encoding each sub-image based on Hash encoding to generate a target matrix; wherein M and N are both positive integers.
The server cuts the image after performing gray-scale processing on the image to form a plurality of sub-images with the size of M x N. And then, encoding each sub-image by adopting Hash encoding so as to generate a target matrix. As an optional implementation manner, the specific process of encoding each sub-image based on hash encoding to generate the target matrix includes: calculating the pixel mean value of each sub-image and the pixel mean value of the gray level image; respectively carrying out numerical comparison on the pixel mean value of each sub-image and the pixel mean value of the gray level image; based on the numerical comparison result, an objective matrix is generated.
As a comparison method, if the pixel mean value of the sub-image is greater than the pixel mean value of the grayscale image, the sub-image is marked as 1, and if the pixel mean value of the sub-image is not greater than the pixel mean value of the grayscale image, the sub-image is marked as 0.
Illustratively, the pixel mean value of sub-image a is 140; and if the pixel mean value of the grayscale image is 120, the pixel mean value of the sub-image a is greater than that of the grayscale image, so that the corresponding coding number of the sub-image a is 1. The pixel mean value of the sub-image B is 110; and the pixel mean value of the grayscale image is 120, the pixel mean value of the sub-image B is greater than the pixel mean value of the grayscale image, so that the corresponding coding number of the sub-image B is 0. In this way, the target matrix can be obtained. Illustratively, the object matrix is [1, 0, 1, … …, 1, 1, 0 ].
As another comparison method, if the pixel mean value of the sub-image is greater than the pixel mean value of the grayscale image, the sub-image is marked as 0, and if the pixel mean value of the sub-image is not greater than the pixel mean value of the grayscale image, the sub-image is marked as 1.
It should be noted that, for an example of this implementation, reference may be made to the foregoing embodiment, and repeated description is not repeated here, and of course, in other embodiments, the encoding number may also be set according to actual requirements, for example, if the pixel mean value of the sub-image is greater than the pixel mean value of the grayscale image, the sub-image is denoted as 8, and if the pixel mean value of the sub-image is not greater than the pixel mean value of the grayscale image, the sub-image is denoted as 6, which is not limited in this respect.
As can be seen, in the embodiment of the present invention, the pixel mean value of each sub-image is obtained, and the pixel mean value of the grayscale image is obtained; then, the pixel mean value of each sub-image is compared with the pixel mean value of the gray level image in numerical value; and finally, generating a target matrix based on the comparison result. The target matrix formed by the method is composed of different values, so that the similarity between the first matrix and the target matrix can be calculated according to the values, and the method can improve the reasonability and reliability of similarity calculation between images.
Optionally, the calculating the pixel mean value of each sub-image and the pixel mean value of the grayscale image includes: acquiring the gray value of each pixel point in each sub-image; calculating the average value of the gray values of all pixel points in each sub-image to obtain the pixel average value of each sub-image; and calculating the average value of the pixel mean values of all the sub-images in the gray level image to obtain the pixel mean value of the gray level image.
Therefore, in the embodiment of the invention, the gray value of each pixel point in each sub-image is obtained; then calculating the average value of the gray values of all pixel points in each sub-image to obtain the pixel mean value of each sub-image; and finally, calculating the average value of the pixel mean values of all the sub-images in the gray level image so as to obtain the reasonable and reliable pixel mean value of the gray level image.
Step S104: similarity calculation is carried out on the target matrix and a first matrix in a first database, and a second matrix, the similarity of which with the target matrix exceeds a preset threshold value, is determined in the first matrix; the first matrix is generated by performing gray level conversion, image cutting and hash coding on the expression images stored in the first database.
Then, the server calls the expression images stored in the first database to perform gray level conversion, image cutting and Hash coding, and then generates a first matrix to perform similarity calculation. It should be noted that the generation method of the first matrix is the same as that of the target matrix, and is not described herein for the sake of avoiding redundancy.
As an optional similarity calculation method, the performing similarity calculation on the target matrix and a first matrix in a first database, and determining a second matrix, in the first matrix, whose similarity with the target matrix exceeds a preset threshold includes: calculating the similarity between the target matrix and each first matrix in the first database based on a Hamming distance algorithm, and determining a third matrix; and screening out the second matrix with the similarity exceeding a preset threshold value with the target matrix from the third matrix.
It should be noted that the hamming distance between two equal-length character strings is the number of different characters at the corresponding positions of the two character strings. For example, the first matrix is [1, 0, 1, 1] and the object matrix is [0, 0, 1, 1 ]. It can be seen that, if the first bit characters of the first matrix and the target matrix are different, the hamming distance between the first matrix and the target matrix is 1. If the first matrix is [1, 0, 1], the target matrix is [0, 1, 0 ]. And if the three-bit characters of the first matrix and the target matrix are different, the Hamming distance between the first matrix and the target matrix is 3.
In the embodiment of the invention, the similarity between the target matrix and the first matrix can be accurately calculated through a Hamming distance algorithm.
As another optional similarity calculation method, the performing similarity calculation on the target matrix and a first matrix in a first database, and determining a second matrix, in the first matrix, whose similarity with the target matrix exceeds a preset threshold includes:
calculating the similarity between the target matrix and a first matrix in a first database by a cosine similarity algorithm to determine a third matrix;
wherein, the formula of the cosine similarity algorithm is as follows:
(ii) a Wherein,representing cosine similarity of the target matrix and the first matrix; a represents the target matrix; b represents the first matrix;representing the ith value in the target matrix;represents the firstThe ith value in a matrix;
and screening out the second matrix with the similarity exceeding a preset threshold value with the target matrix from the third matrix.
That is, in the embodiment of the present invention, the similarity between the target matrix and the first matrix can be more accurately and reasonably calculated by the cosine similarity calculation method.
Optionally, the expression images in the first database are divided into different matrix groups according to types; each matrix group comprises a plurality of first matrices, the similarity calculation of the target matrix and the first matrices in the first database is carried out, and a second matrix with the similarity exceeding a preset threshold value with the target matrix is determined in the first matrices, and the method comprises the following steps:
calculating the similarity of the target matrix and a first matrix in each matrix group;
acquiring a preset number of fourth matrixes with highest similarity in each matrix group;
calculating the average value of the similarity of the fourth matrix and the first matrix in each matrix group;
and determining a matrix with the similarity exceeding a preset threshold in the fourth matrix with the maximum average value as the second matrix.
As can be seen, in the embodiment of the present invention, the specific process of calculating the similarity is as follows: calculating the similarity of the target matrix and the first matrix in each matrix group; acquiring a preset number of fourth matrixes with highest similarity in each matrix group; calculating the average value of the similarity of the fourth matrix and the first matrix in each matrix group; and determining a matrix with the similarity exceeding a preset threshold in the fourth matrix with the maximum average value as the second matrix. In this way, the influence of the same expression image on the prediction result when the same expression image appears in different groups can be reduced.
Step S105: finding out expression images corresponding to the second matrix from the first database, and displaying the expression images corresponding to the second matrix to a user according to the sequence of similarity from high to low; and the expression image corresponding to the second matrix is the predicted expression image liked by the chat object.
In addition, the image-based prediction method provided by the embodiment of the invention further comprises the following steps: extracting characters in the expression image; acquiring a reply language book corresponding to the characters from a second database; finding out an expression image containing the reply language record from a third database; and the expression image containing the reply language book is the predicted expression image used for replying the chat object.
That is, the second database and the third database are also preconfigured. And the second database stores a reply language book corresponding to each character. And the third database stores the expression images containing the respective reply excerpts.
For example, after the server obtains the expression image, actively extract the characters in the expression image, for example, the characters are 'you have had a meal', then the server obtains the reply language record corresponding to the characters from the second database, and if the reply language record 'certainly have a cheer', the server finds the expression image containing the reply language record 'certainly have a cheer' from the third database.
Therefore, the user can reply the chat object in the expression image mode through the mode, so that the chat efficiency is improved, and the user experience is also improved.
In summary, in the embodiment of the present invention, the server obtains the emoticons sent from the chat object in the chat frame of the social software; then, carrying out gray level conversion on the expression image to generate a gray level image; cutting the gray level image to form M-N sub-images, and encoding each sub-image based on Hash encoding to generate a target matrix; then, similarity calculation is carried out on the target matrix and a first matrix in a first database, and a second matrix with similarity exceeding a preset threshold value with the target matrix is determined in the first matrix; and finally, finding out the expression image corresponding to the second matrix from the first database, and displaying the expression images corresponding to the second matrix to the user according to the sequence of similarity from high to low. By the method, the user using the social software can quickly reply through the predicted expression image liked by the chat object, namely, the prediction method can accurately predict the expression image liked by the chat object, and further improves the use experience of the user in chatting by adopting the chat software.
Referring to fig. 3, based on the same inventive concept, an embodiment of the present invention further provides an image-based prediction apparatus 200, including:
the obtaining module 210 is configured to obtain an emoticon sent from a chat object in a chat frame of the social software.
The processing module 220 is configured to perform gray level conversion on the expression image to generate a gray level image; cutting the gray level image to form M-N sub-images, and encoding each sub-image based on Hash encoding to generate a target matrix; wherein M and N are both positive integers; similarity calculation is carried out on the target matrix and a first matrix in a first database, and a second matrix, the similarity of which with the target matrix exceeds a preset threshold value, is determined in the first matrix; the first matrix is generated by performing gray level conversion, image cutting and hash coding on the expression images stored in the first database.
The prediction module 230 is configured to find the expression image corresponding to the second matrix from the first database, and show the expression image corresponding to the second matrix to a user in an order from high similarity to low similarity; and the expression image corresponding to the second matrix is the predicted expression image which the chat object likes.
Optionally, the processing module 220 is specifically configured to perform gray scale conversion on the expression image by using a weighting algorithm to generate the gray scale image; wherein the expression of the weighting algorithm is:;represents the ashThe gray values of the pixel points of the intensity image,representing the pixel value of a red channel of a pixel point;representing the pixel value of a green channel of a pixel point;expressing the pixel value of a blue channel of a pixel point, or performing gray level conversion on the expression image by adopting an average algorithm to generate the gray level image; wherein, the expression of the mean algorithm is as follows:;representing the gray values of the pixels of the gray scale image,representing the pixel value of a red channel of a pixel point;representing the pixel value of a green channel of a pixel point;and expressing the pixel value of the blue channel of the pixel point.
Optionally, the processing module 220 is specifically configured to calculate a pixel mean value of each of the sub-images and a pixel mean value of the grayscale image; comparing the pixel mean value of each sub-image with the pixel mean value of the gray level image respectively; generating the target matrix based on the numerical comparison result; if the pixel mean value of the sub-image is greater than the pixel mean value of the gray-scale image, the sub-image is marked as 1, if the pixel mean value of the sub-image is not greater than the pixel mean value of the gray-scale image, the sub-image is marked as 0, or if the pixel mean value of the sub-image is greater than the pixel mean value of the gray-scale image, the sub-image is marked as 0, and if the pixel mean value of the sub-image is not greater than the pixel mean value of the gray-scale image, the sub-image is marked as 1.
Optionally, the processing module 220 is specifically configured to obtain a gray scale value of each pixel point in each sub-image; calculating the average value of the gray values of all pixel points in each sub-image to obtain the pixel average value of each sub-image; and calculating the average value of the pixel mean values of all the sub-images in the gray level image to obtain the pixel mean value of the gray level image.
Optionally, the processing module 220 is specifically configured to calculate, based on a hamming distance algorithm, a similarity between the target matrix and each of the first matrices in the first database, and determine a third matrix; and screening out the second matrix with the similarity exceeding a preset threshold value with the target matrix from the third matrix.
Optionally, the processing module 220 is specifically configured to calculate, by a cosine similarity algorithm, a similarity between the target matrix and a first matrix in the first database, and determine a third matrix; wherein, the formula of the cosine similarity algorithm is as follows:(ii) a Wherein,representing cosine similarity of the target matrix and the first matrix; a represents the target matrix; b represents the first matrix;representing the ith value in the target matrix;representing the ith value in the first matrix; and screening out the second matrix with the similarity exceeding a preset threshold value with the target matrix from the third matrix.
Optionally, the expression images in the first database are divided into different matrix groups according to types; each matrix group includes a plurality of the first matrices, and the processing module 220 is specifically configured to calculate a similarity between the target matrix and the first matrix in each matrix group; acquiring a preset number of fourth matrixes with highest similarity in each matrix group; calculating the average value of the similarity of the fourth matrix and the first matrix in each matrix group; and determining a matrix with the similarity exceeding a preset threshold in the fourth matrix with the maximum average value as the second matrix.
Optionally, the processing module 220 is further specifically configured to extract characters in the expression image; acquiring a reply language book corresponding to the characters from a second database; finding out an expression image containing the reply language record from a third database; and the expression image containing the reply language book is the predicted expression image used for replying the chat object.
It should be noted that, as those skilled in the art can clearly understand, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
Based on the same inventive concept, embodiments of the present invention also provide a computer-readable storage medium, on which a computer program is stored, which, when executed, performs the methods provided in the above embodiments.
The storage medium may be any available medium that can be accessed by a computer or a data storage device including one or more integrated servers, data centers, and the like. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
In addition, units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
Furthermore, the functional modules in the embodiments of the present invention may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
In this document, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions.
The above description is only an example of the present invention, and is not intended to limit the scope of the present invention, and it will be apparent to those skilled in the art that various modifications and variations can be made in the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims (10)
1. An image-based prediction method, comprising:
obtaining an expression image sent by a chat object in a chat frame of social software;
performing gray level conversion on the expression image to generate a gray level image;
cutting the gray level image to form M-N sub-images, and encoding each sub-image based on Hash encoding to generate a target matrix; wherein M and N are both positive integers;
similarity calculation is carried out on the target matrix and a first matrix in a first database, and a second matrix, the similarity of which with the target matrix exceeds a preset threshold value, is determined in the first matrix; the first matrix is generated by performing gray level conversion, image cutting and hash coding on the expression images stored in the first database; and
finding out the expression image corresponding to the second matrix from the first database, and displaying the expression images corresponding to the second matrix to a user according to the sequence of similarity from high to low; and the expression image corresponding to the second matrix is the predicted expression image liked by the chat object.
2. The prediction method according to claim 1, wherein the performing of the gray-scale conversion on the expression image to generate a gray-scale image comprises: performing gray level conversion on the expression image by adopting a weighting algorithm to generate a gray level image; wherein the expression of the weighting algorithm is:;representing the gray values of the pixels of the gray scale image,representing the pixel value of a red channel of a pixel point;representing the pixel value of a green channel of a pixel point;expressing the pixel value of a blue channel of a pixel point, or performing gray level conversion on the expression image by adopting an average algorithm to generate the gray level image; the expression of the mean value algorithm is as follows:;representing the gray values of the pixels of the gray scale image,representing the pixel value of a red channel of a pixel point;representing the pixel value of a green channel of a pixel point;and expressing the pixel value of the blue channel of the pixel point.
3. The prediction method of claim 1, wherein the encoding each sub-image based on hash coding to generate an object matrix comprises:
calculating the pixel mean value of each sub-image and the pixel mean value of the gray level image;
comparing the pixel mean value of each sub-image with the pixel mean value of the gray level image respectively; and
generating the target matrix based on the numerical comparison result;
if the pixel mean value of the sub-image is greater than the pixel mean value of the grayscale image, the sub-image is marked as 1, if the pixel mean value of the sub-image is not greater than the pixel mean value of the grayscale image, the sub-image is marked as 0, or if the pixel mean value of the sub-image is greater than the pixel mean value of the grayscale image, the sub-image is marked as 0, if the pixel mean value of the sub-image is not greater than the pixel mean value of the grayscale image, the sub-image is marked as 1.
4. The prediction method according to claim 3, wherein the calculating the pixel mean value of each of the sub-images and the pixel mean value of the gray scale image comprises:
acquiring the gray value of each pixel point in each sub-image;
calculating the average value of the gray values of all pixel points in each sub-image to obtain the pixel average value of each sub-image;
and calculating the average value of the pixel mean values of all the sub-images in the gray level image to obtain the pixel mean value of the gray level image.
5. The prediction method according to claim 1, wherein the calculating the similarity between the target matrix and a first matrix in a first database, and determining a second matrix with similarity exceeding a preset threshold with the target matrix in the first matrix comprises:
calculating the similarity between the target matrix and each first matrix in the first database based on a Hamming distance algorithm, and determining a third matrix;
and screening out the second matrix with the similarity exceeding a preset threshold value with the target matrix from the third matrix.
6. The prediction method according to claim 1, wherein the calculating the similarity between the target matrix and a first matrix in a first database, and determining a second matrix with similarity exceeding a preset threshold with the target matrix in the first matrix comprises:
calculating the similarity between the target matrix and a first matrix in a first database by a cosine similarity algorithm to determine a third matrix;
wherein, the formula of the cosine similarity algorithm is as follows:
(ii) a Wherein,representing cosine similarity of the target matrix and the first matrix; a represents the target matrix; b represents the first matrix;representing the ith value in the target matrix;representing the ith value in the first matrix;
and screening out the second matrix with the similarity exceeding a preset threshold value with the target matrix from the third matrix.
7. The prediction method according to claim 1, wherein the expression images in the first database are divided into different matrix groups according to types; each matrix group comprises a plurality of first matrices, the similarity calculation of the target matrix and the first matrices in the first database is carried out, and a second matrix with the similarity exceeding a preset threshold value with the target matrix is determined in the first matrices, and the method comprises the following steps:
calculating the similarity of the target matrix and a first matrix in each matrix group;
acquiring a preset number of fourth matrixes with highest similarity in each matrix group;
calculating the average value of the similarity of the fourth matrix and the first matrix in each matrix group;
and determining a matrix with the similarity exceeding a preset threshold in the fourth matrix with the maximum average value as the second matrix.
8. The prediction method according to claim 1, characterized in that the method further comprises:
extracting characters in the expression image;
acquiring a reply language book corresponding to the characters from a second database;
finding out an expression image containing the reply language record from a third database; and the expression image containing the reply language book is the predicted expression image used for replying the chat object.
9. An age prediction apparatus based on a user avatar, comprising:
the obtaining module is used for obtaining the expression image sent by the chat object in the chat frame of the social software;
the processing module is used for carrying out gray level conversion on the expression image to generate a gray level image; cutting the gray level image to form M-N sub-images, and encoding each sub-image based on Hash encoding to generate a target matrix; wherein M and N are both positive integers; similarity calculation is carried out on the target matrix and a first matrix in a first database, and a second matrix, the similarity of which with the target matrix exceeds a preset threshold value, is determined in the first matrix; the first matrix is generated by performing gray level conversion, image cutting and hash coding on the expression images stored in the first database;
the prediction module is used for searching the expression image corresponding to the second matrix from the first database and displaying the expression image corresponding to the second matrix to a user according to the sequence of similarity from high to low; and the expression image corresponding to the second matrix is the predicted expression image liked by the chat object.
10. A server, comprising: a processor and a memory, the processor and the memory connected;
the memory is used for storing programs;
the processor is configured to execute a program stored in the memory to perform the prediction method of any one of claims 1-8.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210412967.5A CN114511713A (en) | 2022-04-20 | 2022-04-20 | Image-based prediction method and device and server |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210412967.5A CN114511713A (en) | 2022-04-20 | 2022-04-20 | Image-based prediction method and device and server |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114511713A true CN114511713A (en) | 2022-05-17 |
Family
ID=81555052
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210412967.5A Pending CN114511713A (en) | 2022-04-20 | 2022-04-20 | Image-based prediction method and device and server |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114511713A (en) |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105975563A (en) * | 2016-04-29 | 2016-09-28 | 腾讯科技(深圳)有限公司 | Facial expression recommendation method and apparatus |
CN106228451A (en) * | 2016-05-15 | 2016-12-14 | 盛禾东林(厦门)文创科技有限公司 | A kind of caricature chat system |
CN111190493A (en) * | 2018-11-15 | 2020-05-22 | 中兴通讯股份有限公司 | Expression input method, device, equipment and storage medium |
CN111193657A (en) * | 2019-12-12 | 2020-05-22 | 广州啦咔网络科技有限公司 | Chat expression reply method, device and storage medium |
CN113505765A (en) * | 2021-09-09 | 2021-10-15 | 北京轻松筹信息技术有限公司 | Age prediction method and device based on user head portrait and electronic equipment |
-
2022
- 2022-04-20 CN CN202210412967.5A patent/CN114511713A/en active Pending
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105975563A (en) * | 2016-04-29 | 2016-09-28 | 腾讯科技(深圳)有限公司 | Facial expression recommendation method and apparatus |
CN106228451A (en) * | 2016-05-15 | 2016-12-14 | 盛禾东林(厦门)文创科技有限公司 | A kind of caricature chat system |
CN111190493A (en) * | 2018-11-15 | 2020-05-22 | 中兴通讯股份有限公司 | Expression input method, device, equipment and storage medium |
CN111193657A (en) * | 2019-12-12 | 2020-05-22 | 广州啦咔网络科技有限公司 | Chat expression reply method, device and storage medium |
CN113505765A (en) * | 2021-09-09 | 2021-10-15 | 北京轻松筹信息技术有限公司 | Age prediction method and device based on user head portrait and electronic equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US20210099310A1 (en) | Image processing method, image matching method, device and storage medium | |
CN111144457B (en) | Image processing method, device, equipment and storage medium | |
CN113032580B (en) | Associated file recommendation method and system and electronic equipment | |
CN111159413A (en) | Log clustering method, device, equipment and storage medium | |
CN114612743A (en) | Deep learning model training method, target object identification method and device | |
CN111701247A (en) | Method and equipment for determining unified account | |
CN112765324A (en) | Concept drift detection method and device | |
CN113627536A (en) | Model training method, video classification method, device, equipment and storage medium | |
US20230096921A1 (en) | Image recognition method and apparatus, electronic device and readable storage medium | |
CN113810375B (en) | Webshell detection method, device and equipment and readable storage medium | |
CN113887551B (en) | Target person analysis method based on ticket data, terminal device and storage medium | |
CN116361567B (en) | Data processing method and system applied to cloud office | |
CN113505765B (en) | Age prediction method and device based on user head portrait and electronic equipment | |
CN116975864A (en) | Malicious code detection method and device, electronic equipment and storage medium | |
CN115169489B (en) | Data retrieval method, device, equipment and storage medium | |
CN114511713A (en) | Image-based prediction method and device and server | |
CN116309002B (en) | Graph data storage, access and processing methods, training methods, equipment and media | |
CN111639260B (en) | Content recommendation method, content recommendation device and storage medium | |
CN112633285B (en) | Domain adaptation method, domain adaptation device, electronic equipment and storage medium | |
CN108009233B (en) | Image restoration method and device, computer equipment and storage medium | |
CN113535885B (en) | Age prediction method and device based on user nickname and electronic equipment | |
CN115497113B (en) | Information generation method, device, electronic equipment and storage medium | |
CN117112846B (en) | Multi-information source license information management method, system and medium | |
CN115131453B (en) | Color filling model training, color filling method and device and electronic equipment | |
CN111818114B (en) | Information sharing method and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20220517 |